From fa6384eb39f6f703bbbde06524c9246979876d3f Mon Sep 17 00:00:00 2001 From: Richard Antalik Date: Wed, 31 Jan 2024 19:04:09 +0100 Subject: [PATCH] Fix #92140: Can't assign shortcuts to tools Set operator context for VSE tool panel and pass correct space_type and region_type to WM_keymap_find_all(). Pull Request: https://projects.blender.org/blender/blender/pulls/105959 --- source/blender/editors/include/ED_screen.hh | 6 +++++- source/blender/editors/screen/area.cc | 15 +++++++++++--- .../editors/space_buttons/space_buttons.cc | 3 ++- .../editors/space_image/space_image.cc | 3 ++- .../space_sequencer/space_sequencer.cc | 12 ++++++++++- .../editors/space_userpref/space_userpref.cc | 3 ++- .../editors/space_view3d/space_view3d.cc | 5 +++-- .../windowmanager/intern/wm_keymap_utils.cc | 20 ++++++++++++++++++- 8 files changed, 56 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/include/ED_screen.hh b/source/blender/editors/include/ED_screen.hh index a67d4ab8b93..ef64f24af5f 100644 --- a/source/blender/editors/include/ED_screen.hh +++ b/source/blender/editors/include/ED_screen.hh @@ -89,7 +89,10 @@ void ED_region_search_filter_update(const ScrArea *area, ARegion *region); const char *ED_area_region_search_filter_get(const ScrArea *area, const ARegion *region); void ED_region_panels_init(wmWindowManager *wm, ARegion *region); -void ED_region_panels_ex(const bContext *C, ARegion *region, const char *contexts[]); +void ED_region_panels_ex(const bContext *C, + ARegion *region, + wmOperatorCallContext op_context, + const char *contexts[]); void ED_region_panels(const bContext *C, ARegion *region); /** * \param contexts: A NULL terminated array of context strings to match against. @@ -99,6 +102,7 @@ void ED_region_panels(const bContext *C, ARegion *region); void ED_region_panels_layout_ex(const bContext *C, ARegion *region, ListBase *paneltypes, + wmOperatorCallContext op_context, const char *contexts[], const char *category_override); /** diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index 69ef0fab361..4fae0b33014 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -3112,6 +3112,7 @@ static int panel_draw_width_from_max_width_get(const ARegion *region, void ED_region_panels_layout_ex(const bContext *C, ARegion *region, ListBase *paneltypes, + wmOperatorCallContext op_context, const char *contexts[], const char *category_override) { @@ -3187,6 +3188,10 @@ void ED_region_panels_layout_ex(const bContext *C, update_tot_size = false; } + if (panel && panel->layout) { + uiLayoutSetOperatorContext(panel->layout, op_context); + } + ed_panel_draw(C, region, ®ion->panels, pt, panel, width, em, nullptr, search_filter); } @@ -3280,7 +3285,8 @@ void ED_region_panels_layout_ex(const bContext *C, void ED_region_panels_layout(const bContext *C, ARegion *region) { - ED_region_panels_layout_ex(C, region, ®ion->type->paneltypes, nullptr, nullptr); + ED_region_panels_layout_ex( + C, region, ®ion->type->paneltypes, WM_OP_INVOKE_REGION_WIN, nullptr, nullptr); } void ED_region_panels_draw(const bContext *C, ARegion *region) @@ -3332,10 +3338,13 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) UI_view2d_scrollers_draw_ex(v2d, use_mask ? &mask : nullptr, use_full_hide); } -void ED_region_panels_ex(const bContext *C, ARegion *region, const char *contexts[]) +void ED_region_panels_ex(const bContext *C, + ARegion *region, + wmOperatorCallContext op_context, + const char *contexts[]) { /* TODO: remove? */ - ED_region_panels_layout_ex(C, region, ®ion->type->paneltypes, contexts, nullptr); + ED_region_panels_layout_ex(C, region, ®ion->type->paneltypes, op_context, contexts, nullptr); ED_region_panels_draw(C, region); } diff --git a/source/blender/editors/space_buttons/space_buttons.cc b/source/blender/editors/space_buttons/space_buttons.cc index 803cb7d9cb2..aaae845530c 100644 --- a/source/blender/editors/space_buttons/space_buttons.cc +++ b/source/blender/editors/space_buttons/space_buttons.cc @@ -305,7 +305,8 @@ static void buttons_main_region_layout_properties(const bContext *C, const char *contexts[2] = {buttons_main_region_context_string(sbuts->mainb), nullptr}; - ED_region_panels_layout_ex(C, region, ®ion->type->paneltypes, contexts, nullptr); + ED_region_panels_layout_ex( + C, region, ®ion->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts, nullptr); } /** \} */ diff --git a/source/blender/editors/space_image/space_image.cc b/source/blender/editors/space_image/space_image.cc index 153b7bf4542..88b41fd45a5 100644 --- a/source/blender/editors/space_image/space_image.cc +++ b/source/blender/editors/space_image/space_image.cc @@ -807,7 +807,8 @@ static void image_buttons_region_layout(const bContext *C, ARegion *region) break; } - ED_region_panels_layout_ex(C, region, ®ion->type->paneltypes, contexts_base, nullptr); + ED_region_panels_layout_ex( + C, region, ®ion->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts_base, nullptr); } static void image_buttons_region_draw(const bContext *C, ARegion *region) diff --git a/source/blender/editors/space_sequencer/space_sequencer.cc b/source/blender/editors/space_sequencer/space_sequencer.cc index ef788a39641..bbe303e40e3 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.cc +++ b/source/blender/editors/space_sequencer/space_sequencer.cc @@ -675,7 +675,17 @@ static void sequencer_tools_region_init(wmWindowManager *wm, ARegion *region) static void sequencer_tools_region_draw(const bContext *C, ARegion *region) { - ED_region_panels(C, region); + wmOperatorCallContext op_context = WM_OP_INVOKE_REGION_WIN; + switch (region->regiontype) { + case RGN_TYPE_CHANNELS: + op_context = WM_OP_INVOKE_REGION_CHANNELS; + break; + case RGN_TYPE_PREVIEW: + op_context = WM_OP_INVOKE_REGION_PREVIEW; + break; + } + + ED_region_panels_ex(C, region, op_context, nullptr); } /* *********************** preview region ************************ */ diff --git a/source/blender/editors/space_userpref/space_userpref.cc b/source/blender/editors/space_userpref/space_userpref.cc index f649fbf04f4..3996bf40f1e 100644 --- a/source/blender/editors/space_userpref/space_userpref.cc +++ b/source/blender/editors/space_userpref/space_userpref.cc @@ -126,7 +126,8 @@ static void userpref_main_region_layout(const bContext *C, ARegion *region) BLI_str_tolower_ascii(id_lower, strlen(id_lower)); } - ED_region_panels_layout_ex(C, region, ®ion->type->paneltypes, contexts, nullptr); + ED_region_panels_layout_ex( + C, region, ®ion->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts, nullptr); } static void userpref_operatortypes() {} diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index 35948a4fbf1..3de0e952de4 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -1792,7 +1792,8 @@ void ED_view3d_buttons_region_layout_ex(const bContext *C, paneltypes = &art->paneltypes; } - ED_region_panels_layout_ex(C, region, paneltypes, contexts_base, category_override); + ED_region_panels_layout_ex( + C, region, paneltypes, WM_OP_INVOKE_REGION_WIN, contexts_base, category_override); } static void view3d_buttons_region_layout(const bContext *C, ARegion *region) @@ -1921,7 +1922,7 @@ static void view3d_tools_region_init(wmWindowManager *wm, ARegion *region) static void view3d_tools_region_draw(const bContext *C, ARegion *region) { const char *contexts[] = {CTX_data_mode_string(C), nullptr}; - ED_region_panels_ex(C, region, contexts); + ED_region_panels_ex(C, region, WM_OP_INVOKE_REGION_WIN, contexts); } static void view3d_tools_header_region_draw(const bContext *C, ARegion *region) diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.cc b/source/blender/windowmanager/intern/wm_keymap_utils.cc index c39ca90b86c..d02a2eb21b1 100644 --- a/source/blender/windowmanager/intern/wm_keymap_utils.cc +++ b/source/blender/windowmanager/intern/wm_keymap_utils.cc @@ -77,6 +77,8 @@ wmKeyMapItem *WM_keymap_add_tool(wmKeyMap *keymap, wmKeyMap *WM_keymap_guess_from_context(const bContext *C) { + eSpace_Type space_type = SPACE_EMPTY; + eRegion_Type region_type = RGN_TYPE_WINDOW; SpaceLink *sl = CTX_wm_space_data(C); const char *km_id = nullptr; if (sl->spacetype == SPACE_VIEW3D) { @@ -174,11 +176,27 @@ wmKeyMap *WM_keymap_guess_from_context(const bContext *C) break; } } + else if (sl->spacetype == SPACE_SEQ) { + const SpaceSeq *sseq = (SpaceSeq *)sl; + const enum eSpaceSeq_Displays view = eSpaceSeq_Displays(sseq->view); + space_type = SPACE_SEQ; + switch (view) { + case SEQ_VIEW_SEQUENCE: + km_id = "Sequencer"; + break; + case SEQ_VIEW_PREVIEW: + km_id = "SequencerPreview"; + break; + case SEQ_VIEW_SEQUENCE_PREVIEW: + km_id = "SequencerCommon"; + break; + } + } else { return nullptr; } - wmKeyMap *km = WM_keymap_find_all(CTX_wm_manager(C), km_id, SPACE_EMPTY, RGN_TYPE_WINDOW); + wmKeyMap *km = WM_keymap_find_all(CTX_wm_manager(C), km_id, space_type, region_type); BLI_assert(km); return km; }