- Timestamp:
- 2020-02-22T07:47:13+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r15887 r15890 58 58 public class JoinAreasAction extends JosmAction { 59 59 // This will be used to commit commands and unite them into one large command sequence at the end 60 private final transient LinkedList<Command> executedCmds = new LinkedList<>(); 60 61 private final transient LinkedList<Command> cmds = new LinkedList<>(); 61 private int cmdsCount;62 62 private DataSet ds; 63 63 private final transient List<Relation> addedRelations = new LinkedList<>(); … … 485 485 private void clearFields() { 486 486 ds = null; 487 cmdsCount = 0;488 487 cmds.clear(); 489 488 addedRelations.clear(); … … 562 561 commitCommands(tr("Move tags from ways to relations")); 563 562 564 makeCommitsOneAction(marktr("Joined overlapping areas"));563 commitExecuted(); 565 564 566 565 if (result.polygons != null && ds != null) { … … 580 579 } catch (UserCancelException exception) { 581 580 Logging.trace(exception); 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(); 593 } 581 tryUndo(); 582 } catch (JosmRuntimeException | IllegalArgumentException 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(); 597 } 598 ds.endUpdate(); 594 599 } 595 600 } … … 896 901 897 902 cmds.clear(); 898 cmdsCount++;899 903 } 900 904 901 905 private void commitCommand(Command c) { 902 if (addUndoRedo) { 903 UndoRedoHandler.getInstance().add(c); 904 } else { 905 c.executeCommand(); 906 } 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 } 922 } 923 executedCmds.clear(); 907 924 } 908 925 … … 1436 1453 // the user about this. 1437 1454 1438 //TODO: ReverseWay and Combine way are really slow and we use them a lot here. This slows down large joins.1439 1455 List<Way> actionWays = new ArrayList<>(ways.size()); 1440 1456 int oldestPos = 0; … … 1450 1466 ReverseWayResult res = ReverseWayAction.reverseWay(way.way); 1451 1467 commitCommand(res.getReverseCommand()); 1452 cmdsCount++;1453 1468 } 1454 1469 } … … 1462 1477 } 1463 1478 commitCommand(result.b); 1464 cmdsCount++;1465 1479 1466 1480 return result.a; … … 1708 1722 } 1709 1723 1710 /**1711 * Takes the last cmdsCount actions back and combines them into a single action1712 * (for when the user wants to undo the join action)1713 * @param message The commit message to display1714 */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 1731 1724 @Override 1732 1725 protected void updateEnabledState() { … … 1738 1731 updateEnabledStateOnModifiableSelection(selection); 1739 1732 } 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 } 1740 1755 }
Note:
See TracChangeset
for help on using the changeset viewer.