source: josm/trunk/src/org/openstreetmap/josm/actions/UndoAction.java@ 17534

Last change on this file since 17534 was 14397, checked in by Don-vip, 5 years ago

fix #16935 - simplify/cleanup help topics of ToggleDialog/ToggleDialogAction

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9
10import org.openstreetmap.josm.data.UndoRedoHandler;
11import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
12import org.openstreetmap.josm.gui.MainApplication;
13import org.openstreetmap.josm.gui.MapFrame;
14import org.openstreetmap.josm.tools.Shortcut;
15
16/**
17 * Undoes the last command.
18 *
19 * @author imi
20 */
21public class UndoAction extends JosmAction implements CommandQueueListener {
22
23 /**
24 * Construct the action with "Undo" as label.
25 */
26 public UndoAction() {
27 super(tr("Undo"), "undo", tr("Undo the last action."),
28 Shortcut.registerShortcut("system:undo", tr("Edit: {0}", tr("Undo")), KeyEvent.VK_Z, Shortcut.CTRL), true);
29 setEnabled(false);
30 setHelpId(ht("/Action/Undo"));
31 }
32
33 @Override
34 public void actionPerformed(ActionEvent e) {
35 MapFrame map = MainApplication.getMap();
36 if (map == null)
37 return;
38 map.repaint();
39 UndoRedoHandler.getInstance().undo();
40 }
41
42 @Override
43 protected void updateEnabledState() {
44 setEnabled(UndoRedoHandler.getInstance().hasUndoCommands());
45 }
46
47 @Override
48 public void commandChanged(int queueSize, int redoSize) {
49 if (!UndoRedoHandler.getInstance().hasUndoCommands()) {
50 putValue(NAME, tr("Undo"));
51 setTooltip(tr("Undo the last action."));
52 } else {
53 putValue(NAME, tr("Undo ..."));
54 setTooltip(tr("Undo {0}",
55 UndoRedoHandler.getInstance().getLastCommand().getDescriptionText()));
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.