Changeset 4908 in josm


Ignore:
Timestamp:
2012-02-08T22:31:29+01:00 (8 years ago)
Author:
simon04
Message:

fix #7327 - show hint in undo-menu which action will be undone (from event stack)

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r4901 r4908  
    268268        menu = new MainMenu();
    269269
    270         undoRedo.listenerCommands.add(redoUndoListener);
     270        undoRedo.addCommandQueueListener(redoUndoListener);
    271271
    272272        // creating toolbar
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r4733 r4908  
    7474            Main.registerActionShortcut(this, sc);
    7575        }
    76         putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc));
     76        setTooltip(tooltip);
    7777        if (getValue("toolbar") == null) {
    7878            putValue("toolbar", toolbarId == null ? iconName : toolbarId);
     
    119119        }
    120120        putValue("help", helpId);
     121    }
     122
     123    public void setTooltip(String tooltip) {
     124        putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc));
    121125    }
    122126
  • trunk/src/org/openstreetmap/josm/actions/RedoAction.java

    r3810 r4908  
    99
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1112import org.openstreetmap.josm.tools.Shortcut;
    1213
     
    1617 * @author imi
    1718 */
    18 public class RedoAction extends JosmAction {
     19public class RedoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {
    1920
    2021    /**
     
    3940        setEnabled(Main.main != null && !Main.main.undoRedo.redoCommands.isEmpty());
    4041    }
     42
     43    @Override
     44    public void commandChanged(int queueSize, int redoSize) {
     45        if (Main.main.undoRedo.redoCommands.isEmpty()) {
     46            putValue(NAME, tr("Redo"));
     47            setTooltip(tr("Redo the last undone action."));
     48        } else {
     49            putValue(NAME, tr("Redo ..."));
     50            setTooltip(tr("Redo {0}",
     51                    Main.main.undoRedo.redoCommands.getFirst().getDescrpitionText()));
     52        }
     53    }
    4154}
  • trunk/src/org/openstreetmap/josm/actions/UndoAction.java

    r3810 r4908  
    99
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1112import org.openstreetmap.josm.tools.Shortcut;
    1213
     
    1617 * @author imi
    1718 */
    18 public class UndoAction extends JosmAction {
     19public class UndoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {
    1920
    2021    /**
     
    4041    }
    4142
     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().getDescrpitionText()));
     52        }
     53    }
    4254}
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r4894 r4908  
    160160    @Override public Collection<? extends OsmPrimitive> getParticipatingPrimitives() {
    161161        return cloneMap.keySet();
     162    }
     163
     164    public String getDescrpitionText() {
     165        Object o = getDescription();
     166        if (o instanceof JLabel) {
     167            return ((JLabel) o).getText();
     168        } else {
     169            return o.toString();
     170        }
    162171    }
    163172
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r3910 r4908  
    2424    public final LinkedList<Command> redoCommands = new LinkedList<Command>();
    2525
    26     public final LinkedList<CommandQueueListener> listenerCommands = new LinkedList<CommandQueueListener>();
     26    private final LinkedList<CommandQueueListener> listenerCommands = new LinkedList<CommandQueueListener>();
    2727
    2828    public UndoRedoHandler() {
     
    163163    public void layerAdded(Layer newLayer) {}
    164164    public void activeLayerChange(Layer oldLayer, Layer newLayer) {}
     165
     166    public void removeCommandQueueListener(CommandQueueListener l) {
     167        listenerCommands.remove(l);
     168    }
     169
     170    public boolean addCommandQueueListener(CommandQueueListener l) {
     171        return listenerCommands.add(l);
     172    }
    165173}
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r4843 r4908  
    401401
    402402        add(editMenu, undo);
     403        Main.main.undoRedo.addCommandQueueListener(undo);
    403404        add(editMenu, redo);
     405        Main.main.undoRedo.addCommandQueueListener(redo);
    404406        editMenu.addSeparator();
    405407        add(editMenu, copy);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r4395 r4908  
    203203            listener.updateEnabledState();
    204204        }
    205         Main.main.undoRedo.listenerCommands.add(this);
     205        Main.main.undoRedo.addCommandQueueListener(this);
    206206    }
    207207
     
    219219        undoTreeModel.setRoot(new DefaultMutableTreeNode());
    220220        redoTreeModel.setRoot(new DefaultMutableTreeNode());
    221         Main.main.undoRedo.listenerCommands.remove(this);
     221        Main.main.undoRedo.removeCommandQueueListener(this);
    222222    }
    223223
Note: See TracChangeset for help on using the changeset viewer.