Changeset 17347 in josm for trunk/src/org
- Timestamp:
- 2020-11-24T07:00:30+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 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(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r17188 r17347 51 51 import org.openstreetmap.josm.gui.MainApplication; 52 52 import org.openstreetmap.josm.gui.SideButton; 53 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 54 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 53 55 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 54 56 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 63 65 * @since 94 64 66 */ 65 public class CommandStackDialog extends ToggleDialog implements CommandQueuePreciseListener {67 public class CommandStackDialog extends ToggleDialog implements CommandQueuePreciseListener, ActiveLayerChangeListener { 66 68 67 69 private final DefaultTreeModel undoTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); … … 145 147 InputMapUtils.addEnterAction(undoTree, selectAndZoomAction); 146 148 InputMapUtils.addEnterAction(redoTree, selectAndZoomAction); 149 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 147 150 } 148 151 … … 553 556 } 554 557 } 558 559 @Override 560 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 561 hideNotify(); 562 showNotify(); 563 } 555 564 }
Note:
See TracChangeset
for help on using the changeset viewer.