UI: "Delete Other Workspaces" operator

Adds a context menu entry to delete all workspaces but the one the menu
was spawned from.

Co-authored-by: Nig3l <nig3lpro@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/138530
This commit is contained in:
Maxime-Cots
2025-08-07 16:07:05 +02:00
committed by Julian Eisel
parent a43359eb88
commit 7f8d01f809
2 changed files with 38 additions and 2 deletions

View File

@@ -632,8 +632,10 @@ class TOPBAR_MT_workspace_menu(Menu):
layout = self.layout
layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
if len(bpy.data.workspaces) > 1:
layout.operator("workspace.delete", text="Delete", icon='REMOVE')
if len(bpy.data.workspaces) <= 1:
return
layout.operator("workspace.delete", text="Delete", icon='REMOVE')
layout.separator()
@@ -648,6 +650,10 @@ class TOPBAR_MT_workspace_menu(Menu):
props = layout.operator("screen.workspace_cycle", text="Next Workspace")
props.direction = 'NEXT'
layout.separator()
layout.operator("workspace.delete_all_others")
# Grease Pencil Object - Primitive curve
class TOPBAR_PT_gpencil_primitive(Panel):

View File

@@ -9,6 +9,8 @@
#include <cstdlib>
#include <cstring>
#include <fmt/format.h>
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
@@ -341,6 +343,33 @@ static void WORKSPACE_OT_delete(wmOperatorType *ot)
ot->exec = workspace_delete_exec;
}
static wmOperatorStatus workspace_delete_all_others_exec(bContext *C, wmOperator * /*op*/)
{
Main *bmain = CTX_data_main(C);
WorkSpace *workspace = workspace_context_get(C);
LISTBASE_FOREACH (WorkSpace *, ws, &bmain->workspaces) {
if (ws != workspace) {
WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_DELETE, ws);
WM_event_add_notifier(C, NC_WINDOW, nullptr);
}
}
return OPERATOR_FINISHED;
}
static void WORKSPACE_OT_delete_all_others(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Delete Other Workspaces";
ot->description = "Delete all workspaces except this one";
ot->idname = "WORKSPACE_OT_delete_all_others";
/* api callbacks */
ot->poll = workspace_context_poll;
ot->exec = workspace_delete_all_others_exec;
}
static wmOperatorStatus workspace_append_activate_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
@@ -643,6 +672,7 @@ void ED_operatortypes_workspace()
{
WM_operatortype_append(WORKSPACE_OT_duplicate);
WM_operatortype_append(WORKSPACE_OT_delete);
WM_operatortype_append(WORKSPACE_OT_delete_all_others);
WM_operatortype_append(WORKSPACE_OT_add);
WM_operatortype_append(WORKSPACE_OT_append_activate);
WM_operatortype_append(WORKSPACE_OT_reorder_to_back);