Commit: d94137ee7ddecc67af7f0788245435822a507abf
Author: Philipp Oeser
Date:   Fri Aug 14 15:15:25 2015 +0200
Branches: master
https://developer.blender.org/rBd94137ee7ddecc67af7f0788245435822a507abf

Outliner: Context menu for scenes

Adds context menu for scenes in the outliner, for now, with only a 'Delete' 
entry.

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

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

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

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

diff --git a/source/blender/editors/space_outliner/outliner_intern.h 
b/source/blender/editors/space_outliner/outliner_intern.h
index 54c0e4b..7d15128 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -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);
diff --git a/source/blender/editors/space_outliner/outliner_ops.c 
b/source/blender/editors/space_outliner/outliner_ops.c
index f586957..839d44d 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -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);
diff --git a/source/blender/editors/space_outliner/outliner_tools.c 
b/source/blender/editors/space_outliner/outliner_tools.c
index 3fc4744..27100aa 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -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);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to