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 <campbell@blender.org>2022-05-20 07:30:17 +0300
committerCampbell Barton <campbell@blender.org>2022-05-26 05:16:35 +0300
commit3f3d82cfe9cefe4bfd9da3d283dec4a1923ec22d (patch)
tree532de0110686d29f63c550c4784f8d2acc86e110 /source/blender/windowmanager/intern
parent11480763b62e6ca72ae869391b8e5495e57410a6 (diff)
UI support for showing candidates for string properties
Currently strings are used for cases where a list of identifiers would be useful to show. Add support for string properties to reference a callback to populate candidates to show when editing a string. The user isn't prevented from typing in text not found in this list, it's just useful as a reference. Support for expanding the following strings has been added: - Operator, menu & panel identifiers in the keymap editor. - WM operators that reference data-paths expand using the Python-consoles auto-complete functionality. - Names of keying sets for insert/delete keyframe operators. Details: - `bpy.props.StringProperty` takes an option `search` callback. - A new string callback has been added, set via `RNA_def_property_string_search_func` or `RNA_def_property_string_search_func_runtime`. - Addresses usability issue highlighted by T89560, where setting keying set identifiers as strings isn't practical. - Showing additional right-aligned text in the search results is supported but disabled by default as the text is too cramped in most string search popups where the feature would make sense. It could be enabled as part of other layout tweaks. Reviewed By: brecht Ref D14986
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r--source/blender/windowmanager/intern/wm_menu_type.c18
-rw-r--r--source/blender/windowmanager/intern/wm_operator_type.c21
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c23
-rw-r--r--source/blender/windowmanager/intern/wm_panel_type.c18
4 files changed, 78 insertions, 2 deletions
diff --git a/source/blender/windowmanager/intern/wm_menu_type.c b/source/blender/windowmanager/intern/wm_menu_type.c
index 9e50ebb1ce5..b4cf5a79cfa 100644
--- a/source/blender/windowmanager/intern/wm_menu_type.c
+++ b/source/blender/windowmanager/intern/wm_menu_type.c
@@ -99,3 +99,21 @@ bool WM_menutype_poll(bContext *C, MenuType *mt)
}
return true;
}
+
+void WM_menutype_idname_visit_for_search(const bContext *UNUSED(C),
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ const char *UNUSED(edit_text),
+ StringPropertySearchVisitFunc visit_fn,
+ void *visit_user_data)
+{
+ GHashIterator gh_iter;
+ GHASH_ITER (gh_iter, menutypes_hash) {
+ MenuType *mt = BLI_ghashIterator_getValue(&gh_iter);
+
+ StringPropertySearchVisitParams visit_params = {NULL};
+ visit_params.text = mt->idname;
+ visit_params.info = mt->label;
+ visit_fn(visit_user_data, &visit_params);
+ }
+}
diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c
index 8aa8469f0bc..d1c27504628 100644
--- a/source/blender/windowmanager/intern/wm_operator_type.c
+++ b/source/blender/windowmanager/intern/wm_operator_type.c
@@ -246,6 +246,27 @@ void WM_operatortype_last_properties_clear_all(void)
}
}
+void WM_operatortype_idname_visit_for_search(const bContext *UNUSED(C),
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ const char *UNUSED(edit_text),
+ StringPropertySearchVisitFunc visit_fn,
+ void *visit_user_data)
+{
+ GHashIterator gh_iter;
+ GHASH_ITER (gh_iter, global_ops_hash) {
+ wmOperatorType *ot = BLI_ghashIterator_getValue(&gh_iter);
+
+ char idname_py[OP_MAX_TYPENAME];
+ WM_operator_py_idname(idname_py, ot->idname);
+
+ StringPropertySearchVisitParams visit_params = {NULL};
+ visit_params.text = idname_py;
+ visit_params.info = ot->name;
+ visit_fn(visit_user_data, &visit_params);
+ }
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index c3f2f9d15ca..307d3282659 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -1870,7 +1870,14 @@ static void WM_OT_call_menu(wmOperatorType *ot)
ot->flag = OPTYPE_INTERNAL;
- RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the menu");
+ PropertyRNA *prop;
+
+ prop = RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the menu");
+ RNA_def_property_string_search_func_runtime(
+ prop,
+ WM_menutype_idname_visit_for_search,
+ /* Only a suggestion as menu items may be referenced from add-ons that have been disabled. */
+ (PROP_STRING_SEARCH_SORT | PROP_STRING_SEARCH_SUGGESTION));
}
static int wm_call_pie_menu_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@@ -1902,7 +1909,14 @@ static void WM_OT_call_menu_pie(wmOperatorType *ot)
ot->flag = OPTYPE_INTERNAL;
- RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the pie menu");
+ PropertyRNA *prop;
+
+ prop = RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the pie menu");
+ RNA_def_property_string_search_func_runtime(
+ prop,
+ WM_menutype_idname_visit_for_search,
+ /* Only a suggestion as menu items may be referenced from add-ons that have been disabled. */
+ (PROP_STRING_SEARCH_SORT | PROP_STRING_SEARCH_SUGGESTION));
}
static int wm_call_panel_exec(bContext *C, wmOperator *op)
@@ -1938,6 +1952,11 @@ static void WM_OT_call_panel(wmOperatorType *ot)
PropertyRNA *prop;
prop = RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the menu");
+ RNA_def_property_string_search_func_runtime(
+ prop,
+ WM_paneltype_idname_visit_for_search,
+ /* Only a suggestion as menu items may be referenced from add-ons that have been disabled. */
+ (PROP_STRING_SEARCH_SORT | PROP_STRING_SEARCH_SUGGESTION));
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
prop = RNA_def_boolean(ot->srna, "keep_open", true, "Keep Open", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
diff --git a/source/blender/windowmanager/intern/wm_panel_type.c b/source/blender/windowmanager/intern/wm_panel_type.c
index bfcc86c38e7..860b53c1071 100644
--- a/source/blender/windowmanager/intern/wm_panel_type.c
+++ b/source/blender/windowmanager/intern/wm_panel_type.c
@@ -65,3 +65,21 @@ void WM_paneltype_clear(void)
{
BLI_ghash_free(g_paneltypes_hash, NULL, NULL);
}
+
+void WM_paneltype_idname_visit_for_search(const bContext *UNUSED(C),
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ const char *UNUSED(edit_text),
+ StringPropertySearchVisitFunc visit_fn,
+ void *visit_user_data)
+{
+ GHashIterator gh_iter;
+ GHASH_ITER (gh_iter, g_paneltypes_hash) {
+ PanelType *pt = BLI_ghashIterator_getValue(&gh_iter);
+
+ StringPropertySearchVisitParams visit_params = {NULL};
+ visit_params.text = pt->idname;
+ visit_params.info = pt->label;
+ visit_fn(visit_user_data, &visit_params);
+ }
+}