[Bf-extensions-cvs] [67ef6e56] blender-v2.83-release: Collection Manager: Fix active collections. Task: T69577

Ryan Inch noreply at git.blender.org
Sat Apr 25 10:30:59 CEST 2020


Commit: 67ef6e567b19c57720674242bb24c8d72c14e2ef
Author: Ryan Inch
Date:   Sat Apr 25 04:15:30 2020 -0400
Branches: blender-v2.83-release
https://developer.blender.org/rBA67ef6e567b19c57720674242bb24c8d72c14e2ef

Collection Manager: Fix active collections. Task: T69577

Fix display of and interaction with active collections.

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

M	object_collection_manager/__init__.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 3ee2b18e..67300a8b 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": (2, 7, 13),
+    "version": (2, 7, 14),
     "blender": (2, 80, 0),
     "location": "View3D - Object Mode (Shortcut - M)",
     "warning": '',  # used for warning icon and text in addons panel
@@ -68,7 +68,7 @@ from bpy.props import (
 
 class CollectionManagerProperties(PropertyGroup):
     cm_list_collection: CollectionProperty(type=internals.CMListCollection)
-    cm_list_index: IntProperty(update=ui.update_selection)
+    cm_list_index: IntProperty()
 
     show_exclude: BoolProperty(default=True, name="[EC] Exclude from View Layer")
     show_selectable: BoolProperty(default=True, name="[SS] Disable Selection")
diff --git a/object_collection_manager/operators.py b/object_collection_manager/operators.py
index c1259acd..b03370d9 100644
--- a/object_collection_manager/operators.py
+++ b/object_collection_manager/operators.py
@@ -69,13 +69,13 @@ class SetActiveCollection(Operator):
     '''Set the active collection'''
     bl_label = "Set Active Collection"
     bl_idname = "view3d.set_active_collection"
-    bl_options = {'REGISTER', 'UNDO'}
+    bl_options = {'UNDO'}
 
     collection_index: IntProperty()
     collection_name: StringProperty()
 
     def execute(self, context):
-        if self.collection_index == 0:
+        if self.collection_index == -1:
             cm = context.scene.collection_manager
             cm.cm_list_index = -1
             layer_collection = context.view_layer.layer_collection
@@ -86,6 +86,9 @@ class SetActiveCollection(Operator):
 
         context.view_layer.active_layer_collection = layer_collection
 
+        if context.view_layer.active_layer_collection != layer_collection:
+            self.report({'WARNING'}, "Can't set excluded collection as active")
+
         return {'FINISHED'}
 
 
@@ -961,6 +964,11 @@ class CMNewCollectionOperator(Operator):
 
             cm.cm_list_index = 0
 
+
+        # set new collection to active
+        layer_collection = layer_collections[new_collection.name]["ptr"]
+        context.view_layer.active_layer_collection = layer_collection
+
         global rename
         rename[0] = True
 
diff --git a/object_collection_manager/ui.py b/object_collection_manager/ui.py
index 61c44a5b..f4f0e73e 100644
--- a/object_collection_manager/ui.py
+++ b/object_collection_manager/ui.py
@@ -150,7 +150,7 @@ class CollectionManager(Operator):
 
         prop = master_collection_row.operator("view3d.set_active_collection",
                                               text='', icon='GROUP', depress=highlight)
-        prop.collection_index = 0
+        prop.collection_index = -1
         prop.collection_name = 'Master Collection'
 
         master_collection_row.separator()
@@ -471,7 +471,17 @@ class CM_UL_items(UIList):
             row.label(icon='BLANK1')
 
 
-        row.label(icon='GROUP')
+        # collection icon
+        c_icon = row.row()
+        highlight = False
+        if (context.view_layer.active_layer_collection == laycol["ptr"]):
+                highlight = True
+
+        prop = c_icon.operator("view3d.set_active_collection", text='', icon='GROUP',
+                                              emboss=highlight, depress=highlight)
+
+        prop.collection_index = laycol["row_index"]
+        prop.collection_name = item.name
 
         if context.preferences.addons[__package__].preferences.enable_qcd:
             QCD = row.row()
@@ -792,18 +802,6 @@ def update_icon(base, icon, theme_color):
     icon.icon_pixels_float = colored_icon
 
 
-def update_selection(self, context):
-    cm = context.scene.collection_manager
-
-    if cm.cm_list_index == -1:
-        return
-
-    selected_item = cm.cm_list_collection[cm.cm_list_index]
-    layer_collection = layer_collections[selected_item.name]["ptr"]
-
-    context.view_layer.active_layer_collection = layer_collection
-
-
 def filter_items_by_name_insensitive(pattern, bitflag, items, propname="name", flags=None, reverse=False):
         """
         Set FILTER_ITEM for items which name matches filter_name one (case-insensitive).



More information about the Bf-extensions-cvs mailing list