diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py index 39a22906f0a21999e096c8aff77e9f87f8a6f6c8..4d895df7b403eb3b860ebc7b3287c89ddfcba63b 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 5267b1c6f7e44cedfe8455021377e7759fffa817..e7f63884261ab49a04e89e8bd8553fc9713e3c0c 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 7f693ac9116c058dc0816a8a322bb896a66e77c1..473a59087c823699c67452e97bef584c394a46a4 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 dcd804fa5134303c91711af3a977365bca225dc0..88e9d0ccdbea6dd7d936d363ef681e651003b860 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