| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 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.data.UndoRedoHandler;
|
|---|
| 11 | import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
|
|---|
| 12 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 13 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 14 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * Redoes the last command.
|
|---|
| 18 | *
|
|---|
| 19 | * @author imi
|
|---|
| 20 | */
|
|---|
| 21 | public class RedoAction extends JosmAction implements CommandQueueListener {
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * Construct the action with "Redo" as label.
|
|---|
| 25 | */
|
|---|
| 26 | public RedoAction() {
|
|---|
| 27 | super(tr("Redo"), "redo", tr("Redo the last undone action."),
|
|---|
| 28 | Shortcut.registerShortcut("system:redo", tr("Edit: {0}", tr("Redo")), KeyEvent.VK_Y, Shortcut.CTRL), true);
|
|---|
| 29 | setEnabled(false);
|
|---|
| 30 | setHelpId(ht("/Action/Redo"));
|
|---|
| 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().redo();
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | @Override
|
|---|
| 43 | protected void updateEnabledState() {
|
|---|
| 44 | setEnabled(UndoRedoHandler.getInstance().hasRedoCommands());
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | @Override
|
|---|
| 48 | public void commandChanged(int queueSize, int redoSize) {
|
|---|
| 49 | if (!UndoRedoHandler.getInstance().hasRedoCommands()) {
|
|---|
| 50 | putValue(NAME, tr("Redo"));
|
|---|
| 51 | setTooltip(tr("Redo the last undone action."));
|
|---|
| 52 | } else {
|
|---|
| 53 | putValue(NAME, tr("Redo ..."));
|
|---|
| 54 | setTooltip(tr("Redo {0}",
|
|---|
| 55 | UndoRedoHandler.getInstance().getRedoCommands().get(0).getDescriptionText()));
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|