Changeset 16187 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2020-03-21T21:27:36+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r16048 r16187 592 592 // revert all executed commands 593 593 ds = executedCmds.getFirst().getAffectedDataSet(); 594 ds. beginUpdate();595 while (!executedCmds.isEmpty()) {596 executedCmds.removeLast().undoCommand();597 }598 ds.endUpdate();594 ds.update(() -> { 595 while (!executedCmds.isEmpty()) { 596 executedCmds.removeLast().undoCommand(); 597 } 598 }); 599 599 } 600 600 } … … 1748 1748 @Override 1749 1749 public void undoCommand() { 1750 getAffectedDataSet().beginUpdate(); 1751 super.undoCommand(); 1752 getAffectedDataSet().endUpdate(); 1750 getAffectedDataSet().update(super::undoCommand); 1753 1751 } 1754 1752 1755 1753 @Override 1756 1754 public boolean executeCommand() { 1757 getAffectedDataSet().beginUpdate(); 1758 boolean rc = super.executeCommand(); 1759 getAffectedDataSet().endUpdate(); 1760 return rc; 1755 return getAffectedDataSet().update(super::executeCommand); 1761 1756 } 1762 1757 } -
trunk/src/org/openstreetmap/josm/actions/MoveAction.java
r15676 r16187 12 12 import javax.swing.JOptionPane; 13 13 14 import org.openstreetmap.josm.command.Command;15 14 import org.openstreetmap.josm.command.MoveCommand; 16 15 import org.openstreetmap.josm.data.UndoRedoHandler; … … 98 97 } 99 98 100 @Override 101 public void actionPerformed(ActionEvent event) { 102 DataSet ds = getLayerManager().getEditDataSet(); 103 104 if (!MainApplication.isDisplayingMapView() || ds == null) 105 return; 106 107 // find out how many "real" units the objects have to be moved in order to 108 // achive an 1-pixel movement 109 110 MapView mapView = MainApplication.getMap().mapView; 99 /** 100 * Find out how many "real" units the objects have to be moved in order to achieve an 1-pixel movement 101 * @param mapView map view 102 * @return move offset 103 */ 104 private EastNorth getOffset(MapView mapView) { 111 105 EastNorth en1 = mapView.getEastNorth(100, 100); 112 106 EastNorth en2 = mapView.getEastNorth(101, 101); … … 131 125 } 132 126 127 return new EastNorth(distx, disty); 128 } 129 130 @Override 131 public void actionPerformed(ActionEvent event) { 132 DataSet ds = getLayerManager().getEditDataSet(); 133 134 if (!MainApplication.isDisplayingMapView() || ds == null) 135 return; 136 137 MapView mapView = MainApplication.getMap().mapView; 138 final EastNorth dist = getOffset(mapView); 139 133 140 Collection<OsmPrimitive> selection = ds.getSelected(); 134 141 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 135 142 136 Command c = UndoRedoHandler.getInstance().getLastCommand(); 137 138 ds.beginUpdate(); 139 try { 143 MoveCommand cmd = ds.update(c -> { 144 MoveCommand moveCmd; 140 145 if (c instanceof MoveCommand && ds.equals(c.getAffectedDataSet()) 141 146 && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) { 142 ((MoveCommand) c).moveAgain(distx, disty); 147 moveCmd = (MoveCommand) c; 148 moveCmd.moveAgain(dist.east(), dist.north()); 143 149 } else { 144 c = new MoveCommand(ds, selection, distx, disty);145 UndoRedoHandler.getInstance().add( c);150 moveCmd = new MoveCommand(ds, selection, dist.east(), dist.north()); 151 UndoRedoHandler.getInstance().add(moveCmd); 146 152 } 147 } finally { 148 ds.endUpdate(); 149 } 153 return moveCmd; 154 }, UndoRedoHandler.getInstance().getLastCommand()); 150 155 151 156 for (Node n : affectedNodes) { 152 157 if (n.isLatLonKnown() && n.isOutSideWorld()) { 153 158 // Revert move 154 ((MoveCommand) c).moveAgain(-distx, -disty);159 cmd.moveAgain(-dist.east(), -dist.north()); 155 160 JOptionPane.showMessageDialog( 156 161 MainApplication.getMainFrame(), -
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r15586 r16187 172 172 public void actionPerformed(ActionEvent e) { 173 173 DataSet ds = getLayerManager().getEditDataSet(); 174 ds.beginUpdate(); 175 try { 174 ds.update(() -> { 176 175 List<Way> ways = ds.getSelectedWays().stream() 177 176 .filter(p -> !p.isIncomplete()) … … 195 194 simplifyWays(ways, err); 196 195 } 197 } finally { 198 ds.endUpdate(); 199 } 196 }); 200 197 } 201 198 -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r15735 r16187 247 247 248 248 private static void addRemoveSelection(DataSet ds, OsmPrimitive toAdd, OsmPrimitive toRemove) { 249 ds.beginUpdate(); // to prevent the selection listener to screw around with the state 250 try { 249 ds.update(() -> { // to prevent the selection listener to screw around with the state 251 250 addSelection(ds, toAdd); 252 251 clearSelection(ds, toRemove); 253 } finally { 254 ds.endUpdate(); 255 } 252 }); 256 253 } 257 254 -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r16177 r16187 712 712 if (mode == Mode.MOVE) { 713 713 if (startEN == null) return false; // fix #8128 714 ds.beginUpdate();715 try {714 return ds.update(() -> { 715 MoveCommand moveCmd = null; 716 716 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) { 717 ((MoveCommand) c).saveCheckpoint(); 718 ((MoveCommand) c).applyVectorTo(currentEN); 717 moveCmd = (MoveCommand) c; 718 moveCmd.saveCheckpoint(); 719 moveCmd.applyVectorTo(currentEN); 719 720 } else if (!selection.isEmpty()) { 720 c= new MoveCommand(selection, startEN, currentEN);721 UndoRedoHandler.getInstance().add( c);721 moveCmd = new MoveCommand(selection, startEN, currentEN); 722 UndoRedoHandler.getInstance().add(moveCmd); 722 723 } 723 724 for (Node n : affectedNodes) { 724 725 if (n.isOutSideWorld()) { 725 726 // Revert move 726 if ( c instanceof MoveCommand) {727 ((MoveCommand) c).resetToCheckpoint();727 if (moveCmd != null) { 728 moveCmd.resetToCheckpoint(); 728 729 } 729 730 // TODO: We might use a simple notification in the lower left corner. … … 737 738 } 738 739 } 739 } finally { 740 ds.endUpdate(); 741 } 740 return true; 741 }); 742 742 } else { 743 743 startEN = currentEN; // drag can continue after scaling/rotation … … 747 747 } 748 748 749 ds.beginUpdate(); 750 try { 749 return ds.update(() -> { 751 750 if (mode == Mode.ROTATE) { 752 751 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) { … … 767 766 MainApplication.getMap().statusLine.setDist(ways); 768 767 } 769 } finally { 770 ds.endUpdate(); 771 } 772 } 773 return true; 768 return true; 769 }); 770 } 774 771 } 775 772 … … 910 907 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 911 908 Command c = getLastCommandInDataset(ds); 912 ds.beginUpdate(); 913 try { 909 ds.update(() -> { 914 910 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) { 915 911 Node selectedNode = selNodes.iterator().next(); … … 919 915 targetEN.getY() - selectedEN.getY()); 920 916 } 921 } finally { 922 ds.endUpdate(); 923 } 917 }); 924 918 } 925 919
Note:
See TracChangeset
for help on using the changeset viewer.