Cleanup: split keymap lookups into own functions
More will be added in 2.8, keep this manageable.
This commit is contained in:
@@ -942,7 +942,6 @@ static void ui_menu_block_set_keyaccels(uiBlock *block)
|
|||||||
* but this could be supported */
|
* but this could be supported */
|
||||||
void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_strip)
|
void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_strip)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (do_strip && (but->flag & UI_BUT_HAS_SEP_CHAR)) {
|
if (do_strip && (but->flag & UI_BUT_HAS_SEP_CHAR)) {
|
||||||
char *cpoin = strrchr(but->str, UI_SEP_CHAR);
|
char *cpoin = strrchr(but->str, UI_SEP_CHAR);
|
||||||
if (cpoin) {
|
if (cpoin) {
|
||||||
@@ -973,43 +972,70 @@ void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
/** \name Find Key Shortcut for Button
|
||||||
|
*
|
||||||
|
* - #ui_but_event_operator_string (and helpers)
|
||||||
|
* - #ui_but_event_property_operator_string
|
||||||
|
* \{ */
|
||||||
|
|
||||||
|
static bool ui_but_event_operator_string_from_operator(
|
||||||
|
const bContext *C, uiBut *but,
|
||||||
|
char *buf, const size_t buf_len)
|
||||||
|
{
|
||||||
|
BLI_assert(but->optype != NULL);
|
||||||
|
bool found = false;
|
||||||
|
IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
|
||||||
|
|
||||||
|
if (WM_key_event_operator_string(
|
||||||
|
C, but->optype->idname, but->opcontext, prop, true,
|
||||||
|
buf, buf_len))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ui_but_event_operator_string_from_menu(
|
||||||
|
const bContext *C, uiBut *but,
|
||||||
|
char *buf, const size_t buf_len)
|
||||||
|
{
|
||||||
|
MenuType *mt = UI_but_menutype_get(but);
|
||||||
|
BLI_assert(mt != NULL);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
IDProperty *prop_menu, *prop_menu_name;
|
||||||
|
|
||||||
|
/* annoying, create a property */
|
||||||
|
IDPropertyTemplate val = {0};
|
||||||
|
prop_menu = IDP_New(IDP_GROUP, &val, __func__); /* dummy, name is unimportant */
|
||||||
|
IDP_AddToGroup(prop_menu, (prop_menu_name = IDP_NewString("", "name", sizeof(mt->idname))));
|
||||||
|
|
||||||
|
IDP_AssignString(prop_menu_name, mt->idname, sizeof(mt->idname));
|
||||||
|
|
||||||
|
if (WM_key_event_operator_string(
|
||||||
|
C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true,
|
||||||
|
buf, buf_len))
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDP_FreeProperty(prop_menu);
|
||||||
|
MEM_freeN(prop_menu);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
static bool ui_but_event_operator_string(
|
static bool ui_but_event_operator_string(
|
||||||
const bContext *C, uiBut *but,
|
const bContext *C, uiBut *but,
|
||||||
char *buf, const size_t buf_len)
|
char *buf, const size_t buf_len)
|
||||||
{
|
{
|
||||||
MenuType *mt;
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if (but->optype) {
|
if (but->optype != NULL) {
|
||||||
IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
|
found = ui_but_event_operator_string_from_operator(C, but, buf, buf_len);
|
||||||
|
|
||||||
if (WM_key_event_operator_string(
|
|
||||||
C, but->optype->idname, but->opcontext, prop, true,
|
|
||||||
buf, buf_len))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ((mt = UI_but_menutype_get(but))) {
|
else if (UI_but_menutype_get(but) != NULL) {
|
||||||
IDProperty *prop_menu;
|
found = ui_but_event_operator_string_from_menu(C, but, buf, buf_len);
|
||||||
IDProperty *prop_menu_name;
|
|
||||||
|
|
||||||
/* annoying, create a property */
|
|
||||||
IDPropertyTemplate val = {0};
|
|
||||||
prop_menu = IDP_New(IDP_GROUP, &val, __func__); /* dummy, name is unimportant */
|
|
||||||
IDP_AddToGroup(prop_menu, (prop_menu_name = IDP_NewString("", "name", sizeof(mt->idname))));
|
|
||||||
|
|
||||||
IDP_AssignString(prop_menu_name, mt->idname, sizeof(mt->idname));
|
|
||||||
|
|
||||||
if (WM_key_event_operator_string(
|
|
||||||
C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, true,
|
|
||||||
buf, buf_len))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
IDP_FreeProperty(prop_menu);
|
|
||||||
MEM_freeN(prop_menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
@@ -1131,6 +1157,8 @@ static bool ui_but_event_property_operator_string(
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** \} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This goes in a seemingly weird pattern:
|
* This goes in a seemingly weird pattern:
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user