[Bf-extensions-cvs] [f3beaf24] master: Collection Manager: Made filtering case-insensitive. Task: T69577

Ryan Inch noreply at git.blender.org
Sat Nov 16 08:13:25 CET 2019


Commit: f3beaf241996d17feec0dee5f0888b0e9f55b4e3
Author: Ryan Inch
Date:   Sat Nov 16 02:11:23 2019 -0500
Branches: master
https://developer.blender.org/rBACf3beaf241996d17feec0dee5f0888b0e9f55b4e3

Collection Manager: Made filtering case-insensitive. 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 0daca32c..faf849b8 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,3,1),
+    "version": (1,3,2),
     "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 6033bdc5..1d390b36 100644
--- a/collection_manager/ui.py
+++ b/collection_manager/ui.py
@@ -161,6 +161,42 @@ def update_selection(self, context):
     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).
+        pattern is the filtering pattern.
+        propname is the name of the string property to use for filtering.
+        flags must be a list of integers the same length as items, or None!
+        return a list of flags (based on given flags if not None),
+        or an empty list if no flags were given and no filtering has been done.
+        """
+        import fnmatch
+
+        if not pattern or not items:  # Empty pattern or list = no filtering!
+            return flags or []
+
+        if flags is None:
+            flags = [0] * len(items)
+        
+        # Make pattern case-insensitive
+        pattern = pattern.lower()
+
+        # Implicitly add heading/trailing wildcards.
+        pattern = "*" + pattern + "*"
+
+        for i, item in enumerate(items):
+            name = getattr(item, propname, None)
+            
+            # Make name case-insensitive
+            name = name.lower()
+            
+            # This is similar to a logical xor
+            if bool(name and fnmatch.fnmatch(name, pattern)) is not bool(reverse):
+                flags[i] |= bitflag
+            
+        return flags
+
+
 class CM_UL_items(UIList):
     last_filter_value = ""
     
@@ -267,7 +303,7 @@ class CM_UL_items(UIList):
         list_items = getattr(data, propname)
         
         if self.filter_name:
-            flt_flags = UI_UL_list.filter_items_by_name(self.filter_name, self.bitflag_filter_item, list_items)
+            flt_flags = filter_items_by_name_insensitive(self.filter_name, self.bitflag_filter_item, list_items)
         
         else:
             flt_flags = [self.bitflag_filter_item] * len(list_items)



More information about the Bf-extensions-cvs mailing list