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 <julian@blender.org>2021-08-10 13:54:06 +0300
committerJulian Eisel <julian@blender.org>2021-08-10 14:04:49 +0300
commit05879f2c36e9e59ca62011aafb266a7b8dd64656 (patch)
tree27448ffd1114714814e8202710b93a79792ab49b /source/blender/editors/space_file
parentfe1740ae6a580f9618ae05cf03839da51dab0c4e (diff)
File/Asset Browser: Select/Activate File on Right Click for Context Menu
Right clicking would spawn the context menu under the cursor, but some operators would actually act on the active asset/file which wasn't the one clicked on. When multiple files are selected and one of them is right-clicked on, selection is not changed to allow operations on multiple files. E.g. deletion. This makes the File/Asset Browser match the Outliner (in behavior, not implementation). For the right-click selection keymap: * The context menu still only spawns on W. * Bonus: Right click now does something, it actually selects files! I could have done additional changes here to avoid this, but it seems like a good addition. This is also a better alternative to rB5edfde58fe60, which didn't work properly either. Using rename from the context menu would only work if the clicked on file was also active... Differential Revision: https://developer.blender.org/D12065 Reviewed by: Campbell Barton
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r--source/blender/editors/space_file/file_ops.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index c7e5f744455..d1ef1b33023 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -546,6 +546,9 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
const bool fill = RNA_boolean_get(op->ptr, "fill");
const bool do_diropen = RNA_boolean_get(op->ptr, "open");
const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
+ const bool only_activate_if_selected = RNA_boolean_get(op->ptr, "only_activate_if_selected");
+ /* Used so right mouse clicks can do both, activate and spawn the context menu. */
+ const bool pass_through = RNA_boolean_get(op->ptr, "pass_through");
if (region->regiontype != RGN_TYPE_WINDOW) {
return OPERATOR_CANCELLED;
@@ -563,8 +566,13 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int numfiles = filelist_files_ensure(sfile->files);
if ((idx >= 0) && (idx < numfiles)) {
+ const bool is_selected = filelist_entry_select_index_get(sfile->files, idx, CHECK_ALL) &
+ FILE_SEL_SELECTED;
+ if (only_activate_if_selected && is_selected) {
+ /* Don't deselect other items. */
+ }
/* single select, deselect all selected first */
- if (!extend) {
+ else if (!extend) {
file_select_deselect_all(sfile, FILE_SEL_SELECTED);
}
}
@@ -593,7 +601,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
WM_event_add_mousemove(CTX_wm_window(C)); /* for directory changes */
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
- return OPERATOR_FINISHED;
+ return pass_through ? (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH) : OPERATOR_FINISHED;
}
void FILE_OT_select(wmOperatorType *ot)
@@ -628,6 +636,20 @@ void FILE_OT_select(wmOperatorType *ot)
"Deselect On Nothing",
"Deselect all when nothing under the cursor");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna,
+ "only_activate_if_selected",
+ false,
+ "Only Activate if Selected",
+ "Do not change selection if the item under the cursor is already "
+ "selected, only activate it");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna,
+ "pass_through",
+ false,
+ "Pass Through",
+ "Even on successful execution, pass the event on so other operators can "
+ "execute on it as well");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
}
/** \} */
@@ -2752,20 +2774,6 @@ static void file_rename_state_activate(SpaceFile *sfile, int file_idx, bool requ
}
}
-static int file_rename_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
- ScrArea *area = CTX_wm_area(C);
- SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
- FileSelectParams *params = ED_fileselect_get_active_params(sfile);
-
- if (params) {
- file_rename_state_activate(sfile, params->active_file, true);
- ED_area_tag_redraw(area);
- }
-
- return OPERATOR_FINISHED;
-}
-
static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
{
ScrArea *area = CTX_wm_area(C);
@@ -2773,7 +2781,7 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
FileSelectParams *params = ED_fileselect_get_active_params(sfile);
if (params) {
- file_rename_state_activate(sfile, params->highlight_file, false);
+ file_rename_state_activate(sfile, params->active_file, false);
ED_area_tag_redraw(area);
}
@@ -2788,7 +2796,6 @@ void FILE_OT_rename(struct wmOperatorType *ot)
ot->idname = "FILE_OT_rename";
/* api callbacks */
- ot->invoke = file_rename_invoke;
ot->exec = file_rename_exec;
/* File browsing only operator (not asset browsing). */
ot->poll = ED_operator_file_browsing_active;