From 011c8c730fb3efc9e00855911d4df5deb3f0c0f5 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Thu, 16 Feb 2017 10:54:09 +0100 Subject: Outliner collection operators, all but collection link Note: It may be missing a notifier to prevent Outliner from crashing when deleting collections. --- .../editors/space_outliner/outliner_collections.c | 215 ++++++++++++--------- 1 file changed, 123 insertions(+), 92 deletions(-) (limited to 'source/blender/editors/space_outliner/outliner_collections.c') diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index 382276a64b2..441ac81fdfa 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 to select", 0, INT_MAX); } -static int rename_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event)) -{ - TODO_LAYER_OPERATORS; - BKE_report(op->reports, RPT_ERROR, "COLLECTIONS_rename not implemented yet"); - return OPERATOR_CANCELLED; -} - -void OUTLINER_OT_collections_rename(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Rename"; - ot->idname = "OUTLINER_OT_collections_rename"; - ot->description = "Rename active collection or override"; - - /* api callbacks */ - ot->invoke = rename_invoke; - ot->poll = operator_not_master_collection_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - /* -------------------------------------------------------------------- */ static int stubs_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUSED(event)) @@ -250,11 +282,11 @@ static int stubs_invoke(bContext *UNUSED(C), wmOperator *op, const wmEvent *UNUS return OPERATOR_CANCELLED; } -void OUTLINER_OT_collections_objects_add(wmOperatorType *ot) +void OUTLINER_OT_collection_objects_add(wmOperatorType *ot) { /* identifiers */ ot->name = "Add Objects"; - ot->idname = "OUTLINER_OT_collections_objects_add"; + ot->idname = "OUTLINER_OT_collection_objects_add"; ot->description = "Add selected objects to collection"; /* api callbacks */ @@ -264,12 +296,12 @@ void OUTLINER_OT_collections_objects_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -void OUTLINER_OT_collections_objects_remove(wmOperatorType *ot) +void OUTLINER_OT_collection_objects_remove(wmOperatorType *ot) { /* identifiers */ ot->name = "Remove Object"; - ot->idname = "OUTLINER_OT_collections_objects_remove"; - ot->description = "Remove object from collection"; + ot->idname = "OUTLINER_OT_collection_objects_remove"; + ot->description = "Remove objects from collection"; /* api callbacks */ ot->invoke = stubs_invoke; @@ -278,12 +310,12 @@ void OUTLINER_OT_collections_objects_remove(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -void OUTLINER_OT_collections_objects_select(wmOperatorType *ot) +void OUTLINER_OT_collection_objects_select(wmOperatorType *ot) { /* identifiers */ ot->name = "Select Objects"; - ot->idname = "OUTLINER_OT_collections_objects_select"; - ot->description = "Selected collection objects"; + ot->idname = "OUTLINER_OT_collection_objects_select"; + ot->description = "Select collection objects"; /* api callbacks */ ot->invoke = stubs_invoke; @@ -292,12 +324,12 @@ void OUTLINER_OT_collections_objects_select(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -void OUTLINER_OT_collections_objects_deselect(wmOperatorType *ot) +void OUTLINER_OT_collection_objects_deselect(wmOperatorType *ot) { /* identifiers */ ot->name = "Deselect Objects"; - ot->idname = "OUTLINER_OT_collections_objects_deselect"; - ot->description = "Deselected collection objects"; + ot->idname = "OUTLINER_OT_collection_objects_deselect"; + ot->description = "Deselect collection objects"; /* api callbacks */ ot->invoke = stubs_invoke; @@ -305,4 +337,3 @@ void OUTLINER_OT_collections_objects_deselect(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - -- cgit v1.2.3