Ticket #18133: 18133.patch

File 18133.patch, 3.6 KB (added by simon04, 4 years ago)
  • src/org/openstreetmap/josm/data/UndoRedoHandler.java

    diff --git a/src/org/openstreetmap/josm/data/UndoRedoHandler.java b/src/org/openstreetmap/josm/data/UndoRedoHandler.java
    index 0602ecea0..29541aadd 100644
    a b public synchronized void undo(int num) {  
    393393        });
    394394    }
    395395
     396    /**
     397     * Undoes the specified command.
     398     * @param command the command to undo
     399     * @throws NullPointerException if the command is null
     400     * @since xxx
     401     */
     402    public synchronized void undo(Command command) {
     403        Objects.requireNonNull(command, "command");
     404        if (commands.remove(command)) {
     405            command.undoCommand();
     406            redoCommands.add(command);
     407            fireCommandsChanged();
     408        }
     409    }
     410
    396411    /**
    397412     * Redoes the last undoed command.
    398413     */
  • src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java b/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
    index 554aba099..d998586ec 100644
    a b  
    8686    private UndoRedoType lastOperation = UndoRedoType.UNDO;
    8787
    8888    // Actions for context menu and Enter key
     89    private final UndoCommandAction undoCommandAction = new UndoCommandAction();
    8990    private final SelectAction selectAction = new SelectAction();
    9091    private final SelectAndZoomAction selectAndZoomAction = new SelectAndZoomAction();
    9192
    protected CommandListMutableTreeNode getNodeForCommand(PseudoCommand c) {  
    347348    /**
    348349     * Return primitives that are affected by some command
    349350     * @param path GUI elements
    350      * @return collection of affected primitives, onluy usable ones
     351     * @return collection of affected primitives, only usable ones
    351352     */
    352353    protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(TreePath path) {
    353354        PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
    private void swapNode(DefaultTreeModel srcModel, DefaultMutableTreeNode srcRoot,  
    408409        ensureTreesConsistency();
    409410    }
    410411
     412    /**
     413     * Action that undoes the single selected command, but not the commands that followed after.
     414     * @since xxx
     415     */
     416    public class UndoCommandAction extends AbstractAction {
     417
     418        /**
     419         * Constructs a new {@code UndoCommandAction}.
     420         */
     421        public UndoCommandAction() {
     422            putValue(NAME, tr("Undo this action"));
     423            putValue(SHORT_DESCRIPTION, tr("Undo this action"));
     424            new ImageProvider("undo").getResource().attachImageIcon(this, true);
     425        }
     426
     427        @Override
     428        public void actionPerformed(ActionEvent e) {
     429            if (!undoTree.isSelectionEmpty()) {
     430                undoSelected();
     431            }
     432        }
     433
     434        private void undoSelected() {
     435            final TreePath path = undoTree.getSelectionPath();
     436            final PseudoCommand command = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
     437            if (command instanceof Command) {
     438                UndoRedoHandler.getInstance().undo((Command) command);
     439                buildTrees();
     440            }
     441        }
     442    }
     443
    411444    /**
    412445     * Action that selects the objects that take part in a command.
    413446     */
    public void mouseClicked(MouseEvent evt) {  
    546579
    547580    private class CommandStackPopup extends JPopupMenu {
    548581        CommandStackPopup() {
     582            add(undoCommandAction);
    549583            add(selectAction);
    550584            add(selectAndZoomAction);
    551585        }