Changeset 12316 in josm


Ignore:
Timestamp:
2017-06-04T20:59:41+02:00 (2 years ago)
Author:
michael2402
Message:

Add a method to undo/redo to get the last command.

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

Legend:

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

    r12315 r12316  
    133133        Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
    134134
    135         Command c = !Main.main.undoRedo.commands.isEmpty()
    136         ? Main.main.undoRedo.commands.getLast() : null;
     135        Command c = Main.main.undoRedo.getLastCommand();
    137136
    138137        ds.beginUpdate();
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r12284 r12316  
    13231323        public void actionPerformed(ActionEvent e) {
    13241324            Main.main.undoRedo.undo();
    1325             Command lastCmd = Main.main.undoRedo.commands.peekLast();
     1325            Command lastCmd = Main.main.undoRedo.getLastCommand();
    13261326            if (lastCmd == null) return;
    13271327            Node n = null;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r12314 r12316  
    809809     */
    810810    private static Command getLastCommandInDataset(DataSet ds) {
    811         LinkedList<Command> commands = Main.main.undoRedo.commands;
    812         if (!commands.isEmpty()) {
    813             Command lastCommand = commands.getLast();
    814             if (lastCommand instanceof SequenceCommand) {
    815                 lastCommand = ((SequenceCommand) lastCommand).getLastCommand();
    816             }
    817             if (ds.equals(lastCommand.getAffectedDataSet())) {
    818                 return lastCommand;
    819             }
    820         }
    821         return null;
     811        Command lastCommand = Main.main.undoRedo.getLastCommand();
     812        if (lastCommand instanceof SequenceCommand) {
     813            lastCommand = ((SequenceCommand) lastCommand).getLastCommand();
     814        }
     815        if (lastCommand != null && ds.equals(lastCommand.getAffectedDataSet())) {
     816            return lastCommand;
     817        } else {
     818            return null;
     819        }
    822820    }
    823821
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r11627 r12316  
    2929    /**
    3030     * All commands that were made on the dataset. Don't write from outside!
     31     *
     32     * @see #getLastCommand()
    3133     */
    3234    public final LinkedList<Command> commands = new LinkedList<>();
     
    4345    public UndoRedoHandler() {
    4446        Main.getLayerManager().addLayerChangeListener(this);
     47    }
     48
     49    /**
     50     * Gets the last command that was executed on the command stack.
     51     * @return That command or <code>null</code> if there is no such command.
     52     * @since #12316
     53     */
     54    public Command getLastCommand() {
     55        return commands.peekLast();
    4556    }
    4657
Note: See TracChangeset for help on using the changeset viewer.