...
 
Commits (5)
......@@ -23,7 +23,7 @@ bl_info = {
"name": "Collection Manager",
"description": "Manage collections and their objects",
"author": "Ryan Inch",
"version": (1,3,0),
"version": (1,5,1),
"blender": (2, 80, 0),
"location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel
......
......@@ -13,13 +13,22 @@ row_index = 0
def get_max_lvl():
return max_lvl
def clone_list(l1, l2):
l1.clear()
for x in l2:
l1.append(x)
def update_col_name(self, context):
if self.name != self.last_name:
if self.name == '':
self.name = self.last_name
return
if self.last_name != '':
layer_collections[self.last_name]["ptr"].collection.name = self.name
update_property_group(context)
self.last_name = self.name
class CMListCollection(PropertyGroup):
name: StringProperty()
name: StringProperty(update=update_col_name)
last_name: StringProperty()
def update_collection_tree(context):
......
This diff is collapsed.
......@@ -7,11 +7,7 @@ from bpy.types import (
from .internals import *
from .operators import (
excludeall_history,
restrictselectall_history,
hideall_history,
disableviewall_history,
disablerenderall_history,
rto_history,
rename,
phantom_history,
)
......@@ -21,15 +17,16 @@ class CollectionManager(Operator):
bl_label = "Collection Manager"
bl_idname = "view3d.collection_manager"
view_layer = ""
last_view_layer = ""
def draw(self, context):
layout = self.layout
scn = context.scene
view_layer = context.view_layer.name
if context.view_layer.name != self.view_layer:
if view_layer != self.last_view_layer:
update_collection_tree(context)
self.view_layer = context.view_layer.name
self.last_view_layer = view_layer
title_row = layout.split(factor=0.5)
main = title_row.row()
......@@ -80,23 +77,33 @@ class CollectionManager(Operator):
sec2.alignment = 'RIGHT'
if scn.show_exclude:
depress = True if len(excludeall_history) else False
exclude_all_history = rto_history["exclude_all"].get(view_layer, [])
depress = True if len(exclude_all_history) else False
sec2.operator("view3d.un_exclude_all_collections", text="", icon='CHECKBOX_HLT', depress=depress)
if scn.show_selectable:
depress = True if len(restrictselectall_history) else False
select_all_history = rto_history["select_all"].get(view_layer, [])
depress = True if len(select_all_history) else False
sec2.operator("view3d.un_restrict_select_all_collections", text="", icon='RESTRICT_SELECT_OFF', depress=depress)
if scn.show_hideviewport:
depress = True if len(hideall_history) else False
hide_all_history = rto_history["hide_all"].get(view_layer, [])
depress = True if len(hide_all_history) else False
sec2.operator("view3d.un_hide_all_collections", text="", icon='HIDE_OFF', depress=depress)
if scn.show_disableviewport:
depress = True if len(disableviewall_history) else False
disable_all_history = rto_history["disable_all"].get(view_layer, [])
depress = True if len(disable_all_history) else False
sec2.operator("view3d.un_disable_viewport_all_collections", text="", icon='RESTRICT_VIEW_OFF', depress=depress)
if scn.show_render:
depress = True if len(disablerenderall_history) else False
render_all_history = rto_history["render_all"].get(view_layer, [])
depress = True if len(render_all_history) else False
sec2.operator("view3d.un_disable_render_all_collections", text="", icon='RESTRICT_RENDER_OFF', depress=depress)
layout.row().template_list("CM_UL_items", "", context.scene, "CMListCollection", context.scene, "CMListIndex", rows=15, sort_lock=True)
......@@ -161,6 +168,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 = ""
......@@ -206,7 +249,7 @@ class CM_UL_items(UIList):
#name_row.activate_init = True
#rename[0] = False
name_row.prop(collection, "name", text="", expand=True)
name_row.prop(item, "name", text="", expand=True)
# used as a separator (actual separator not wide enough)
row.label()
......@@ -267,7 +310,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)
......