Commit bc591c92 authored by Ryan Inch's avatar Ryan Inch
Browse files

Collection Manager: initial implementation of suggestions by draguu from blenderartists

parent 786f4704
......@@ -23,7 +23,7 @@ bl_info = {
"name": "Collection Manager",
"description": "Manage collections and their objects",
"author": "Ryan Inch",
"version": (1,0),
"version": (1,1),
"blender": (2, 80, 0),
"location": "View3D - Object Mode",
"warning": '', # used for warning icon and text in addons panel
......
......@@ -8,6 +8,7 @@ collection_tree = []
expanded = []
max_lvl = 0
row_index = 0
def get_max_lvl():
return max_lvl
......@@ -18,15 +19,18 @@ class CMListCollection(PropertyGroup):
def update_collection_tree(context):
global max_lvl
global row_index
collection_tree.clear()
layer_collections.clear()
max_lvl = 0
row_index = 0
init_laycol_list = context.view_layer.layer_collection.children
master_laycol = {"id": 0,
"name": context.view_layer.layer_collection.name,
"lvl": -1,
"row_index": -1,
"visible": True,
"has_children": True,
"expanded": True,
......@@ -39,10 +43,13 @@ def update_collection_tree(context):
def get_all_collections(context, collections, parent, tree, level=0, visible=False):
global row_index
for item in collections:
laycol = {"id": len(layer_collections) +1,
"name": item.name,
"lvl": level,
"row_index": row_index,
"visible": visible,
"has_children": False,
"expanded": False,
......@@ -51,6 +58,8 @@ def get_all_collections(context, collections, parent, tree, level=0, visible=Fal
"ptr": item
}
row_index += 1
layer_collections[item.name] = laycol
tree.append(laycol)
......@@ -61,7 +70,7 @@ def get_all_collections(context, collections, parent, tree, level=0, visible=Fal
if item.name in expanded and laycol["visible"]:
laycol["expanded"] = True
get_all_collections(context, item.children, laycol, laycol["children"], level+1, visible=True)
get_all_collections(context, item.children, laycol, laycol["children"], level+1, visible=True)
else:
get_all_collections(context, item.children, laycol, laycol["children"], level+1)
......
......@@ -713,7 +713,7 @@ class CMRemoveCollectionOperator(bpy.types.Operator):
return {'FINISHED'}
rename = [False]
class CMNewCollectionOperator(bpy.types.Operator):
'''Add New Collection'''
bl_label = "Add New Collection"
......@@ -735,16 +735,30 @@ class CMNewCollectionOperator(bpy.types.Operator):
laycol["ptr"].collection.children.link(new_collection)
expanded.append(laycol["name"])
# update tree view property
update_property_group(context)
scn.CMListIndex = layer_collections[new_collection.name]["row_index"]
else:
laycol["parent"]["ptr"].collection.children.link(new_collection)
# update tree view property
update_property_group(context)
scn.CMListIndex = layer_collections[new_collection.name]["row_index"]
# if no collections add top level collection and select it
else:
scn.collection.children.link(new_collection)
# update tree view property
update_property_group(context)
scn.CMListIndex = 0
# update tree view
update_property_group(context)
global rename
rename[0] = True
# reset history
exclude_history.clear()
......
......@@ -12,6 +12,7 @@ from .operators import (
hideall_history,
disableviewall_history,
disablerenderall_history,
rename,
)
......@@ -118,7 +119,7 @@ class CollectionManager(Operator):
#disablerenderall_history.clear()
context.scene.CMListIndex = 0
#context.scene.CMListIndex = 0
update_property_group(context)
if get_max_lvl() > 5:
......@@ -170,7 +171,13 @@ class CM_UL_items(UIList):
row.label(icon='GROUP')
row.prop(collection, "name", text="", expand=True)
name_row = row.row()
#if rename[0] and index == scn.CMListIndex:
#name_row.activate_init = True
#rename[0] = False
name_row.prop(collection, "name", text="", expand=True)
# used as a separator (actual separator not wide enough)
row.label()
......@@ -213,6 +220,9 @@ class CM_UL_items(UIList):
icon = 'RESTRICT_RENDER_ON' if laycol["ptr"].collection.hide_render else 'RESTRICT_RENDER_OFF'
row.operator("view3d.disable_render_collection", text="", icon=icon, emboss=False).name = item.name
row.separator()
#row.label(text="|")
row.separator()
row.operator("view3d.remove_collection", text="", icon='X', emboss=False).collection_name = item.name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment