Skip to content
Snippets Groups Projects
Commit 1d722cb7 authored by Ryan Inch's avatar Ryan Inch
Browse files

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.
parent 1ae12e6f
Branches
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ bl_info = { ...@@ -22,7 +22,7 @@ bl_info = {
"name": "Collection Manager", "name": "Collection Manager",
"description": "Manage collections and their objects", "description": "Manage collections and their objects",
"author": "Ryan Inch", "author": "Ryan Inch",
"version": (1,9,3), "version": (1,10,0),
"blender": (2, 80, 0), "blender": (2, 80, 0),
"location": "View3D - Object Mode (Shortcut - M)", "location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel "warning": '', # used for warning icon and text in addons panel
......
...@@ -80,7 +80,10 @@ def update_collection_tree(context): ...@@ -80,7 +80,10 @@ def update_collection_tree(context):
"ptr": layer_collection "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): def get_all_collections(context, collections, parent, tree, level=0, visible=False):
......
...@@ -73,8 +73,9 @@ class ExpandAllOperator(Operator): ...@@ -73,8 +73,9 @@ class ExpandAllOperator(Operator):
return {'FINISHED'} return {'FINISHED'}
expand_history = {"target": "", "history": []}
class ExpandSublevelOperator(Operator): 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_label = "Expand Sublevel Items"
bl_idname = "view3d.expand_sublevel" bl_idname = "view3d.expand_sublevel"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
...@@ -83,8 +84,16 @@ class ExpandSublevelOperator(Operator): ...@@ -83,8 +84,16 @@ class ExpandSublevelOperator(Operator):
name: StringProperty() name: StringProperty()
index: IntProperty() index: IntProperty()
# static class var
isolated = False
def invoke(self, context, event): 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/collapse all subcollections
expand = None expand = None
...@@ -111,6 +120,35 @@ class ExpandSublevelOperator(Operator): ...@@ -111,6 +120,35 @@ class ExpandSublevelOperator(Operator):
loop(layer_collections[self.name]["ptr"]) 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: else:
# expand/collapse collection # expand/collapse collection
if self.expand: if self.expand:
...@@ -118,6 +156,10 @@ class ExpandSublevelOperator(Operator): ...@@ -118,6 +156,10 @@ class ExpandSublevelOperator(Operator):
else: else:
expanded.remove(self.name) 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 # set selected row to the collection you're expanding/collapsing and update tree view
context.scene.collection_manager.cm_list_index = self.index context.scene.collection_manager.cm_list_index = self.index
......
...@@ -37,6 +37,7 @@ from .internals import ( ...@@ -37,6 +37,7 @@ from .internals import (
from .operators import ( from .operators import (
rto_history, rto_history,
expand_history,
phantom_history, phantom_history,
) )
...@@ -277,8 +278,10 @@ class CM_UL_items(UIList): ...@@ -277,8 +278,10 @@ class CM_UL_items(UIList):
# add expander if collection has children to make UIList act like tree view # add expander if collection has children to make UIList act like tree view
if laycol["has_children"]: if laycol["has_children"]:
if laycol["expanded"]: if laycol["expanded"]:
prop = row.operator("view3d.expand_sublevel", text="", highlight = True if expand_history["target"] == item.name else False
icon='DISCLOSURE_TRI_DOWN', emboss=False)
prop = row.operator("view3d.expand_sublevel", text="", icon='DISCLOSURE_TRI_DOWN',
emboss=highlight, depress=highlight)
prop.expand = False prop.expand = False
prop.name = item.name prop.name = item.name
prop.index = index prop.index = index
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment