| 582 | | //revert changes |
| 583 | | //FIXME: this is dirty hack |
| 584 | | makeCommitsOneAction(tr("Reverting changes")); |
| 585 | | if (addUndoRedo) { |
| 586 | | UndoRedoHandler.getInstance().undo(); |
| 587 | | // add no-change commands to the stack to remove the half-done commands |
| 588 | | Way w = ways.iterator().next(); |
| 589 | | cmds.add(new ChangeCommand(w, w)); |
| 590 | | cmds.add(new ChangeCommand(w, w)); |
| 591 | | commitCommands(tr("Reverting changes")); |
| 592 | | UndoRedoHandler.getInstance().undo(); |
| | 581 | tryUndo(); |
| | 582 | } catch (JosmRuntimeException exception) { |
| | 583 | Logging.trace(exception); |
| | 584 | tryUndo(); |
| | 585 | throw exception; |
| | 586 | } |
| | 587 | } |
| | 588 | |
| | 589 | private void tryUndo() { |
| | 590 | cmds.clear(); |
| | 591 | if (!executedCmds.isEmpty()) { |
| | 592 | // revert all executed commands |
| | 593 | ds = executedCmds.getFirst().getAffectedDataSet(); |
| | 594 | ds.beginUpdate(); |
| | 595 | while (!executedCmds.isEmpty()) { |
| | 596 | executedCmds.removeLast().undoCommand(); |
| 902 | | if (addUndoRedo) { |
| 903 | | UndoRedoHandler.getInstance().add(c); |
| 904 | | } else { |
| 905 | | c.executeCommand(); |
| | 906 | c.executeCommand(); |
| | 907 | executedCmds.add(c); |
| | 908 | } |
| | 909 | |
| | 910 | /** |
| | 911 | * Add all executed commands as one command to the undo stack without executing them again. |
| | 912 | */ |
| | 913 | private void commitExecuted() { |
| | 914 | cmds.clear(); |
| | 915 | if (addUndoRedo && !executedCmds.isEmpty()) { |
| | 916 | UndoRedoHandler ur = UndoRedoHandler.getInstance(); |
| | 917 | if (executedCmds.size() == 1) { |
| | 918 | ur.add(executedCmds.getFirst(), false); |
| | 919 | } else { |
| | 920 | ur.add(new JoinAreaCommand(executedCmds), false); |
| | 921 | } |
| 1710 | | /** |
| 1711 | | * Takes the last cmdsCount actions back and combines them into a single action |
| 1712 | | * (for when the user wants to undo the join action) |
| 1713 | | * @param message The commit message to display |
| 1714 | | */ |
| 1715 | | private void makeCommitsOneAction(String message) { |
| 1716 | | cmds.clear(); |
| 1717 | | if (addUndoRedo) { |
| 1718 | | UndoRedoHandler ur = UndoRedoHandler.getInstance(); |
| 1719 | | List<Command> commands = ur.getUndoCommands(); |
| 1720 | | int i = Math.max(commands.size() - cmdsCount, 0); |
| 1721 | | for (; i < commands.size(); i++) { |
| 1722 | | cmds.add(commands.get(i)); |
| 1723 | | } |
| 1724 | | ur.undo(cmds.size()); |
| 1725 | | } |
| 1726 | | |
| 1727 | | commitCommands(message == null ? marktr("Join Areas Function") : message); |
| 1728 | | cmdsCount = 0; |
| 1729 | | } |
| 1730 | | |
| | 1733 | |
| | 1734 | private static class JoinAreaCommand extends SequenceCommand { |
| | 1735 | JoinAreaCommand(Collection<Command> sequenz) { |
| | 1736 | super(tr("Joined overlapping areas"), sequenz, true); |
| | 1737 | setSequenceComplete(true); |
| | 1738 | } |
| | 1739 | |
| | 1740 | @Override |
| | 1741 | public void undoCommand() { |
| | 1742 | getAffectedDataSet().beginUpdate(); |
| | 1743 | super.undoCommand(); |
| | 1744 | getAffectedDataSet().endUpdate(); |
| | 1745 | } |
| | 1746 | |
| | 1747 | @Override |
| | 1748 | public boolean executeCommand() { |
| | 1749 | getAffectedDataSet().beginUpdate(); |
| | 1750 | boolean rc = super.executeCommand(); |
| | 1751 | getAffectedDataSet().endUpdate(); |
| | 1752 | return rc; |
| | 1753 | } |
| | 1754 | } |