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...
This commit is contained in:
Bastien Montagne 2019-03-05 16:17:09 +01:00
parent d31b2f8549
commit 8858311463
Notes: blender-bot 2024-01-16 18:05:25 +01:00
Referenced by issue #58715, File Browser: Creating "New Folder" issues with too many existing folders in display
4 changed files with 40 additions and 20 deletions

View File

@ -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);

View File

@ -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";

View File

@ -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';
}
}

View File

@ -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) {