[Bf-blender-cvs] [ae5d3fa2d03] master: UI: use visible regions when showing candidates for operators data-path

Campbell Barton noreply at git.blender.org
Thu May 26 06:16:33 CEST 2022


Commit: ae5d3fa2d03f9be43e1562449f9c9064920d06fe
Author: Campbell Barton
Date:   Thu May 26 13:44:24 2022 +1000
Branches: master
https://developer.blender.org/rBae5d3fa2d03f9be43e1562449f9c9064920d06fe

UI: use visible regions when showing candidates for operators data-path

When expanding the data path for the context, use Context.temp_override
to extract context members. Without this, only context-members available
in the preferences were used which misses members which are likely to
be useful.

Iterate over all windows, areas and regions showing unique member as
candidates. The search is limited to WINDOW/PREVIEW region types, the
preferences space type is also excluded. See the doc-string for
rna_path_prop_search_for_context for additional notes on this.

===================================================================

M	release/scripts/startup/bl_operators/wm.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 09dbd2e5334..37d7ef19a28 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -22,7 +22,7 @@ from bpy.props import (
 from bpy.app.translations import pgettext_iface as iface_
 
 
-def rna_path_prop_search_for_context(self, context, edit_text):
+def _rna_path_prop_search_for_context_impl(context, edit_text, unique_attrs):
     # 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."
@@ -32,15 +32,55 @@ def rna_path_prop_search_for_context(self, context, edit_text):
     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(("(", ")")):
+        if attr.endswith((
+                # Exclude function calls because they are generally not part of data-paths.
+                "(", ")",
+                # RNA properties for introspection, not useful to expand.
+                ".bl_rna", ".rna_type",
+        )):
+            continue
+        attr_full = prefix + attr.lstrip()
+        if attr_full in unique_attrs:
             continue
-        yield prefix + attr.lstrip()
+        unique_attrs.add(attr_full)
+        yield attr_full
+
+
+def rna_path_prop_search_for_context(self, context, edit_text):
+    # NOTE(@campbellbarton): Limiting data-path expansion is rather arbitrary.
+    # It's possible for e.g. that someone would want to set a shortcut in the preferences or
+    # in other region types than those currently expanded. Unless there is a reasonable likelihood
+    # users might expand these space-type/region-type combinations - exclude them from this search.
+    # After all, this list is mainly intended as a hint, users are not prevented from constructing
+    # the data-paths themselves.
+    unique_attrs = set()
+
+    for window in context.window_manager.windows:
+        for area in window.screen.areas:
+            # Users are very unlikely to be setting shortcuts in the preferences, skip this.
+            if area.type == 'PREFERENCES':
+                continue
+            space = area.spaces.active
+            # Ignore the same region type multiple times in an area.
+            # Prevents the 3D-viewport quad-view from attempting to expand 3 extra times for e.g.
+            region_type_unique = set()
+            for region in area.regions:
+                if region.type not in {'WINDOW', 'PREVIEW'}:
+                    continue
+                if region.type in region_type_unique:
+                    continue
+                region_type_unique.add(region.type)
+                with context.temp_override(window=window, area=area, region=region):
+                    yield from _rna_path_prop_search_for_context_impl(context, edit_text, unique_attrs)
+
+    if not unique_attrs:
+        # Users *might* only have a preferences area shown, in that case just expand the current context.
+        yield from _rna_path_prop_search_for_context_impl(context, edit_text, unique_attrs)
 
 
 rna_path_prop = StringProperty(
     name="Context Attributes",
-    description="RNA context string",
+    description="Context data-path (expanded using visible windows in the current .blend file)",
     maxlen=1024,
     search=rna_path_prop_search_for_context,
 )



More information about the Bf-blender-cvs mailing list