Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-03-24 03:34:18 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-03-24 05:41:18 +0300
commitc46dcdf8871e7404516a234087cfc4bf4e2794d0 (patch)
treeca5f6d549a3294441a452ae04507e46360324bad /source/blender/windowmanager
parent94b8166a8b0519aef76e8cb8d0c9a6035fe04baf (diff)
UI: add menu search functionality to operator search menu
This has some advantages over operator search: - Some operators need options set to be usefully accessed. - Shows key bindings to access menus (for actions that don't have key bindings themselves). - Non operator actions such as check-boxes are also shown. - Menu items can control execution context, using invoke or execute where appropriate so we can control how the operator runs. Part of the design task T74157. This can be tested using the 'Experimental' preferences section or selected in the key-map editor.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 961854ac23e..2ae71eb2490 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -1687,10 +1687,15 @@ static void WM_OT_operator_defaults(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Operator Search Menu
+/** \name Operator/Menu Search Operator
* \{ */
struct SearchPopupInit_Data {
+ enum {
+ SEARCH_TYPE_OPERATOR = 0,
+ SEARCH_TYPE_MENU = 1,
+ } search_type;
+
int size[2];
};
@@ -1717,7 +1722,17 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *region, void *userdat
0,
0,
"");
- UI_but_func_operator_search(but);
+
+ if (init_data->search_type == SEARCH_TYPE_OPERATOR) {
+ UI_but_func_operator_search(but);
+ }
+ else if (init_data->search_type == SEARCH_TYPE_MENU) {
+ UI_but_func_menu_search(but);
+ }
+ else {
+ BLI_assert(0);
+ }
+
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
/* fake button, it holds space for search items */
@@ -1747,7 +1762,7 @@ static int wm_search_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
-static int wm_search_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+static int wm_search_menu_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
/* Exception for launching via spacebar */
if (event->type == EVT_SPACEKEY) {
@@ -1775,9 +1790,20 @@ static int wm_search_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
}
}
+ PropertyRNA *prop = op->type->prop;
+ int search_type;
+ if (RNA_property_is_set(op->ptr, prop)) {
+ search_type = RNA_property_enum_get(op->ptr, prop);
+ }
+ else {
+ search_type = U.experimental.use_menu_search ? SEARCH_TYPE_MENU : SEARCH_TYPE_OPERATOR;
+ }
+
static struct SearchPopupInit_Data data;
- data.size[0] = UI_searchbox_size_x() * 2;
- data.size[1] = UI_searchbox_size_y();
+ data = (struct SearchPopupInit_Data){
+ .search_type = search_type,
+ .size = {UI_searchbox_size_x() * 2, UI_searchbox_size_y()},
+ };
UI_popup_block_invoke(C, wm_block_search_menu, &data, NULL);
@@ -1793,6 +1819,15 @@ static void WM_OT_search_menu(wmOperatorType *ot)
ot->invoke = wm_search_menu_invoke;
ot->exec = wm_search_menu_exec;
ot->poll = WM_operator_winactive;
+
+ static const EnumPropertyItem search_type_items[] = {
+ {SEARCH_TYPE_OPERATOR, "OPERATOR", 0, "Operator", "Search all operators"},
+ {SEARCH_TYPE_MENU, "MENU", 0, "Menu", "Search active menu items"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "type", search_type_items, SEARCH_TYPE_OPERATOR, "Type", "");
}
static int wm_call_menu_exec(bContext *C, wmOperator *op)