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.
This commit is contained in:
parent
ac52a53628
commit
5edfde58fe
Notes:
blender-bot
2023-02-14 00:10:13 +01:00
Referenced by commit 9a85592dde
, Fix: First item in File Browser can't be renamed
Referenced by issue #71773, File Browser: Rename shortcut "F2" key is not consistent
|
@ -1793,6 +1793,7 @@ def km_file_browser(params):
|
|||
{"properties": [("data_path", 'space_data.params.show_hidden')]}),
|
||||
("file.directory_new", {"type": 'I', "value": 'PRESS'},
|
||||
{"properties": [("confirm", False)]}),
|
||||
("file.rename", {"type": 'F2', "value": 'PRESS'}, None),
|
||||
("file.delete", {"type": 'X', "value": 'PRESS'}, None),
|
||||
("file.delete", {"type": 'DEL', "value": 'PRESS'}, None),
|
||||
("file.smoothscroll", {"type": 'TIMER1', "value": 'ANY', "any": True}, None),
|
||||
|
|
|
@ -1183,6 +1183,7 @@ def km_file_browser(params):
|
|||
{"properties": [("data_path", 'space_data.params.show_hidden')]}),
|
||||
("file.directory_new", {"type": 'I', "value": 'PRESS'},
|
||||
{"properties": [("confirm", False)]}),
|
||||
("file.rename", {"type": 'F2', "value": 'PRESS'}, None),
|
||||
("file.delete", {"type": 'DEL', "value": 'PRESS'}, None),
|
||||
("file.smoothscroll", {"type": 'TIMER1', "value": 'ANY', "any": True}, None),
|
||||
("wm.context_toggle", {"type": 'T', "value": 'PRESS'},
|
||||
|
|
|
@ -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);
|
||||
ScrArea *sa = CTX_wm_area(C);
|
||||
SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(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;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue