[Bf-blender-cvs] [011c8c730f] blender2.8: Outliner collection operators, all but collection link

Dalai Felinto noreply at git.blender.org
Thu Feb 16 14:40:01 CET 2017


Commit: 011c8c730fb3efc9e00855911d4df5deb3f0c0f5
Author: Dalai Felinto
Date:   Thu Feb 16 10:54:09 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB011c8c730fb3efc9e00855911d4df5deb3f0c0f5

Outliner collection operators, all but collection link

Note: It may be missing a notifier to prevent Outliner from crashing
when deleting collections.

===================================================================

M	release/scripts/startup/bl_ui/space_outliner.py
M	source/blender/editors/space_outliner/outliner_collections.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index db91c382ef..56b6ea4622 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -63,11 +63,11 @@ class OUTLINER_HT_header(Header):
         elif space.display_mode == 'COLLECTIONS':
             row = layout.row(align=True)
 
-            row.operator("outliner.collections_new", text="", icon='NEW')
-            row.operator("outliner.collections_override_new", text="", icon='LINK_AREA')
-            row.operator("outliner.collections_link", text="", icon='LINKED')
-            row.operator("outliner.collections_unlink", text="", icon='UNLINKED')
-            row.operator("outliner.collections_delete", text="", icon='X')
+            row.operator("outliner.collection_new", text="", icon='NEW')
+            row.operator("outliner.collection_override_new", text="", icon='LINK_AREA')
+            row.operator("outliner.collection_link", text="", icon='LINKED')
+            row.operator("outliner.collection_unlink", text="", icon='UNLINKED')
+            row.operator("outliner.collection_delete", text="", icon='X')
 
 
 class OUTLINER_MT_editor_menus(Menu):
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index 382276a64b..441ac81fdf 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -25,9 +25,12 @@
  */
 
 #include "BKE_context.h"
+#include "BKE_collection.h"
 #include "BKE_layer.h"
 #include "BKE_report.h"
 
+#include "BLI_listbase.h"
+
 #include "ED_screen.h"
 
 #include "WM_api.h"
@@ -39,41 +42,20 @@
 #include "outliner_intern.h" /* own include */
 
 /* -------------------------------------------------------------------- */
-/* polls */
 
-static SceneCollection *collection_manager_collection_active(bContext *C)
+static LayerCollection *outliner_collection_active(bContext *C)
 {
 	TODO_LAYER_OPERATORS;
-	/* consider that we may have overrides active
+	/* consider that we may have overrides or objects active
 	 * leading to no active collections */
-	return CTX_data_scene_collection(C);
+	return CTX_data_layer_collection(C);
 }
 
-static int operator_not_master_collection_active(bContext *C)
+static CollectionOverride *outliner_override_active(bContext *UNUSED(C))
 {
-	SceneCollection *sc = collection_manager_collection_active(C);
-	if (sc == NULL) {
-		return 1;
-	}
-
-	return  (sc == BKE_collection_master(CTX_data_scene(C))) ? 0 : 1;
-}
-
-static int operator_top_collection_active(bContext *C)
-{
-	SceneCollection *sc = collection_manager_collection_active(C);
-	if (sc == NULL) {
-		return 0;
-	}
-
 	TODO_LAYER_OPERATORS;
-	/* see if it's a top collection */
-	return 1;
-}
-
-static int operator_collection_active(bContext *C)
-{
-	return collection_manager_collection_active(C) ? 1 : 0;
+	TODO_LAYER_OVERRIDE;
+	return NULL;
 }
 
 /* -------------------------------------------------------------------- */
@@ -86,11 +68,11 @@ static int collection_link_invoke(bContext *UNUSED(C), wmOperator *op, const wmE
 	return OPERATOR_CANCELLED;
 }
 
