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:
authorJulian Eisel <eiseljulian@gmail.com>2019-10-14 17:21:17 +0300
committerJulian Eisel <eiseljulian@gmail.com>2019-10-14 17:32:18 +0300
commit5edfde58fe60ff59b4a689d3a9cfd7ecf83a2f98 (patch)
tree08b7a0835f650a17da242d86738f6d927d05439c /source/blender/editors/space_file/file_ops.c
parentac52a53628263f40b0a54379bce3ad0aed663e59 (diff)
File Browser: Add F2 shortcut to rename files
Previously, we used Ctrl+Click for renaming, but since that shortcut is now consistently used to add items to the selection, we can't use that. In other cases we switched to F2 now, so it makes sense for the File Browser too. Further, AFAIK renaming was only possible through the context menu, which makes it hard to discover in the right click select keymap (have to press W). Note that I had to do some internal changes to ensure the context menu always acts on the clicked/hovered item, while the shortcut operates on the active item. William and I agreed that this is likely the behavior expected by most users.
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r--source/blender/editors/space_file/file_ops.c64
1 files changed, 27 insertions, 37 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 5ea95383892..44f562393d5 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2395,60 +2395,49 @@ void FILE_OT_filenum(struct wmOperatorType *ot)
RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100, 100);
}
-static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
+static void file_rename_state_activate(SpaceFile *sfile, int file_idx, bool require_selected)
{
- ScrArea *sa = CTX_wm_area(C);
- SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
+ const int numfiles = filelist_files_ensure(sfile->files);
- if (sfile->params) {
- int idx = sfile->params->highlight_file;
- int numfiles = filelist_files_ensure(sfile->files);
- if ((0 <= idx) && (idx < numfiles)) {
- FileDirEntry *file = filelist_file(sfile->files, idx);
+ if ((file_idx > 0) && (file_idx < numfiles)) {
+ FileDirEntry *file = filelist_file(sfile->files, file_idx);
+
+ if ((require_selected == false) ||
+ (filelist_entry_select_get(sfile->files, file, CHECK_ALL) & FILE_SEL_SELECTED)) {
filelist_entry_select_index_set(
- sfile->files, idx, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL);
+ sfile->files, file_idx, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL);
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;
}
+ }
+}
+
+static int file_rename_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
+{
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
+
+ if (sfile->params) {
+ file_rename_state_activate(sfile, sfile->params->active_file, true);
ED_area_tag_redraw(sa);
}
return OPERATOR_FINISHED;
}
-static bool file_rename_poll(bContext *C)
+static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
{
- bool poll = ED_operator_file_active(C);
- SpaceFile *sfile = CTX_wm_space_file(C);
-
- if (sfile && sfile->params) {
- int idx = sfile->params->highlight_file;
- int numfiles = filelist_files_ensure(sfile->files);
-
- if ((0 <= idx) && (idx < numfiles)) {
- FileDirEntry *file = filelist_file(sfile->files, idx);
- if (FILENAME_IS_CURRPAR(file->relpath)) {
- poll = false;
- }
- }
+ ScrArea *sa = CTX_wm_area(C);
+ SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
- if (sfile->params->highlight_file < 0) {
- poll = false;
- }
- else {
- char dir[FILE_MAX_LIBEXTRA];
- if (filelist_islibrary(sfile->files, dir, NULL)) {
- poll = false;
- }
- }
- }
- else {
- poll = false;
+ if (sfile->params) {
+ file_rename_state_activate(sfile, sfile->params->highlight_file, false);
+ ED_area_tag_redraw(sa);
}
- return poll;
+ return OPERATOR_FINISHED;
}
void FILE_OT_rename(struct wmOperatorType *ot)
@@ -2459,8 +2448,9 @@ void FILE_OT_rename(struct wmOperatorType *ot)
ot->idname = "FILE_OT_rename";
/* api callbacks */
+ ot->invoke = file_rename_invoke;
ot->exec = file_rename_exec;
- ot->poll = file_rename_poll;
+ ot->poll = ED_operator_file_active;
}
static bool file_delete_poll(bContext *C)