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
This commit is contained in:
parent
8b286bf35a
commit
d94137ee7d
Notes:
blender-bot
2023-02-14 08:59:10 +01:00
Referenced by issue #45661, Delete scene from Outliner
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue