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
This commit is contained in:
Richard Antalik
2024-01-31 19:04:09 +01:00
committed by Richard Antalik
parent a1792e98a4
commit fa6384eb39
8 changed files with 56 additions and 11 deletions

View File

@@ -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);
/**

View File

@@ -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, &region->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, &region->type->paneltypes, nullptr, nullptr);
ED_region_panels_layout_ex(
C, region, &region->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, &region->type->paneltypes, contexts, nullptr);
ED_region_panels_layout_ex(C, region, &region->type->paneltypes, op_context, contexts, nullptr);
ED_region_panels_draw(C, region);
}

View File

@@ -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, &region->type->paneltypes, contexts, nullptr);
ED_region_panels_layout_ex(
C, region, &region->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts, nullptr);
}
/** \} */

View File

@@ -807,7 +807,8 @@ static void image_buttons_region_layout(const bContext *C, ARegion *region)
break;
}
ED_region_panels_layout_ex(C, region, &region->type->paneltypes, contexts_base, nullptr);
ED_region_panels_layout_ex(
C, region, &region->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts_base, nullptr);
}
static void image_buttons_region_draw(const bContext *C, ARegion *region)

View File

@@ -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 ************************ */

View File

@@ -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, &region->type->paneltypes, contexts, nullptr);
ED_region_panels_layout_ex(
C, region, &region->type->paneltypes, WM_OP_INVOKE_REGION_WIN, contexts, nullptr);
}
static void userpref_operatortypes() {}

View File

@@ -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)

View File

@@ -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;
}