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:
Diffstat (limited to 'object_collection_manager/operators.py')
-rw-r--r--object_collection_manager/operators.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/object_collection_manager/operators.py b/object_collection_manager/operators.py
index e2412419..a12b8339 100644
--- a/object_collection_manager/operators.py
+++ b/object_collection_manager/operators.py
@@ -69,6 +69,8 @@ from .operator_utils import (
set_exclude_state,
)
+from . import ui
+
class SetActiveCollection(Operator):
'''Set the active collection'''
bl_label = "Set Active Collection"
@@ -1227,9 +1229,23 @@ class CMNewCollectionOperator(Operator):
def execute(self, context):
global rto_history
- new_collection = bpy.data.collections.new('Collection')
+ new_collection = bpy.data.collections.new("New Collection")
cm = context.scene.collection_manager
+ # prevent adding collections when collections are filtered
+ # and the selection is ambiguous
+ if cm.cm_list_index == -1 and ui.CM_UL_items.filtering:
+ send_report("Cannot create new collection.\n"
+ "No collection is selected and collections are filtered."
+ )
+ return {'CANCELLED'}
+
+ if cm.cm_list_index > -1 and not ui.CM_UL_items.visible_items[cm.cm_list_index]:
+ send_report("Cannot create new collection.\n"
+ "The selected collection isn't visible."
+ )
+ return {'CANCELLED'}
+
# if there are collections
if len(cm.cm_list_collection) > 0:
@@ -1277,6 +1293,9 @@ class CMNewCollectionOperator(Operator):
layer_collection = layer_collections[new_collection.name]["ptr"]
context.view_layer.active_layer_collection = layer_collection
+ # show the new collection when collections are filtered.
+ ui.CM_UL_items.new_collections.append(new_collection.name)
+
global rename
rename[0] = True