| 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
|---|
| 2 | package org.openstreetmap.josm.actions; |
|---|
| 3 | |
|---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht; |
|---|
| 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; |
|---|
| 11 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
|---|
| 12 | import org.openstreetmap.josm.tools.Shortcut; |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * Undoes the last command. |
|---|
| 16 | * |
|---|
| 17 | * @author imi |
|---|
| 18 | */ |
|---|
| 19 | public class UndoAction extends JosmAction implements OsmDataLayer.CommandQueueListener { |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Construct the action with "Undo" as label. |
|---|
| 23 | */ |
|---|
| 24 | public UndoAction() { |
|---|
| 25 | super(tr("Undo"), "undo", tr("Undo the last action."), |
|---|
| 26 | Shortcut.registerShortcut("system:undo", tr("Edit: {0}", tr("Undo")), KeyEvent.VK_Z, Shortcut.CTRL), true); |
|---|
| 27 | setEnabled(false); |
|---|
| 28 | putValue("help", ht("/Action/Undo")); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public void actionPerformed(ActionEvent e) { |
|---|
| 32 | if (Main.map == null) |
|---|
| 33 | return; |
|---|
| 34 | Main.map.repaint(); |
|---|
| 35 | Main.main.undoRedo.undo(); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | @Override |
|---|
| 39 | protected void updateEnabledState() { |
|---|
| 40 | setEnabled(Main.main != null && !Main.main.undoRedo.commands.isEmpty()); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | @Override |
|---|
| 44 | public void commandChanged(int queueSize, int redoSize) { |
|---|
| 45 | if (Main.main.undoRedo.commands.isEmpty()) { |
|---|
| 46 | putValue(NAME, tr("Undo")); |
|---|
| 47 | setTooltip(tr("Undo the last action.")); |
|---|
| 48 | } else { |
|---|
| 49 | putValue(NAME, tr("Undo ...")); |
|---|
| 50 | setTooltip(tr("Undo {0}", |
|---|
| 51 | Main.main.undoRedo.commands.getFirst().getDescriptionText())); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | } |
|---|