blob: 57b7c55a97abbf3a8c874fbc56035251705cce00 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*******************************************************************************
* Copyright (c) 2005, 2015 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.operations;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchMessages;
/**
* <p>
* UndoActionHandler provides common behavior for performing an undo, as well as
* labelling and enabling the undo menu item. This class may be instantiated by
* clients.
* </p>
*
* @since 3.1
*/
public final class UndoActionHandler extends OperationHistoryActionHandler {
/**
* Construct an action handler that handles the labelling and enabling of the
* undo action for the specified undo context.
*
* @param site the workbench part site that created the action.
* @param context the undo context to be used for the undo
*/
public UndoActionHandler(IWorkbenchPartSite site, IUndoContext context) {
super(site, context);
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
setDisabledImageDescriptor(
PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO);
}
@Override
void flush() {
getHistory().dispose(getUndoContext(), true, false, false);
}
@Override
String getCommandString() {
return WorkbenchMessages.Operations_undoCommand;
}
@Override
String getTooltipString() {
return WorkbenchMessages.Operations_undoTooltipCommand;
}
@Override
String getSimpleCommandString() {
return WorkbenchMessages.Workbench_undo;
}
@Override
String getSimpleTooltipString() {
return WorkbenchMessages.Workbench_undoToolTip;
}
@Override
IUndoableOperation getOperation() {
return getHistory().getUndoOperation(getUndoContext());
}
@Override
IStatus runCommand(IProgressMonitor pm) throws ExecutionException {
return getHistory().undo(getUndoContext(), pm, this);
}
@Override
boolean shouldBeEnabled() {
return getHistory().canUndo(getUndoContext());
}
}
|