diff options
author | Julian Eisel <julian@blender.org> | 2021-07-05 14:30:47 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-07-05 14:35:41 +0300 |
commit | 2eca9c7ed4e9819564a7be474e281e6f3b296107 (patch) | |
tree | ac44118a04563893aca51d8b84c150f80721c86d /source/blender/editors/space_file/filesel.c | |
parent | 2c6c1b6cc046558519bb8dcfb8ee60401862d7e0 (diff) |
Cleanup: Move common File Browser renaming code into functions
Code would manually do the same things in a couple of places, obvious case of
unnecessary code duplication.
Diffstat (limited to 'source/blender/editors/space_file/filesel.c')
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 7a3ae4d9bb5..4e59e4ba06e 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -1227,6 +1227,37 @@ void ED_fileselect_exit(wmWindowManager *wm, SpaceFile *sfile) } } +void file_params_smoothscroll_timer_clear(wmWindowManager *wm, wmWindow *win, SpaceFile *sfile) +{ + WM_event_remove_timer(wm, win, sfile->smoothscroll_timer); + sfile->smoothscroll_timer = NULL; +} + +/** + * Set the renaming-state to #FILE_PARAMS_RENAME_POSTSCROLL_PENDING and trigger the smooth-scroll + * timer. To be used right after a file was renamed. + * Note that the caller is responsible for setting the correct rename-file info + * (#FileSelectParams.renamefile or #FileSelectParams.renamefile_uuid). + */ +void file_params_invoke_rename_postscroll(wmWindowManager *wm, wmWindow *win, SpaceFile *sfile) +{ + FileSelectParams *params = ED_fileselect_get_active_params(sfile); + + params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING; + + if (sfile->smoothscroll_timer != NULL) { + file_params_smoothscroll_timer_clear(wm, win, sfile); + } + sfile->smoothscroll_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 1000.0); + sfile->scroll_offset = 0; +} + +void file_params_renamefile_clear(FileSelectParams *params) +{ + params->renamefile[0] = '\0'; + params->rename_flag = 0; +} + /** * Helper used by both main update code, and smooth-scroll timer, * to try to enable rename editing from #FileSelectParams.renamefile name. @@ -1260,8 +1291,7 @@ void file_params_renamefile_activate(SpaceFile *sfile, FileSelectParams *params) /* 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; + file_params_renamefile_clear(params); } } |