Skip to content

Commit 90de1f0

Browse files
committed
Add a command to persist workbench state
Fixes #3398
1 parent cbf687d commit 90de1f0

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025, Red Hat, Inc. and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
package org.eclipse.ui.internal;
12+
13+
import org.eclipse.core.commands.AbstractHandler;
14+
import org.eclipse.core.commands.ExecutionEvent;
15+
import org.eclipse.core.runtime.IStatus;
16+
import org.eclipse.ui.PlatformUI;
17+
18+
public class PersistWorkbenchHandler extends AbstractHandler {
19+
20+
@Override
21+
public Object execute(ExecutionEvent event) {
22+
if (PlatformUI.getWorkbench() instanceof Workbench workbench) {
23+
workbench.persist(false);
24+
return IStatus.OK;
25+
}
26+
return IStatus.ERROR;
27+
}
28+
29+
}

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/Workbench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ public void run() {
12161216
* Will also skip saving the model to the disk since that is
12171217
* done later in shutdown.
12181218
*/
1219-
private void persist(final boolean shutdown) {
1219+
void persist(final boolean shutdown) {
12201220
// persist editors that can be and possibly close the others
12211221
SafeRunner.run(new SafeRunnable() {
12221222
@Override

bundles/org.eclipse.ui.workbench/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
</with>
2727
</enabledWhen>
2828
</handler>
29+
<handler
30+
class="org.eclipse.ui.internal.PersistWorkbenchHandler"
31+
commandId="org.eclipse.ui.persistWorkbenchState">
32+
</handler>
2933
</extension>
3034
</plugin>

bundles/org.eclipse.ui/plugin.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ command.up.description = Navigate up one level
293293
command.up.name = Up
294294
command.toggleCoolbar.name = Toggle Main Toolbar Visibility
295295
command.toggleCoolbar.description = Toggles the visibility of the window toolbar
296+
command.persistWorkbenchState.name = Persist workbench state
297+
command.persistWorkbenchState.description = Forces persistence of the current workbench state for potential future recovery
296298

297299
context.editingText.description = Editing Text Context
298300
context.editingText.name = Editing Text

bundles/org.eclipse.ui/plugin.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,12 @@
14371437
id="org.eclipse.ui.toggleShowKeys"
14381438
name="%command.showKeysToggle.name">
14391439
</command>
1440+
<command
1441+
categoryId="org.eclipse.ui.category.window"
1442+
description="%command.persistWorkbenchState.description"
1443+
id="org.eclipse.ui.persistWorkbenchState"
1444+
name="%command.persistWorkbenchState.name">
1445+
</command>
14401446
</extension>
14411447

14421448
<extension

0 commit comments

Comments
 (0)