From 4326f8af08c845eeb4eb45800ca047f690044007 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 5 Mar 2019 21:01:45 +0100 Subject: File Editor: Refactor 'new dir' / renaming code. We really do not need two 256 chars variables to hanlde renaming, a mere pair of flags can handle the situation just as well. Also, scroll to newly renamed item, will help when one want to find again the directory they just added and rename. At some point we'll probably want to refactor scrolling further (to make it fully out of rename code/context e.g.), but for now think this will do. --- source/blender/editors/space_file/filesel.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/space_file/filesel.c') diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 7b642e75eac..5195fa818d6 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -738,19 +738,33 @@ void ED_fileselect_exit(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile) * params->renamefile name. */ void file_params_renamefile_activate(SpaceFile *sfile, FileSelectParams *params) { + BLI_assert(params->rename_flag != 0); + + if ((params->rename_flag & (FILE_PARAMS_RENAME_ACTIVE | FILE_PARAMS_RENAME_POSTSCROLL_ACTIVE)) != 0) { + return; + } + 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) { + BLI_assert(file != NULL); + + if ((params->rename_flag & FILE_PARAMS_RENAME_PENDING) != 0) { filelist_entry_select_set(sfile->files, file, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL); + params->rename_flag = FILE_PARAMS_RENAME_ACTIVE; + } + else if ((params->rename_flag & FILE_PARAMS_RENAME_POSTSCROLL_PENDING) != 0) { + filelist_entry_select_set(sfile->files, file, FILE_SEL_ADD, FILE_SEL_HIGHLIGHTED, CHECK_ALL); + params->renamefile[0] = '\0'; + params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_ACTIVE; } } - 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)) { + /* File listing is now async, only reset renaming if matching entry is not found + * when file listing is not done. */ + else if (filelist_is_ready(sfile->files)) { params->renamefile[0] = '\0'; + params->rename_flag = 0; } } -- cgit v1.2.3