[Bf-extensions-cvs] [de11dda9] master: Collection Manager: Add Filter By Selected. Task: T69577

Ryan Inch noreply at git.blender.org
Sun Dec 8 04:09:06 CET 2019


Commit: de11dda9208fee5361a84fb8c8a5785c88d02e71
Author: Ryan Inch
Date:   Sat Dec 7 22:07:44 2019 -0500
Branches: master
https://developer.blender.org/rBACde11dda9208fee5361a84fb8c8a5785c88d02e71

Collection Manager: Add Filter By Selected. Task: T69577

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

M	collection_manager/__init__.py
M	collection_manager/ui.py

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

diff --git a/collection_manager/__init__.py b/collection_manager/__init__.py
index af4c7f0d..11ae0c1b 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,6,0),
+    "version": (1,7,0),
     "blender": (2, 80, 0),
     "location": "View3D - Object Mode (Shortcut - M)",
     "warning": '',  # used for warning icon and text in addons panel
diff --git a/collection_manager/ui.py b/collection_manager/ui.py
index a2e159da..27d922cd 100644
--- a/collection_manager/ui.py
+++ b/collection_manager/ui.py
@@ -5,6 +5,8 @@ from bpy.types import (
     UI_UL_list,
     )
 
+from bpy.props import BoolProperty
+
 from .internals import *
 from .operators import (
     rto_history,
@@ -207,6 +209,12 @@ def filter_items_by_name_insensitive(pattern, bitflag, items, propname="name", f
 class CM_UL_items(UIList):
     last_filter_value = ""
     
+    filter_by_selected: BoolProperty(
+                        name="Filter By Selected",
+                        default=False,
+                        description="Filter collections by selected items"
+                        )
+    
     def draw_item(self, context, layout, data, item, icon, active_data,active_propname, index):
         self.use_filter_show = True
         
@@ -303,6 +311,18 @@ class CM_UL_items(UIList):
             rm_op.enabled = False
     
     
+    def draw_filter(self, context, layout):
+        row = layout.row()
+
+        subrow = row.row(align=True)
+        subrow.prop(self, "filter_name", text="")
+        
+        icon = 'ZOOM_OUT' if self.use_filter_invert else 'ZOOM_IN'
+        subrow.prop(self, "use_filter_invert", text="", icon=icon)
+        
+        subrow = row.row(align=True)
+        subrow.prop(self, "filter_by_selected", text="", icon='SNAP_VOLUME')
+    
     def filter_items(self, context, data, propname):
         flt_flags = []
         flt_neworder = []
@@ -312,7 +332,17 @@ class CM_UL_items(UIList):
         if self.filter_name:
             flt_flags = filter_items_by_name_insensitive(self.filter_name, self.bitflag_filter_item, list_items)
         
-        else:
+        elif self.filter_by_selected:
+            flt_flags = [0] * len(list_items)
+            
+            for idx, item in enumerate(list_items):
+                collection = layer_collections[item.name]["ptr"].collection
+                
+                # check if any of the selected objects are in the collection
+                if not set(context.selected_objects).isdisjoint(collection.objects):
+                    flt_flags[idx] |= self.bitflag_filter_item
+                    
+        else: # display as treeview
             flt_flags = [self.bitflag_filter_item] * len(list_items)
         
             for idx, item in enumerate(list_items):



More information about the Bf-extensions-cvs mailing list