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
This commit is contained in:
2022-05-20 14:30:17 +10:00
parent 11480763b6
commit 3f3d82cfe9
21 changed files with 766 additions and 70 deletions

View File

@@ -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(