Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Inch <mythologylover75@gmail.com>2020-10-20 08:56:26 +0300
committerRyan Inch <mythologylover75@gmail.com>2020-10-20 08:56:26 +0300
commit52fb8e51ac81d21c62d85b63500a7b7ea3213193 (patch)
tree4612eed59c165d20c194d74d976bf4a715abfe1d /object_collection_manager/ui.py
parent860d8d710421c432c4701b2a4d393c6172e329f5 (diff)
Collection Manager: Improve filtering 1. Task: T69577
Improve filtering for new collections. Prevents adding new collections when the selected collection isn't visible and includes the new collection in the current filter until the filtering changes.
Diffstat (limited to 'object_collection_manager/ui.py')
-rw-r--r--object_collection_manager/ui.py54
1 files changed, 50 insertions, 4 deletions
diff --git a/object_collection_manager/ui.py b/object_collection_manager/ui.py
index 8d7acc30..4e1cd2d8 100644
--- a/object_collection_manager/ui.py
+++ b/object_collection_manager/ui.py
@@ -483,20 +483,42 @@ class CollectionManager(Operator):
class CM_UL_items(UIList):
+ filtering = False
last_filter_value = ""
selected_objects = set()
active_object = None
+ visible_items = []
+ new_collections = []
+
+ filter_name: StringProperty(
+ name="Filter By Name",
+ default="",
+ description="Filter collections by name",
+ update=lambda self, context:
+ CM_UL_items.new_collections.clear(),
+ )
+
+ use_filter_invert: BoolProperty(
+ name="Invert",
+ default=False,
+ description="Invert filtering (show hidden items, and vice-versa)",
+ )
+
filter_by_selected: BoolProperty(
name="Filter By Selected",
default=False,
- description="Filter collections by selected items"
+ description="Filter collections by selected items",
+ update=lambda self, context:
+ CM_UL_items.new_collections.clear(),
)
filter_by_qcd: BoolProperty(
name="Filter By QCD",
default=False,
- description="Filter collections to only show QCD slots"
+ description="Filter collections to only show QCD slots",
+ update=lambda self, context:
+ CM_UL_items.new_collections.clear(),
)
def draw_item(self, context, layout, data, item, icon, active_data,active_propname, index):
@@ -750,13 +772,14 @@ class CM_UL_items(UIList):
subrow.prop(self, "filter_by_qcd", text="", icon='EVENT_Q')
def filter_items(self, context, data, propname):
+ CM_UL_items.filtering = True
flt_flags = []
flt_neworder = []
list_items = getattr(data, propname)
if self.filter_name:
- flt_flags = filter_items_by_name_insensitive(self.filter_name, self.bitflag_filter_item, list_items)
+ flt_flags = filter_items_by_name_custom(self.filter_name, self.bitflag_filter_item, list_items)
elif self.filter_by_selected:
flt_flags = [0] * len(list_items)
@@ -768,6 +791,10 @@ class CM_UL_items(UIList):
if not set(context.selected_objects).isdisjoint(collection.objects):
flt_flags[idx] |= self.bitflag_filter_item
+ # add in any recently created collections
+ if item.name in CM_UL_items.new_collections:
+ flt_flags[idx] |= self.bitflag_filter_item
+
elif self.filter_by_qcd:
flt_flags = [0] * len(list_items)
@@ -775,13 +802,28 @@ class CM_UL_items(UIList):
if item.qcd_slot_idx:
flt_flags[idx] |= self.bitflag_filter_item
+ # add in any recently created collections
+ if item.name in CM_UL_items.new_collections:
+ flt_flags[idx] |= self.bitflag_filter_item
+
else: # display as treeview
+ CM_UL_items.filtering = False
+ CM_UL_items.new_collections.clear()
+
flt_flags = [self.bitflag_filter_item] * len(list_items)
for idx, item in enumerate(list_items):
if not layer_collections[item.name]["visible"]:
flt_flags[idx] = 0
+ if self.use_filter_invert:
+ for idx, flag in enumerate(flt_flags):
+ flt_flags[idx] = 0 if flag else self.bitflag_filter_item
+
+ # update visible items list
+ CM_UL_items.visible_items.clear()
+ CM_UL_items.visible_items.extend(flt_flags)
+
return flt_flags, flt_neworder
@@ -1027,7 +1069,7 @@ def update_icon(base, icon, theme_color):
icon.icon_pixels_float = colored_icon
-def filter_items_by_name_insensitive(pattern, bitflag, items, propname="name", flags=None, reverse=False):
+def filter_items_by_name_custom(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.
@@ -1060,4 +1102,8 @@ def filter_items_by_name_insensitive(pattern, bitflag, items, propname="name", f
if bool(name and fnmatch.fnmatch(name, pattern)) is not bool(reverse):
flags[i] |= bitflag
+ # add in any recently created collections
+ if item.name in CM_UL_items.new_collections:
+ flags[i] |= bitflag
+
return flags