source: josm/trunk/src/org/openstreetmap/josm/actions/RedoAction.java @ 14134

Last change on this file since 14134 was 14134, checked in by Don-vip, 7 months ago

see #15229 - deprecate Main*.undoRedo - make UndoRedoHandler a singleton

  • Property svn:eol-style set to native
File size: 1.9 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.Main;
11import org.openstreetmap.josm.data.UndoRedoHandler;
12import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
13import org.openstreetmap.josm.gui.MainApplication;
14import org.openstreetmap.josm.gui.MapFrame;
15import org.openstreetmap.josm.tools.Shortcut;
16
17/**
18 * Redoes the last command.
19 *
20 * @author imi
21 */
22public class RedoAction extends JosmAction implements CommandQueueListener {
23
24    /**
25     * Construct the action with "Redo" as label.
26     */
27    public RedoAction() {
28        super(tr("Redo"), "redo", tr("Redo the last undone action."),
29                Shortcut.registerShortcut("system:redo", tr("Edit: {0}", tr("Redo")), KeyEvent.VK_Y, Shortcut.CTRL), true);
30        setEnabled(false);
31        putValue("help", ht("/Action/Redo"));
32    }
33
34    @Override
35    public void actionPerformed(ActionEvent e) {
36        MapFrame map = MainApplication.getMap();
37        if (map == null)
38            return;
39        map.repaint();
40        UndoRedoHandler.getInstance().redo();
41    }
42
43    @Override
44    protected void updateEnabledState() {
45        setEnabled(Main.main != null && !UndoRedoHandler.getInstance().redoCommands.isEmpty());
46    }
47
48    @Override
49    public void commandChanged(int queueSize, int redoSize) {
50        if (UndoRedoHandler.getInstance().redoCommands.isEmpty()) {
51            putValue(NAME, tr("Redo"));
52            setTooltip(tr("Redo the last undone action."));
53        } else {
54            putValue(NAME, tr("Redo ..."));
55            setTooltip(tr("Redo {0}",
56                    UndoRedoHandler.getInstance().redoCommands.getFirst().getDescriptionText()));
57        }
58    }
59}
Note: See TracBrowser for help on using the repository browser.