| [6380] | 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| [626] | 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| [3810] | 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| [626] | 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 | import java.awt.event.KeyEvent;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.Main;
|
|---|
| [12630] | 11 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 12 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| [4908] | 13 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
|---|
| [1084] | 14 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| [626] | 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * Undoes the last command.
|
|---|
| [1023] | 18 | *
|
|---|
| [626] | 19 | * @author imi
|
|---|
| 20 | */
|
|---|
| [4908] | 21 | public class UndoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {
|
|---|
| [626] | 22 |
|
|---|
| [1169] | 23 | /**
|
|---|
| 24 | * Construct the action with "Undo" as label.
|
|---|
| 25 | */
|
|---|
| 26 | public UndoAction() {
|
|---|
| 27 | super(tr("Undo"), "undo", tr("Undo the last action."),
|
|---|
| [4982] | 28 | Shortcut.registerShortcut("system:undo", tr("Edit: {0}", tr("Undo")), KeyEvent.VK_Z, Shortcut.CTRL), true);
|
|---|
| [1169] | 29 | setEnabled(false);
|
|---|
| [2323] | 30 | putValue("help", ht("/Action/Undo"));
|
|---|
| [1169] | 31 | }
|
|---|
| [626] | 32 |
|
|---|
| [6084] | 33 | @Override
|
|---|
| [1169] | 34 | public void actionPerformed(ActionEvent e) {
|
|---|
| [12630] | 35 | MapFrame map = MainApplication.getMap();
|
|---|
| 36 | if (map == null)
|
|---|
| [1169] | 37 | return;
|
|---|
| [12630] | 38 | map.repaint();
|
|---|
| [12641] | 39 | MainApplication.undoRedo.undo();
|
|---|
| [1169] | 40 | }
|
|---|
| [1820] | 41 |
|
|---|
| 42 | @Override
|
|---|
| 43 | protected void updateEnabledState() {
|
|---|
| [12641] | 44 | setEnabled(Main.main != null && !MainApplication.undoRedo.commands.isEmpty());
|
|---|
| [1820] | 45 | }
|
|---|
| [3810] | 46 |
|
|---|
| [4908] | 47 | @Override
|
|---|
| 48 | public void commandChanged(int queueSize, int redoSize) {
|
|---|
| [12641] | 49 | if (MainApplication.undoRedo.commands.isEmpty()) {
|
|---|
| [4908] | 50 | putValue(NAME, tr("Undo"));
|
|---|
| 51 | setTooltip(tr("Undo the last action."));
|
|---|
| 52 | } else {
|
|---|
| 53 | putValue(NAME, tr("Undo ..."));
|
|---|
| 54 | setTooltip(tr("Undo {0}",
|
|---|
| [12641] | 55 | MainApplication.undoRedo.commands.getLast().getDescriptionText()));
|
|---|
| [4908] | 56 | }
|
|---|
| 57 | }
|
|---|
| [626] | 58 | }
|
|---|