diff options
author | Campbell Barton <campbell@blender.org> | 2022-05-20 07:30:17 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-05-26 05:16:35 +0300 |
commit | 3f3d82cfe9cefe4bfd9da3d283dec4a1923ec22d (patch) | |
tree | 532de0110686d29f63c550c4784f8d2acc86e110 /release/scripts/startup | |
parent | 11480763b62e6ca72ae869391b8e5495e57410a6 (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 'release/scripts/startup')
-rw-r--r-- | release/scripts/startup/bl_operators/wm.py | 18 |
1 files changed, 18 insertions, 0 deletions
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( |