[Bf-blender-cvs] [ffacce5be41] master: UI: Properties editor popover and outliner sync

Nathan Craddock noreply at git.blender.org
Mon Dec 21 22:38:45 CET 2020


Commit: ffacce5be41df68658f8478fee73e74701d2b545
Author: Nathan Craddock
Date:   Mon Dec 21 14:27:09 2020 -0700
Branches: master
https://developer.blender.org/rBffacce5be41df68658f8478fee73e74701d2b545

UI: Properties editor popover and outliner sync

This adds a popover to the properties editor. Currently the only setting
is for controlling outliner to properties syncing.

Because we cannot define a perfect heuristic to determine when
properties editors should change tabs based on outliner icon selection,
we need an option to enable or disable this behavior per properties
editor.

There are 3 options for controlling the syncing. Auto uses the heuristic
to only allow tab switching when a properties editor and outliner share
a border. On and off enable and disable syncing respectively.

Differential Revision: https://developer.blender.org/D9758

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

M	release/scripts/startup/bl_ui/space_properties.py
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/editors/include/ED_buttons.h
M	source/blender/editors/space_buttons/buttons_context.c
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_properties.py b/release/scripts/startup/bl_ui/space_properties.py
index 765cab1ace2..b2a7246af75 100644
--- a/release/scripts/startup/bl_ui/space_properties.py
+++ b/release/scripts/startup/bl_ui/space_properties.py
@@ -46,6 +46,8 @@ class PROPERTIES_HT_header(Header):
 
         layout.separator_spacer()
 
+        layout.popover(panel="PROPERTIES_PT_options", text="")
+
 
 class PROPERTIES_PT_navigation_bar(Panel):
     bl_space_type = 'PROPERTIES'
@@ -69,9 +71,25 @@ class PROPERTIES_PT_navigation_bar(Panel):
             layout.prop_tabs_enum(view, "context", icon_only=True)
 
 
+class PROPERTIES_PT_options(Panel):
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'HEADER'
+    bl_label = 'Options'
+
+    def draw(self, context):
+        layout = self.layout
+
+        space = context.space_data
+
+        col = layout.column()
+        col.label(text="Sync with Outliner")
+        col.row().prop(space, "outliner_sync", expand=True)
+
+
 classes = (
     PROPERTIES_HT_header,
     PROPERTIES_PT_navigation_bar,
+    PROPERTIES_PT_options,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index cd5939b7e63..0c64e835e8b 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -1458,5 +1458,17 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
       }
     }
     FOREACH_NODETREE_END;
