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) {
|
393 | 393 | }); |
394 | 394 | } |
395 | 395 | |
| 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 | |
396 | 411 | /** |
397 | 412 | * Redoes the last undoed command. |
398 | 413 | */ |
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
|
|
86 | 86 | private UndoRedoType lastOperation = UndoRedoType.UNDO; |
87 | 87 | |
88 | 88 | // Actions for context menu and Enter key |
| 89 | private final UndoCommandAction undoCommandAction = new UndoCommandAction(); |
89 | 90 | private final SelectAction selectAction = new SelectAction(); |
90 | 91 | private final SelectAndZoomAction selectAndZoomAction = new SelectAndZoomAction(); |
91 | 92 | |
… |
… |
protected CommandListMutableTreeNode getNodeForCommand(PseudoCommand c) {
|
347 | 348 | /** |
348 | 349 | * Return primitives that are affected by some command |
349 | 350 | * @param path GUI elements |
350 | | * @return collection of affected primitives, onluy usable ones |
| 351 | * @return collection of affected primitives, only usable ones |
351 | 352 | */ |
352 | 353 | protected static Collection<? extends OsmPrimitive> getAffectedPrimitives(TreePath path) { |
353 | 354 | PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand(); |
… |
… |
private void swapNode(DefaultTreeModel srcModel, DefaultMutableTreeNode srcRoot,
|
408 | 409 | ensureTreesConsistency(); |
409 | 410 | } |
410 | 411 | |
| 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 | |
411 | 444 | /** |
412 | 445 | * Action that selects the objects that take part in a command. |
413 | 446 | */ |
… |
… |
public void mouseClicked(MouseEvent evt) {
|
546 | 579 | |
547 | 580 | private class CommandStackPopup extends JPopupMenu { |
548 | 581 | CommandStackPopup() { |
| 582 | add(undoCommandAction); |
549 | 583 | add(selectAction); |
550 | 584 | add(selectAndZoomAction); |
551 | 585 | } |