Collection Manager: Fix selection issues. Task: T69577

Make treeview selection more stable and predictable.
Fix not being able to select the row from the left side with
a top level expander -- adjusts window sizing to account for this.
This commit is contained in:
Ryan Inch 2020-04-25 04:19:33 -04:00
parent 67ef6e567b
commit 0618a7636e
3 changed files with 27 additions and 19 deletions

View File

@ -22,7 +22,7 @@ bl_info = {
"name": "Collection Manager",
"description": "Manage collections and their objects",
"author": "Ryan Inch",
"version": (2, 7, 14),
"version": (2, 7, 15),
"blender": (2, 80, 0),
"location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel

View File

@ -76,14 +76,16 @@ class SetActiveCollection(Operator):
def execute(self, context):
if self.collection_index == -1:
cm = context.scene.collection_manager
cm.cm_list_index = -1
layer_collection = context.view_layer.layer_collection
else:
laycol = layer_collections[self.collection_name]
layer_collection = laycol["ptr"]
# set selection to this row
cm = context.scene.collection_manager
cm.cm_list_index = laycol["row_index"]
context.view_layer.active_layer_collection = layer_collection
if context.view_layer.active_layer_collection != layer_collection:
@ -119,7 +121,6 @@ class ExpandAllOperator(Operator):
class ExpandSublevelOperator(Operator):
''''''
bl_label = "Expand Sublevel Items"
bl_description = (
" * Ctrl+LMB - Expand/Collapse all sublevels\n"
@ -204,8 +205,7 @@ class ExpandSublevelOperator(Operator):
expand_history["history"].clear()
# set selected row to the collection you're expanding/collapsing and update tree view
context.scene.collection_manager.cm_list_index = self.index
#update tree view
update_property_group(context)
return {'FINISHED'}
@ -862,6 +862,7 @@ class CMRemoveCollectionOperator(Operator):
laycol = layer_collections[self.collection_name]
collection = laycol["ptr"].collection
parent_collection = laycol["parent"]["ptr"].collection
selected_row_name = cm.cm_list_collection[cm.cm_list_index].name
# shift all objects in this collection to the parent collection
@ -889,9 +890,21 @@ class CMRemoveCollectionOperator(Operator):
update_property_group(context)
if len(cm.cm_list_collection) == cm.cm_list_index:
cm.cm_list_index = len(cm.cm_list_collection) - 1
update_property_group(context)
# update selected row
laycol = layer_collections.get(selected_row_name, None)
if laycol:
cm.cm_list_index = laycol["row_index"]
elif len(cm.cm_list_collection) == cm.cm_list_index:
cm.cm_list_index -= 1
if cm.cm_list_index > -1:
name = cm.cm_list_collection[cm.cm_list_index].name
laycol = layer_collections[name]
while not laycol["visible"]:
laycol = laycol["parent"]
cm.cm_list_index = laycol["row_index"]
# update qcd

View File

@ -322,15 +322,6 @@ class CollectionManager(Operator):
self.view_layer = view_layer.name
# sync selection in ui list with active layer collection
try:
active_laycol_name = view_layer.active_layer_collection.name
active_laycol_row_index = layer_collections[active_laycol_name]["row_index"]
cm.cm_list_index = active_laycol_row_index
except KeyError: # Master Collection is special and not part of regular collections
cm.cm_list_index = -1
# check if expanded & history/buffer state still correct
if collection_state:
new_state = generate_state()
@ -387,11 +378,12 @@ class CollectionManager(Operator):
# handle window sizing
max_width = 960
min_width = 456
row_indent_width = 15
width_step = 21
scrollbar_width = 21
lvl = get_max_lvl()
width = min_width + (width_step * lvl)
width = min_width + row_indent_width + (width_step * lvl)
if len(layer_collections) > 14:
width += scrollbar_width
@ -440,6 +432,9 @@ class CM_UL_items(UIList):
row = split.row(align=True)
row.alignment = 'LEFT'
# allow room to select the row from the beginning
row.separator()
# indent child items
if laycol["lvl"] > 0:
for _ in range(laycol["lvl"]):