[Bf-extensions-cvs] [1d722cb7] master: Collection Manager: Add isolate tree feature. Task: T69577

Ryan Inch noreply at git.blender.org
Fri Mar 13 00:42:51 CET 2020


Commit: 1d722cb79a597ab1c7da55071a8bb08ca6874de4
Author: Ryan Inch
Date:   Thu Mar 12 19:38:56 2020 -0400
Branches: master
https://developer.blender.org/rBA1d722cb79a597ab1c7da55071a8bb08ca6874de4

Collection Manager: Add isolate tree feature. Task: T69577

Switches the current hotkey for expanding/collapsing all sublevels from
shift-click to ctrl-click.  Isolate tree is set to shift-click.

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

M	object_collection_manager/__init__.py
M	object_collection_manager/internals.py
M	object_collection_manager/operators.py
M	object_collection_manager/ui.py

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

diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py
index 39a22906..4d895df7 100644
--- a/object_collection_manager/__init__.py
+++ b/object_collection_manager/__init__.py
@@ -22,7 +22,7 @@ bl_info = {
     "name": "Collection Manager",
     "description": "Manage collections and their objects",
     "author": "Ryan Inch",
-    "version": (1,9,3),
+    "version": (1,10,0),
     "blender": (2, 80, 0),
     "location": "View3D - Object Mode (Shortcut - M)",
     "warning": '',  # used for warning icon and text in addons panel
diff --git a/object_collection_manager/internals.py b/object_collection_manager/internals.py
index 5267b1c6..e7f63884 100644
--- a/object_collection_manager/internals.py
+++ b/object_collection_manager/internals.py
@@ -80,7 +80,10 @@ def update_collection_tree(context):
                      "ptr": layer_collection
                      }
 
-    get_all_collections(context, init_laycol_list, master_laycol, collection_tree, visible=True)
+    get_all_collections(context, init_laycol_list, master_laycol, master_laycol["children"], visible=True)
+
+    for laycol in master_laycol["children"]:
+        collection_tree.append(laycol)
 
 
 def get_all_collections(context, collections, parent, tree, level=0, visible=False):
diff --git a/object_collection_manager/operators.py b/object_collection_manager/operators.py
index 7f693ac9..473a5908 100644
--- a/object_collection_manager/operators.py
+++ b/object_collection_manager/operators.py
@@ -73,8 +73,9 @@ class ExpandAllOperator(Operator):
         return {'FINISHED'}
 
 
+expand_history = {"target": "", "history": []}
 class ExpandSublevelOperator(Operator):
-    '''  * Shift-Click to expand/collapse all sublevels'''
+    '''  * Ctrl-Click to expand/collapse all sublevels\n  * Shift-Click to isolate/restore tree'''
     bl_label = "Expand Sublevel Items"
     bl_idname = "view3d.expand_sublevel"
     bl_options = {'REGISTER', 'UNDO'}
@@ -83,8 +84,16 @@ class ExpandSublevelOperator(Operator):
     name: StringProperty()
     index: IntProperty()
 
+    # static class var
+    isolated = False
+
     def invoke(self, context, event):
-        if event.shift:
+        global expand_history
+        cls = ExpandSublevelOperator
+
+        modifiers = get_modifiers(event)
+
+        if modifiers == {"ctrl"}:
             # expand/collapse all subcollections
             expand = None
 
@@ -111,6 +120,35 @@ class ExpandSublevelOperator(Operator):
 
             loop(layer_collections[self.name]["ptr"])
 
+            expand_history["target"] = ""
+            expand_history["history"].clear()
+            cls.isolated = False
+
+        elif modifiers == {"shift"}:
+            def isolate_tree(current_laycol):
+                parent = current_laycol["parent"]
+
+                for laycol in parent["children"]:
+                    if laycol["name"] != current_laycol["name"] and laycol["name"] in expanded:
+                        expanded.remove(laycol["name"])
+                        expand_history["history"].append(laycol["name"])
+
+                if parent["parent"]:
+                    isolate_tree(parent)
+
+            if cls.isolated:
+                for item in expand_history["history"]:
+                    expanded.append(item)
+
+                expand_history["target"] = ""
+                expand_history["history"].clear()
+                cls.isolated = False
+
+            else:
+                isolate_tree(layer_collections[self.name])
+                expand_history["target"] = self.name
+                cls.isolated = True
+
         else:
             # expand/collapse collection
             if self.expand:
@@ -118,6 +156,10 @@ class ExpandSublevelOperator(Operator):
             else:
                 expanded.remove(self.name)
 
+            expand_history["target"] = ""
+            expand_history["history"].clear()
+            cls.isolated = False
+
 
         # set selected row to the collection you're expanding/collapsing and update tree view
         context.scene.collection_manager.cm_list_index = self.index
diff --git a/object_collection_manager/ui.py b/object_collection_manager/ui.py
index dcd804fa..88e9d0cc 100644
--- a/object_collection_manager/ui.py
+++ b/object_collection_manager/ui.py
@@ -37,6 +37,7 @@ from .internals import (
 
 from .operators import (
     rto_history,
+    expand_history,
     phantom_history,
     )
 
@@ -277,8 +278,10 @@ class CM_UL_items(UIList):
         # add expander if collection has children to make UIList act like tree view
         if laycol["has_children"]:
             if laycol["expanded"]:
-                prop = row.operator("view3d.expand_sublevel", text="",
-                                    icon='DISCLOSURE_TRI_DOWN', emboss=False)
+                highlight = True if expand_history["target"] == item.name else False
+
+                prop = row.operator("view3d.expand_sublevel", text="", icon='DISCLOSURE_TRI_DOWN',
+                                    emboss=highlight, depress=highlight)
                 prop.expand = False
                 prop.name = item.name
                 prop.index = index



More information about the Bf-extensions-cvs mailing list