+
+    /* Default properties editors to auto outliner sync. */
+    LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+      LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+        LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) {
+          if (space->spacetype == SPACE_PROPERTIES) {
+            SpaceProperties *space_properties = (SpaceProperties *)space;
+            space_properties->outliner_sync = PROPERTIES_SYNC_AUTO;
+          }
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/editors/include/ED_buttons.h b/source/blender/editors/include/ED_buttons.h
index 1ff160b2ca8..af0643f0d64 100644
--- a/source/blender/editors/include/ED_buttons.h
+++ b/source/blender/editors/include/ED_buttons.h
@@ -26,6 +26,7 @@
 extern "C" {
 #endif
 
+struct ScrArea;
 struct SpaceProperties;
 struct bContext;
 
@@ -36,7 +37,13 @@ void ED_buttons_search_string_set(struct SpaceProperties *sbuts, const char *val
 int ED_buttons_search_string_length(struct SpaceProperties *sbuts);
 const char *ED_buttons_search_string_get(struct SpaceProperties *sbuts);
 
-void ED_buttons_set_context(const struct bContext *C, PointerRNA *ptr, const int context);
+bool ED_buttons_should_sync_with_outliner(const struct bContext *C,
+                                          const struct SpaceProperties *sbuts,
+                                          struct ScrArea *area);
+void ED_buttons_set_context(const struct bContext *C,
+                            struct SpaceProperties *sbuts,
+                            PointerRNA *ptr,
+                            const int context);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index c1f29231f96..e2b889bece1 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -752,26 +752,25 @@ static bool is_pointer_in_path(ButsContextPath *path, PointerRNA *ptr)
   return false;
 }
 
-void ED_buttons_set_context(const bContext *C, PointerRNA *ptr, const int context)
+bool ED_buttons_should_sync_with_outliner(const bContext *C,
+                                          const SpaceProperties *sbuts,
+                                          ScrArea *area)
 {
   ScrArea *active_area = CTX_wm_area(C);
-  bScreen *screen = CTX_wm_screen(C);
-
-  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-    /* Only update for properties editors that are visible and share a border. */
-    if (area->spacetype != SPACE_PROPERTIES) {
-      continue;
-    }
-    if (!ED_area_has_shared_border(active_area, area)) {
-      continue;
-    }
+  const bool auto_sync = ED_area_has_shared_border(active_area, area) &&
+                         sbuts->outliner_sync == PROPERTIES_SYNC_AUTO;
+  return auto_sync || sbuts->outliner_sync == PROPERTIES_SYNC_ON;
+}
 
-    SpaceProperties *sbuts = (SpaceProperties *)area->spacedata.first;
-    ButsContextPath path;
-    if (buttons_context_path(C, sbuts, &path, context, 0) && is_pointer_in_path(&path, ptr)) {
-      sbuts->mainbuser = context;
-      sbuts->mainb = sbuts->mainbuser;
-    }
+void ED_buttons_set_context(const bContext *C,
+                            SpaceProperties *sbuts,
+                            PointerRNA *ptr,
+                            const int context)
+{
+  ButsContextPath path;
+  if (buttons_context_path(C, sbuts, &path, context, 0) && is_pointer_in_path(&path, ptr)) {
+    sbuts->mainbuser = context;
+    sbuts->mainb = sbuts->mainbuser;
   }
 }
 
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 6380bb9505e..f8812ff5970 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -1105,6 +1105,24 @@ bPoseChannel *outliner_find_parent_bone(TreeElement *te, TreeElement **r_bone_te
   return NULL;
 }
 
+static void outliner_sync_to_properties_editors(const bContext *C,
+                                                PointerRNA *ptr,
+                                                const int context)
+{
+  bScreen *screen = CTX_wm_screen(C);
+
+  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+    if (area->spacetype != SPACE_PROPERTIES) {
+      continue;
+    }
+
+    SpaceProperties *sbuts = (SpaceProperties *)area->spacedata.first;
+    if (ED_buttons_should_sync_with_outliner(C, sbuts, area)) {
+      ED_buttons_set_context(C, sbuts, ptr, context);
+    }
+  }
+}
+
 static void outliner_set_properties_tab(bContext *C, TreeElement *te, TreeStoreElem *tselem)
 {
   PointerRNA ptr = {0};
@@ -1285,7 +1303,7 @@ static void outliner_set_properties_tab(bContext *C, TreeElement *te, TreeStoreE
   }
 
   if (ptr.data) {
-    ED_buttons_set_context(C, &ptr, context);
+    outliner_sync_to_properties_editors(C, &ptr, context);
   }
 }
 
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 4276e8b568e..f27a89a3d83 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -152,9 +152,12 @@ typedef struct SpaceProperties {
   short mainb, mainbo, mainbuser;
   /** Preview is signal to refresh. */
   short preview;
-  char _pad[5];
+  char _pad[4];
   char flag;
 
+  /* eSpaceButtons_OutlinerSync */
+  char outliner_sync;
+
   /** Runtime. */
   void *path;
   /** Runtime. */
@@ -232,6 +235,13 @@ typedef enum eSpaceButtons_Flag {
   SB_SHADING_CONTEXT = (1 << 4),
 } eSpaceButtons_Flag;
 
+/* SpaceProperties.outliner_sync */
+typedef enum eSpaceButtons_OutlinerSync {
+  PROPERTIES_SYNC_AUTO = 0,
+  PROPERTIES_SYNC_OFF = 1,
+  PROPERTIES_SYNC_ON = 2,
+} eSpaceButtons_OutlinerSync;
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index acfb317c616..fb8f472ad76 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -4776,6 +4776,17 @@ static void rna_def_space_properties(BlenderRNA *brna)
   StructRNA *srna;
   PropertyRNA *prop;
 
+  static const EnumPropertyItem tab_sync_items[] = {
+      {PROPERTIES_SYNC_ON, "ON", 0, "On", "Always sync from outliner editors to this editor"},
+      {PROPERTIES_SYNC_OFF, "OFF", 0, "Off", "Never sync from outliner editors to this editor"},
+      {PROPERTIES_SYNC_AUTO,
+       "AUTO",
+       0,
+       "Auto",
+       "Sync when this editor shares an edge with an outliner editor"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   srna = RNA_def_struct(brna, "SpaceProperties", "Space");
   RNA_def_struct_sdna(srna, "SpaceProperties");
   RNA_def_struct_ui_text(srna, "Properties Space", "Properties space data");
@@ -4826,6 +4837,13 @@ static void rna_def_space_properties(BlenderRNA *brna)
   RNA_def_property_flag(prop, PROP_TEXTEDIT_UPDATE);
   RNA_def_property_update(
       prop, NC_SPACE | ND_SPACE_PROPERTIES, "rna_SpaceProperties_search_filter_update");
+
+  /* Outliner sync. */
+  prop = RNA_def_property(srna, "outliner_sync", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "outliner_sync");
+  RNA_def_property_enum_items(prop, tab_sync_items);
+  RNA_def_property_ui_text(prop, "Outliner Sync", "Sync tabs from outliner datablock selection");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL);
 }
 
 static void rna_def_space_image_overlay(BlenderRNA *brna)



More information about the Bf-blender-cvs mailing list