-void OUTLINER_OT_collections_link(wmOperatorType *ot)
+void OUTLINER_OT_collection_link(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "Add Collection";
-	ot->idname = "OUTLINER_OT_collections_link";
+	ot->idname = "OUTLINER_OT_collection_link";
 	ot->description = "Link a new collection to the active layer";
 
 	/* api callbacks */
@@ -100,23 +82,48 @@ void OUTLINER_OT_collections_link(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static int collection_unlink_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
+/**
+ * Returns true if selected element is a collection directly
+ * linked to the active SceneLayer (not a nested collection)
+ */
+static int collection_unlink_poll(bContext *C)
 {
-	TODO_LAYER_OPERATORS;
-	BKE_report(op->reports, RPT_ERROR, "OUTLINER_OT_collections_unlink not implemented yet");
-	return OPERATOR_CANCELLED;
+	LayerCollection *lc = outliner_collection_active(C);
+
+	if (lc == NULL) {
+		return 0;
+	}
+
+	SceneLayer *sl = CTX_data_scene_layer(C);
+	return BLI_findindex(&sl->layer_collections, lc) != -1 ? 1 : 0;
 }
 
-void OUTLINER_OT_collections_unlink(wmOperatorType *ot)
+static int collection_unlink_exec(bContext *C, wmOperator *op)
+{
+	LayerCollection *lc = outliner_collection_active(C);
+
+	if (lc == NULL) {
+		BKE_report(op->reports, RPT_ERROR, "Active element is not a collection");
+		return OPERATOR_CANCELLED;
+	}
+
+	SceneLayer *sl = CTX_data_scene_layer(C);
+	BKE_collection_unlink(sl, lc);
+
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+	return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_unlink(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "Add Collection";
-	ot->idname = "OUTLINER_OT_collections_unlink";
-	ot->description = "Link a new collection to the active layer";
+	ot->idname = "OUTLINER_OT_collection_unlink";
+	ot->description = "Unlink collection from the active layer";
 
 	/* api callbacks */
-	ot->invoke = collection_unlink_invoke;
-	ot->poll = operator_top_collection_active;
+	ot->exec = collection_unlink_exec;
+	ot->poll = collection_unlink_poll;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -134,11 +141,11 @@ static int collection_new_exec(bContext *C, wmOperator *UNUSED(op))
 	return OPERATOR_FINISHED;
 }
 
-void OUTLINER_OT_collections_new(wmOperatorType *ot)
+void OUTLINER_OT_collection_new(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "New Collection";
-	ot->idname = "OUTLINER_OT_collections_new";
+	ot->idname = "OUTLINER_OT_collection_new";
 	ot->description = "Add a new collection to the scene, and link it to the active layer";
 
 	/* api callbacks */
@@ -148,7 +155,21 @@ void OUTLINER_OT_collections_new(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static int override_new_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
+/**
+ * Returns true is selected element is a collection
+ */
+static int collection_override_new_poll(bContext *(C))
+{
+#ifdef TODO_LAYER_OVERRIDE
+	/* disable for now, since it's not implemented */
+	(void) C;
+	return 0;
+#else
+	return outliner_collection_active(C) ? 1 : 0;
+#endif
+}
+
+static int collection_override_new_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
 {
 	TODO_LAYER_OPERATORS;
 	TODO_LAYER_OVERRIDE;
@@ -156,44 +177,77 @@ static int override_new_invoke(bContext *UNUSED(C), wmOperator *op, const wmEven
 	return OPERATOR_CANCELLED;
 }
 
-void OUTLINER_OT_collections_override_new(wmOperatorType *ot)
+/* in the middle of renames remove s */
+void OUTLINER_OT_collection_override_new(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "New Override";
-	ot->idname = "OUTLINER_OT_collections_override_new";
+	ot->idname = "OUTLINER_OT_collection_override_new";
 	ot->description = "Add a new override to the active collection";
 
 	/* api callbacks */
-	ot->invoke = override_new_invoke;
-	ot->poll = operator_collection_active;
+	ot->invoke = collection_override_new_invoke;
+	ot->poll = collection_override_new_poll;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static int delete_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event))
+/**
+ * Returns true if selected element is a collection
+ * or an override, but not a master collection
+ */
+static int collection_delete_poll(bContext *C)
 {
-	TODO_LAYER_OPERATORS;
-	BKE_report(op->reports, RPT_ERROR, "OUTLINER_OT_collections_delete not implemented yet");
-	return OPERATOR_CANCELLED;
+	LayerCollection *lc = outliner_collection_active(C);
+
+	if (lc == NULL) {
+		/* try override */
+		return outliner_override_active(C) ? 1 : 0;
+	}
+
+	return  (lc->scene_collection == BKE_collection_master(CTX_data_scene(C))) ? 0 : 1;
 }
 
-void OUTLINER_OT_collections_delete(wmOperatorType *ot)
+static int collection_delete_exec(bContext *C, wmOperator *op)
+{
+	Scene *scene = CTX_data_scene(C);
+	LayerCollection *lc = outliner_collection_active(C);
+
+	TODO_LAYER_OVERRIDE; /* handle operators */
+
+	if (lc == NULL) {
+		BKE_report(op->reports, RPT_ERROR, "Active element is not a collection");
+		return OPERATOR_CANCELLED;
+	}
+
+	if (lc->scene_collection == BKE_collection_master(scene)) {
+		BKE_report(op->reports, RPT_ERROR, "You cannot delete the master collection, try unliking it instead");
+		return OPERATOR_CANCELLED;
+	}
+
+	BKE_collection_remove(scene, lc->scene_collection);
+
+	WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+	return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_delete(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "Delete";
-	ot->idname = "OUTLINER_OT_collections_delete";
-	ot->description = "Delete active  override or collection";
+	ot->idname = "OUTLINER_OT_collection_delete";
+	ot->description = "Delete active override or collection";
 
 	/* api callbacks */
-	ot->invoke = delete_invoke;
-	ot->poll = operator_not_master_collection_active;
+	ot->exec = collection_delete_exec;
+	ot->poll = collection_delete_poll;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-static int select_exec(bContext *C, wmOperator *op)
+static int collection_select_exec(bContext *C, wmOperator *op)
 {
 	SceneLayer *sl = CTX_data_scene_layer(C);
 	const int collection_index = RNA_int_get(op->ptr, "collection_index");
@@ -202,15 +256,15 @@ static int select_exec(bContext *C, wmOperator *op)
 	return OPERATOR_FINISHED;
 }
 
-void OUTLINER_OT_collections_select(wmOperatorType *ot)
+void OUTLINER_OT_collection_select(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "Select";
-	ot->idname = "OUTLINER_OT_collections_select";
+	ot->idname = "OUTLINER_OT_collection_select";
 	ot->description = "Change active collection or override";
 
 	/* api callbacks */
-	ot->exec = select_exec;
+	ot->exec = collection_select_exec;
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -219,28 +273,6 @@ void OUTLINER_OT_collections_select(wmOperatorType *ot)
 	            "Index of collection t

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list