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>2020-10-15 22:11:31 +0300
committerJulian Eisel <julian@blender.org>2020-10-15 22:31:43 +0300
commite936f042589eeb4c64a9b0df7cfd3b70ef49af22 (patch)
treeb8637646c6940149d28f351f1acc1f27326fe226 /source/blender/editors/space_outliner/outliner_edit.c
parent0a66436fe5f26f8d7b6fb49396f21313fded8654 (diff)
Outliner: Use operator option to decide which item to rename
The `outliner.item_rename` operator needs to decide if it should rename the active or the hovered item. Previously it checked if the event is a press event, which is a hacky way of doing this and limit how the operator can be used in the keymap. Now use a operator option to let this be controlled on the keymap level. Doesn't change any default behavior.
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_edit.c')
-rw-r--r--source/blender/editors/space_outliner/outliner_edit.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 4a9aa984398..779efc3cacb 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -363,35 +363,48 @@ void item_rename_fn(bContext *C,
do_item_rename(region, te, tselem, reports);
}
-static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *event)
+static TreeElement *outliner_item_rename_find_active(const SpaceOutliner *space_outliner,
+ ReportList *reports)
{
- ARegion *region = CTX_wm_region(C);
- SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
- float fmval[2];
+ TreeElement *active_element = outliner_find_element_with_flag(&space_outliner->tree, TSE_ACTIVE);
- /* Rename active element if key pressed, otherwise rename element at cursor coordinates */
- if (event->val == KM_PRESS) {
- TreeElement *active_element = outliner_find_element_with_flag(&space_outliner->tree,
- TSE_ACTIVE);
+ if (!active_element) {
+ BKE_report(reports, RPT_WARNING, "No active item to rename");
+ return NULL;
+ }
- if (active_element) {
- do_item_rename(region, active_element, TREESTORE(active_element), op->reports);
- }
- else {
- BKE_report(op->reports, RPT_WARNING, "No active item to rename");
- }
+ return active_element;
+}
+
+static TreeElement *outliner_item_rename_find_hovered(const SpaceOutliner *space_outliner,
+ ARegion *region,
+ const wmEvent *event)
+{
+ float fmval[2];
+ UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
+
+ TreeElement *hovered = outliner_find_item_at_y(space_outliner, &space_outliner->tree, fmval[1]);
+ if (hovered && outliner_item_is_co_over_name(hovered, fmval[0])) {
+ return hovered;
}
- else {
- UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
- TreeElement *hovered = outliner_find_item_at_y(
- space_outliner, &space_outliner->tree, fmval[1]);
+ return NULL;
+}
- if (hovered && outliner_item_is_co_over_name(hovered, fmval[0])) {
- do_item_rename(region, hovered, TREESTORE(hovered), op->reports);
- }
+static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ ARegion *region = CTX_wm_region(C);
+ SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
+ const bool use_active = RNA_boolean_get(op->ptr, "use_active");
+
+ TreeElement *te = use_active ? outliner_item_rename_find_active(space_outliner, op->reports) :
+ outliner_item_rename_find_hovered(space_outliner, region, event);
+ if (!te) {
+ return OPERATOR_CANCELLED;
}
+ do_item_rename(region, te, TREESTORE(te), op->reports);
+
return OPERATOR_FINISHED;
}
@@ -407,6 +420,12 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_boolean(ot->srna,
+ "use_active",
+ false,
+ "Use Active",
+ "Rename the active item, rather than the one the mouse is over");
}
/** \} */