From 3f3d82cfe9cefe4bfd9da3d283dec4a1923ec22d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 20 May 2022 14:30:17 +1000 Subject: 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 --- release/scripts/startup/bl_operators/wm.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'release') diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 0f063da40fb..09dbd2e5334 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -21,10 +21,28 @@ from bpy.props import ( ) from bpy.app.translations import pgettext_iface as iface_ + +def rna_path_prop_search_for_context(self, context, edit_text): + # Use the same logic as auto-completing in the Python console to expand the data-path. + from bl_console_utils.autocomplete import intellisense + context_prefix = "context." + line = context_prefix + edit_text + cursor = len(line) + namespace = {"context": context} + comp_prefix, _, comp_options = intellisense.expand(line=line, cursor=len(line), namespace=namespace, private=False) + prefix = comp_prefix[len(context_prefix):] # Strip "context." + for attr in comp_options.split("\n"): + # Exclude function calls because they are generally not part of data-paths. + if attr.endswith(("(", ")")): + continue + yield prefix + attr.lstrip() + + rna_path_prop = StringProperty( name="Context Attributes", description="RNA context string", maxlen=1024, + search=rna_path_prop_search_for_context, ) rna_reverse_prop = BoolProperty( -- cgit v1.2.3