diff options
3 files changed, 43 insertions, 22 deletions
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 6674751f9b8..b27cdbec308 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -773,7 +773,8 @@ def km_outliner(params): items.extend([ ("outliner.highlight_update", {"type": 'MOUSEMOVE', "value": 'ANY', "any": True}, None), ("outliner.item_rename", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None), - ("outliner.item_rename", {"type": 'F2', "value": 'PRESS'}, None), + ("outliner.item_rename", {"type": 'F2', "value": 'PRESS'}, + {"properties": [("use_active", True)]}), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK'}, {"properties": [("extend", False), ("deselect_all", not params.legacy)]}), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK', "ctrl": True}, diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py index c462ac55c53..f5f770deb84 100644 --- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py +++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py @@ -463,6 +463,7 @@ def km_outliner(params): items.extend([ ("outliner.item_rename", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None), ("outliner.item_rename", {"type": 'RET', "value": 'PRESS'}, None), + {"properties": [("use_active", True)]}), ("wm.search_menu", {"type": 'TAB', "value": 'PRESS'}, None), ("outliner.highlight_update", {"type": 'MOUSEMOVE', "value": 'ANY', "any": True}, None), ("outliner.item_activate", {"type": 'LEFTMOUSE', "value": 'CLICK'}, 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(®ion->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(®ion->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"); } /** \} */ |