Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r--source/blender/editors/space_file/file_ops.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 450c3177f92..080a8e46c8e 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -21,9 +21,11 @@
* \ingroup spfile
*/
-#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
+
+#include "BLI_blenlib.h"
#include "BLI_linklist.h"
+#include "BLI_math.h"
#include "BLO_readfile.h"
@@ -1593,13 +1595,13 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w
/* 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') {
+ if ((params->rename_flag & (FILE_PARAMS_RENAME_PENDING | FILE_PARAMS_RENAME_POSTSCROLL_PENDING)) != 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) ) {
+ if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL) & (FILE_SEL_EDITING | FILE_SEL_HIGHLIGHTED)) {
edit_idx = i;
break;
}
@@ -1609,7 +1611,7 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w
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') {
+ if (params->rename_flag == 0) {
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
sfile->smoothscroll_timer = NULL;
}
@@ -1624,8 +1626,7 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w
return OPERATOR_PASS_THROUGH;
}
- offset = ED_fileselect_layout_offset(sfile->layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax);
- if (offset < 0) offset = 0;
+ offset = max_ii(0, ED_fileselect_layout_offset(sfile->layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax));
/* scroll offset is the first file in the row/column we are editing in */
if (sfile->scroll_offset == 0) {
@@ -1640,11 +1641,20 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w
}
numfiles_layout = ED_fileselect_layout_numfiles(sfile->layout, ar);
+ /* Using margins helps avoiding scrolling to stop when target item is barely visible on one side of the screen
+ * (i.e. it centers a bit more the target). */
+ int numfiles_layout_margin = max_ii(0, numfiles_layout / 3);
/* check if we have reached our final scroll position */
- if ( (sfile->scroll_offset >= offset) && (sfile->scroll_offset < offset + numfiles_layout) ) {
+ if ((sfile->scroll_offset >= offset + numfiles_layout_margin) &&
+ (sfile->scroll_offset < offset + numfiles_layout - numfiles_layout_margin)) {
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
sfile->smoothscroll_timer = NULL;
+ /* Postscroll (after rename has been validated by user) is done, rename process is totally finisehd, cleanup. */
+ if ((params->rename_flag & FILE_PARAMS_RENAME_POSTSCROLL_ACTIVE) != 0) {
+ params->renamefile[0] = '\0';
+ params->rename_flag = 0;
+ }
return OPERATOR_FINISHED;
}
@@ -1812,9 +1822,13 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
/* now remember file to jump into editing */
BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
+ sfile->params->rename_flag = FILE_PARAMS_RENAME_PENDING;
/* set timer to smoothly view newly generated file */
/* max 30 frs/sec */
+ 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;
@@ -2203,8 +2217,9 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
if ((0 <= idx) && (idx < numfiles)) {
FileDirEntry *file = filelist_file(sfile->files, idx);
filelist_entry_select_index_set(sfile->files, idx, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL);
- BLI_strncpy(sfile->params->renameedit, file->relpath, FILE_MAXFILE);
- sfile->params->renamefile[0] = '\0';
+ BLI_strncpy(sfile->params->renamefile, file->relpath, FILE_MAXFILE);
+ /* We can skip the pending state, as we can directly set FILE_SEL_EDITING on the expected entry here. */
+ sfile->params->rename_flag = FILE_PARAMS_RENAME_ACTIVE;
}
ED_area_tag_redraw(sa);
}