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 /source/blender/makesrna/intern/rna_access.c | |
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 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index ccb7e1c69bc..c8cb0b7ffb8 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -3369,6 +3369,34 @@ int RNA_property_string_default_length(PointerRNA *UNUSED(ptr), PropertyRNA *pro return strlen(sprop->defaultvalue); } +eStringPropertySearchFlag RNA_property_string_search_flag(PropertyRNA *prop) +{ + StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop); + if (prop->magic != RNA_MAGIC) { + return false; + } + BLI_assert(RNA_property_type(prop) == PROP_STRING); + if (sprop->search) { + BLI_assert(sprop->search_flag & PROP_STRING_SEARCH_SUPPORTED); + } + else { + BLI_assert(sprop->search_flag == 0); + } + return sprop->search_flag; +} + +void RNA_property_string_search(const bContext *C, + PointerRNA *ptr, + PropertyRNA *prop, + const char *edit_text, + StringPropertySearchVisitFunc visit_fn, + void *visit_user_data) +{ + BLI_assert(RNA_property_string_search_flag(prop) & PROP_STRING_SEARCH_SUPPORTED); + StringPropertyRNA *sprop = (StringPropertyRNA *)rna_ensure_property(prop); + sprop->search(C, ptr, prop, edit_text, visit_fn, visit_user_data); +} + int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop) { EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; |