Changeset 12718 in josm for trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
- Timestamp:
- 2017-09-04T00:50:22+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r12691 r12718 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.gui.MainApplication;14 import org.openstreetmap.josm.gui.layer.Layer;15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;17 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;19 import org.openstreetmap.josm.gui.layer.OsmDataLayer;20 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;21 13 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 14 23 15 /** 24 * This is the global undo/redo handler for all {@link OsmDataLayer}s.16 * This is the global undo/redo handler for all {@link DataSet}s. 25 17 * <p> 26 * If you want to change a data layer, you can use {@link #add(Command)} to execute a command on it and make that command undoable.18 * If you want to change a data set, you can use {@link #add(Command)} to execute a command on it and make that command undoable. 27 19 */ 28 public class UndoRedoHandler implements LayerChangeListener{20 public class UndoRedoHandler { 29 21 30 22 /** … … 45 37 */ 46 38 public UndoRedoHandler() { 47 MainApplication.getLayerManager().addLayerChangeListener(this); 39 // Do nothing 40 } 41 42 /** 43 * A listener that gets notified of command queue (undo/redo) size changes. 44 * @since 12718 (moved from {@code OsmDataLayer} 45 */ 46 @FunctionalInterface 47 public interface CommandQueueListener { 48 /** 49 * Notifies the listener about the new queue size 50 * @param queueSize Undo stack size 51 * @param redoSize Redo stack size 52 */ 53 void commandChanged(int queueSize, int redoSize); 48 54 } 49 55 … … 92 98 } 93 99 addNoRedraw(c); 94 c.invalidateAffectedLayers();95 100 afterAdd(); 96 101 … … 125 130 final Command c = commands.removeLast(); 126 131 c.undoCommand(); 127 c.invalidateAffectedLayers();128 132 redoCommands.addFirst(c); 129 133 if (commands.isEmpty()) { … … 161 165 final Command c = redoCommands.removeFirst(); 162 166 c.executeCommand(); 163 c.invalidateAffectedLayers();164 167 commands.add(c); 165 168 if (redoCommands.isEmpty()) { … … 197 200 198 201 /** 199 * Resets all commands that affect the given layer. 200 * @param layer The layer that was affected. 201 */ 202 public void clean(Layer layer) { 203 if (layer == null) 202 * Resets all commands that affect the given dataset. 203 * @param dataSet The data set that was affected. 204 * @since 12718 205 */ 206 public void clean(DataSet dataSet) { 207 if (dataSet == null) 204 208 return; 205 209 boolean changed = false; 206 210 for (Iterator<Command> it = commands.iterator(); it.hasNext();) { 207 if (it.next(). invalidBecauselayerRemoved(layer)) {211 if (it.next().getAffectedDataSet() == dataSet) { 208 212 it.remove(); 209 213 changed = true; … … 211 215 } 212 216 for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) { 213 if (it.next(). invalidBecauselayerRemoved(layer)) {217 if (it.next().getAffectedDataSet() == dataSet) { 214 218 it.remove(); 215 219 changed = true; … … 219 223 fireCommandsChanged(); 220 224 } 221 }222 223 @Override224 public void layerRemoving(LayerRemoveEvent e) {225 clean(e.getRemovedLayer());226 }227 228 @Override229 public void layerAdded(LayerAddEvent e) {230 // Do nothing231 }232 233 @Override234 public void layerOrderChanged(LayerOrderChangeEvent e) {235 // Do nothing236 225 } 237 226
Note:
See TracChangeset
for help on using the changeset viewer.