[Bf-extensions-cvs] [bc591c92] master: Collection Manager: initial implementation of suggestions by draguu from blenderartists

Ryan Inch noreply at git.blender.org
Sun Nov 3 03:41:11 CET 2019


Commit: bc591c92bd965ef94b4088270da42d7fa4f35929
Author: Ryan Inch
Date:   Sat Nov 2 22:40:55 2019 -0400
Branches: master
https://developer.blender.org/rBACbc591c92bd965ef94b4088270da42d7fa4f35929

Collection Manager: initial implementation of suggestions by draguu from blenderartists

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

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

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

diff --git a/collection_manager/__init__.py b/collection_manager/__init__.py
index 94537381..f5afe58a 100644
--- a/collection_manager/__init__.py
+++ b/collection_manager/__init__.py
@@ -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
diff --git a/collection_manager/internals.py b/collection_manager/internals.py
index 1734f3e0..d2b3abf4 100644
--- a/collection_manager/internals.py
+++ b/collection_manager/internals.py
@@ -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)
diff --git a/collection_manager/operators.py b/collection_manager/operators.py
index 6a498e55..9ece24a2 100644
--- a/collection_manager/operators.py
+++ b/collection_manager/operators.py
@@ -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()
diff --git a/collection_manager/ui.py b/collection_manager/ui.py
index cd9ff389..971d8a4a 100644
--- a/collection_manager/ui.py
+++ b/collection_manager/ui.py
@@ -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



More information about the Bf-extensions-cvs mailing list