diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-03-05 18:17:09 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-03-05 23:05:02 +0300 |
commit | 8858311463b7220eef383781d31dde31868fcd7c (patch) | |
tree | 8e065129ce3fa6979d5a44719444676fbdb4afa2 /source/blender/editors/space_file | |
parent | d31b2f854954838fb849b5b0be0011d792eecb43 (diff) |
Fix T58715: File Browser: Creating "New Folder" issues with too many existing folders in display.
Smotthscroll to edited entry was broken since filelisting was
rewritten to become async...
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 20 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 20 | ||||
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 14 |
4 files changed, 39 insertions, 19 deletions
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 44711fd12dc..46e30e556d1 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -28,6 +28,7 @@ struct ARegion; struct ARegionType; +struct FileSelectParams; struct SpaceFile; /* file_ops.c */ @@ -106,7 +107,6 @@ void file_sfile_to_operator_ex(bContext *C, struct wmOperator *op, struct SpaceF void file_sfile_to_operator(bContext *C, struct wmOperator *op, struct SpaceFile *sfile); void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOperator *op); - /* filesel.c */ void fileselect_file_set(SpaceFile *sfile, const int index); float file_string_width(const char *str); @@ -116,6 +116,8 @@ int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matche int autocomplete_directory(struct bContext *C, char *str, void *arg_v); int autocomplete_file(struct bContext *C, char *str, void *arg_v); +void file_params_renamefile_activate(struct SpaceFile *sfile, struct FileSelectParams *params); + /* file_panels.c */ void file_panels_register(struct ARegionType *art); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index a6d52b8fb45..450c3177f92 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1581,7 +1581,7 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w ARegion *ar, *oldar = CTX_wm_region(C); int offset; int numfiles, numfiles_layout; - int edit_idx = 0; + int edit_idx = -1; int i; /* escape if not our timer */ @@ -1590,6 +1590,13 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w numfiles = filelist_files_ensure(sfile->files); + /* Due to async nature of file listing, we may execute this code before `file_refresh()` + * editing entry is available in our listing, so we also have to handle switching to rename mode here. */ + FileSelectParams *params = ED_fileselect_get_params(sfile); + if (params->renamefile[0] != '\0') { + file_params_renamefile_activate(sfile, params); + } + /* check if we are editing a name */ for (i = 0; i < numfiles; ++i) { if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL) ) { @@ -1599,9 +1606,13 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w } /* if we are not editing, we are done */ - if (0 == edit_idx) { - WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); - sfile->smoothscroll_timer = NULL; + if (edit_idx == -1) { + /* Do not invalidate timer if filerename is still pending, we might still be building the filelist + * and yet have to find edited entry... */ + if (params->renamefile[0] == '\0') { + WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); + sfile->smoothscroll_timer = NULL; + } return OPERATOR_PASS_THROUGH; } @@ -1671,7 +1682,6 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w void FILE_OT_smoothscroll(wmOperatorType *ot) { - /* identifiers */ ot->name = "Smooth Scroll"; ot->idname = "FILE_OT_smoothscroll"; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index cc81982bfad..7b642e75eac 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -732,5 +732,25 @@ void ED_fileselect_exit(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile) MEM_freeN(sfile->files); sfile->files = NULL; } +} + +/** Helper used by both main update code, and smoothscroll timer, to try to enable rename editing from + * params->renamefile name. */ +void file_params_renamefile_activate(SpaceFile *sfile, FileSelectParams *params) +{ + BLI_assert(params->renamefile[0] != '\0'); + const int idx = filelist_file_findpath(sfile->files, params->renamefile); + if (idx >= 0) { + FileDirEntry *file = filelist_file(sfile->files, idx); + if (file) { + filelist_entry_select_set(sfile->files, file, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL); + } + } + BLI_strncpy(sfile->params->renameedit, sfile->params->renamefile, sizeof(sfile->params->renameedit)); + /* File listing is now async, do not clear renamefile if matching entry not found + * and dirlist is not finished! */ + if (idx >= 0 || filelist_is_ready(sfile->files)) { + params->renamefile[0] = '\0'; + } } diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index d857955d340..3b40c4a0798 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -260,19 +260,7 @@ static void file_refresh(const bContext *C, ScrArea *sa) } if (params->renamefile[0] != '\0') { - int idx = filelist_file_findpath(sfile->files, params->renamefile); - if (idx >= 0) { - FileDirEntry *file = filelist_file(sfile->files, idx); - if (file) { - filelist_entry_select_set(sfile->files, file, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL); - } - } - BLI_strncpy(sfile->params->renameedit, sfile->params->renamefile, sizeof(sfile->params->renameedit)); - /* File listing is now async, do not clear renamefile if matching entry not found - * and dirlist is not finished! */ - if (idx >= 0 || filelist_is_ready(sfile->files)) { - params->renamefile[0] = '\0'; - } + file_params_renamefile_activate(sfile, params); } if (sfile->layout) { |