From 0e01667e25f683c861eae07292cd709a01b0254f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 2 Oct 2023 16:20:31 +0200 Subject: [PATCH] Fix Split Strips operator not showing shortcut This is because the menu entry was using different operator properties from what the shortcut is defined for. It was needed to make it so an operator which is called from the menu does not have dependency on the mouse location. Now it is achieved by resolving MOUSE side to RIGHT from the operator's exec(). Ref #112598 Pull Request: https://projects.blender.org/blender/blender/pulls/113143 --- scripts/startup/bl_ui/space_sequencer.py | 12 ++++----- .../editors/space_sequencer/sequencer_edit.cc | 25 ++++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/scripts/startup/bl_ui/space_sequencer.py b/scripts/startup/bl_ui/space_sequencer.py index ffb43377f30..e66887d56d3 100644 --- a/scripts/startup/bl_ui/space_sequencer.py +++ b/scripts/startup/bl_ui/space_sequencer.py @@ -20,6 +20,7 @@ from bl_ui.space_toolsystem_common import ( ToolActivePanelHelper, ) from rna_prop_ui import PropertyPanel +from bl_ui_utils.layout import operator_context def _space_view_types(st): @@ -988,13 +989,12 @@ class SEQUENCER_MT_strip(Menu): layout.menu("SEQUENCER_MT_strip_retiming") layout.separator() - props = layout.operator("sequencer.split", text="Split") - props.type = 'SOFT' - props.side = 'RIGHT' + with operator_context(layout, 'EXEC_REGION_WIN'): + props = layout.operator("sequencer.split", text="Split") + props.type = 'SOFT' - props = layout.operator("sequencer.split", text="Hold Split") - props.type = 'HARD' - props.side = 'RIGHT' + props = layout.operator("sequencer.split", text="Hold Split") + props.type = 'HARD' layout.separator() diff --git a/source/blender/editors/space_sequencer/sequencer_edit.cc b/source/blender/editors/space_sequencer/sequencer_edit.cc index f7e3beb80b5..dd68427af79 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.cc +++ b/source/blender/editors/space_sequencer/sequencer_edit.cc @@ -1401,6 +1401,23 @@ EnumPropertyItem prop_side_types[] = { {0, nullptr, 0, nullptr, nullptr}, }; +/* Get the splitting side for the Split Strips's operator exec() callback. */ +static int sequence_split_side_for_exec_get(wmOperator *op) +{ + const int split_side = RNA_enum_get(op->ptr, "side"); + + /* The mouse position can not be resolved from the exec() as the mouse coordinate is not + * accessible. So fall-back to the RIGHT side instead. + * + * The SEQ_SIDE_MOUSE is used by the Strip menu, together with the EXEC_DEFAULT operator + * context in order to have properly resolved shortcut in the menu. */ + if (split_side == SEQ_SIDE_MOUSE) { + return SEQ_SIDE_RIGHT; + } + + return split_side; +} + static int sequencer_split_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); @@ -1409,11 +1426,13 @@ static int sequencer_split_exec(bContext *C, wmOperator *op) bool changed = false; bool seq_selected = false; - const int split_frame = RNA_int_get(op->ptr, "frame"); - const int split_channel = RNA_int_get(op->ptr, "channel"); const bool use_cursor_position = RNA_boolean_get(op->ptr, "use_cursor_position"); + + const int split_frame = use_cursor_position ? RNA_int_get(op->ptr, "frame") : scene->r.cfra; + const int split_channel = use_cursor_position ? RNA_int_get(op->ptr, "channel") : 0; + const eSeqSplitMethod method = eSeqSplitMethod(RNA_enum_get(op->ptr, "type")); - const int split_side = RNA_enum_get(op->ptr, "side"); + const int split_side = sequence_split_side_for_exec_get(op); const bool ignore_selection = RNA_boolean_get(op->ptr, "ignore_selection"); SEQ_prefetch_stop(scene);