diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-03-05 23:01:45 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-03-05 23:05:02 +0300 |
commit | 4326f8af08c845eeb4eb45800ca047f690044007 (patch) | |
tree | cb5ab49dc6f3e33a5f12167dc94cf862cdf29c67 /source/blender/editors/space_file/file_draw.c | |
parent | 8858311463b7220eef383781d31dde31868fcd7c (diff) |
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.
Diffstat (limited to 'source/blender/editors/space_file/file_draw.c')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 17ee7726f45..8156e62a427 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -434,7 +434,7 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) const char *blendfile_path = BKE_main_blendfile_path(bmain); BLI_make_file_string(blendfile_path, orgname, sfile->params->dir, oldname); - BLI_strncpy(filename, sfile->params->renameedit, sizeof(filename)); + BLI_strncpy(filename, sfile->params->renamefile, sizeof(filename)); BLI_filename_make_safe(filename); BLI_make_file_string(blendfile_path, newname, sfile->params->dir, filename); @@ -449,6 +449,17 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) errno ? strerror(errno) : "unknown error"); WM_report_banner_show(); } + else { + /* If rename is sucessfull, scroll to newly renamed entry. */ + BLI_strncpy(sfile->params->renamefile, filename, sizeof(sfile->params->renamefile)); + sfile->params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING; + + if (sfile->smoothscroll_timer != NULL) { + WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); + } + sfile->smoothscroll_timer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER1, 1.0 / 1000.0); + sfile->scroll_offset = 0; + } /* to make sure we show what is on disk */ ED_fileselect_clear(wm, sa, sfile); @@ -677,8 +688,8 @@ void file_draw_list(const bContext *C, ARegion *ar) } but = uiDefBut(block, UI_BTYPE_TEXT, 1, "", sx, sy - layout->tile_h - 0.15f * UI_UNIT_X, - width, textheight, sfile->params->renameedit, 1.0f, - (float)sizeof(sfile->params->renameedit), 0, 0, ""); + width, textheight, sfile->params->renamefile, 1.0f, + (float)sizeof(sfile->params->renamefile), 0, 0, ""); UI_but_func_rename_set(but, renamebutton_cb, file); UI_but_flag_enable(but, UI_BUT_NO_UTF8); /* allow non utf8 names */ UI_but_flag_disable(but, UI_BUT_UNDO); |