Changeset 17347 in josm for trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
- Timestamp:
- 2020-11-24T07:00:30+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r17342 r17347 4 4 import java.util.Collections; 5 5 import java.util.EventObject; 6 import java.util.HashMap; 6 7 import java.util.LinkedList; 7 8 import java.util.List; 9 import java.util.Map; 8 10 import java.util.Objects; 9 11 … … 11 13 import org.openstreetmap.josm.data.osm.DataSet; 12 14 import org.openstreetmap.josm.data.osm.OsmDataManager; 15 import org.openstreetmap.josm.gui.MainApplication; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 17 import org.openstreetmap.josm.gui.util.GuiHelper; 14 18 import org.openstreetmap.josm.spi.preferences.Config; … … 41 45 42 46 private static class InstanceHolder { 43 static final UndoRedoHandler INSTANCE = new UndoRedoHandler(); 47 static final UndoRedoHandler NO_DATA_SET_INSTANCE = new UndoRedoHandler(); 48 static final Map<DataSet, UndoRedoHandler> map = new HashMap<>(); 49 44 50 } 45 51 … … 50 56 */ 51 57 public static UndoRedoHandler getInstance() { 52 return InstanceHolder.INSTANCE; 58 OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer(); 59 if (editLayer != null) { 60 if (editLayer == MainApplication.getLayerManager().getActiveLayer()) { 61 return InstanceHolder.map.computeIfAbsent(editLayer.data, k -> new UndoRedoHandler()); 62 } 63 } 64 return InstanceHolder.NO_DATA_SET_INSTANCE; 53 65 } 54 66 … … 433 445 l.commandChanged(commands.size(), redoCommands.size()); 434 446 } 447 if (getInstance() != InstanceHolder.NO_DATA_SET_INSTANCE) { 448 for (final CommandQueueListener l : InstanceHolder.NO_DATA_SET_INSTANCE.listenerCommands) { 449 l.commandChanged(commands.size(), redoCommands.size()); 450 } 451 452 } 435 453 } 436 454 … … 457 475 if (dataSet == null) 458 476 return; 459 boolean changed = false; 460 changed |= commands.removeIf(c -> c.getAffectedDataSet() == dataSet); 461 changed |= redoCommands.removeIf(c -> c.getAffectedDataSet() == dataSet); 462 if (changed) { 477 if (InstanceHolder.map.remove(dataSet) != null) { 478 redoCommands.clear(); 479 commands.clear(); 463 480 fireEvent(new CommandQueueCleanedEvent(this, dataSet)); 464 481 fireCommandsChanged();
Note:
See TracChangeset
for help on using the changeset viewer.
