diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2015-08-14 16:15:25 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2015-08-14 16:22:52 +0300 |
commit | d94137ee7ddecc67af7f0788245435822a507abf (patch) | |
tree | 3542c0e992513340ddce4a0f5508fef2afe4b339 /source/blender/editors/space_outliner/outliner_tools.c | |
parent | 8b286bf35a379bca8412cc1d82e8eb85b0bc6316 (diff) |
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
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_tools.c')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_tools.c | 80 |
1 files changed, 77 insertions, 3 deletions
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 3fc47444abe..27100aac8cf 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); |