Outliner: Context menu for scenes
authorPhilipp Oeser <info@graphics-engineer.com>
Fri, 14 Aug 2015 13:15:25 +0000 (15:15 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Fri, 14 Aug 2015 13:22:52 +0000 (15:22 +0200)
Adds context menu for scenes in the outliner, for now, with only a 'Delete' entry.

D1448 by @lichtwerk, review by @aligorith and @Severin

source/blender/editors/space_outliner/outliner_intern.h
source/blender/editors/space_outliner/outliner_ops.c
source/blender/editors/space_outliner/outliner_tools.c

index 54c0e4b35b4ad9c3c7858bfc4e4f5dd71ff4d806..7d151282bd2eefb8d369be1c90117113e3ed689d 100644 (file)
@@ -249,6 +249,7 @@ void OUTLINER_OT_group_link(struct wmOperatorType *ot);
 /* outliner_tools.c ---------------------------------------------- */
 
 void OUTLINER_OT_operation(struct wmOperatorType *ot);
+void OUTLINER_OT_scene_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_object_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_group_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_id_operation(struct wmOperatorType *ot);
index f5869575cc6d7495bdd9f5d38c556d902e1af13f..839d44df25d73da0603a65f8b4cb67fb4f60ad3f 100644 (file)
@@ -48,6 +48,7 @@ void outliner_operatortypes(void)
        WM_operatortype_append(OUTLINER_OT_item_openclose);
        WM_operatortype_append(OUTLINER_OT_item_rename);
        WM_operatortype_append(OUTLINER_OT_operation);
+       WM_operatortype_append(OUTLINER_OT_scene_operation);
        WM_operatortype_append(OUTLINER_OT_object_operation);
        WM_operatortype_append(OUTLINER_OT_group_operation);
        WM_operatortype_append(OUTLINER_OT_id_operation);
index 3fc47444abeb0b06f090f98dbea7f0af85fd5c87..27100aac8cfcf2bc37aabf6534ec745dd4381ff2 100644 (file)
@@ -263,7 +263,77 @@ static void outliner_do_libdata_operation(bContext *C, Scene *scene, SpaceOops *
        }
 }
 
-/* */
+/* ******************************************** */
+typedef enum eOutliner_PropSceneOps {
+       OL_SCENE_OP_DELETE = 1
+} eOutliner_PropSceneOps;
+
+static EnumPropertyItem prop_scene_op_types[] = {
+       {OL_SCENE_OP_DELETE, "DELETE", ICON_X, "Delete", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static void outliner_do_scene_operation(
+        bContext *C, eOutliner_PropSceneOps event, ListBase *lb,
+        void (*operation_cb)(bContext *, eOutliner_PropSceneOps, TreeElement *, TreeStoreElem *))
+{
+       TreeElement *te;
+       TreeStoreElem *tselem;
+
+       for (te = lb->first; te; te = te->next) {
+               tselem = TREESTORE(te);
+               if (tselem->flag & TSE_SELECTED) {
+                       operation_cb(C, event, te, tselem);
+               }
+       }
+}
+
+static void scene_cb(bContext *C, eOutliner_PropSceneOps event, TreeElement *UNUSED(te), TreeStoreElem *tselem)
+{
+       Scene *scene = (Scene *)tselem->id;
+
+       if (event == OL_SCENE_OP_DELETE) {
+               ED_screen_delete_scene(C, scene);
+               WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
+       }
+}
+
+static int outliner_scene_operation_exec(bContext *C, wmOperator *op)
+{
+       SpaceOops *soops = CTX_wm_space_outliner(C);
+       const eOutliner_PropSceneOps event = RNA_enum_get(op->ptr, "type");
+
+       outliner_do_scene_operation(C, event, &soops->tree, scene_cb);
+
+       if (event == OL_SCENE_OP_DELETE) {
+               outliner_cleanup_tree(soops);
+               ED_undo_push(C, "Delete Scene(s)");
+       }
+       else {
+               BLI_assert(0);
+               return OPERATOR_CANCELLED;
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_scene_operation(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Outliner Scene Operation";
+       ot->idname = "OUTLINER_OT_scene_operation";
+       ot->description = "Context menu for scene operations";
+
+       /* callbacks */
+       ot->invoke = WM_menu_invoke;
+       ot->exec = outliner_scene_operation_exec;
+       ot->poll = ED_operator_outliner_active;
+
+       ot->flag = 0;
+
+       ot->prop = RNA_def_enum(ot->srna, "type", prop_scene_op_types, 0, "Scene Operation", "");
+}
+/* ******************************************** */
 
 static void object_select_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
                              TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
@@ -1593,8 +1663,12 @@ static int do_outliner_operation_event(bContext *C, Scene *scene, ARegion *ar, S
                set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
                
                if (scenelevel) {
-                       //if (objectlevel || datalevel || idlevel) error("Mixed selection");
-                       //else pupmenu("Scene Operations%t|Delete");
+                       if (objectlevel || datalevel || idlevel) {
+                               BKE_report(reports, RPT_WARNING, "Mixed selection");
+                       }
+                       else {
+                               WM_operator_name_call(C, "OUTLINER_OT_scene_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+                       }
                }
                else if (objectlevel) {
                        WM_operator_name_call(C, "OUTLINER_OT_object_operation", WM_OP_INVOKE_REGION_WIN, NULL);