Ticket #17196: 17196.3.patch
File 17196.3.patch, 5.4 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/data/UndoRedoHandler.java
3 3 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 10 12 import org.openstreetmap.josm.command.Command; 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; 15 19 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 40 44 private final LinkedList<CommandQueuePreciseListener> preciseListenerCommands = new LinkedList<>(); 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 46 52 /** … … 49 55 * @since 14134 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 55 67 /** … … 426 438 for (final CommandQueueListener l : listenerCommands) { 427 439 l.commandChanged(commands.size(), redoCommands.size()); 428 440 } 441 if (getInstance() != InstanceHolder.NO_DATA_SET_INSTANCE) { 442 for (final CommandQueueListener l : InstanceHolder.NO_DATA_SET_INSTANCE.listenerCommands) { 443 l.commandChanged(commands.size(), redoCommands.size()); 444 } 445 446 } 429 447 } 430 448 431 449 private void fireEvent(CommandQueueEvent e) { … … 450 468 public synchronized void clean(DataSet dataSet) { 451 469 if (dataSet == null) 452 470 return; 453 boolean changed = false; 454 changed |= commands.removeIf(c -> c.getAffectedDataSet() == dataSet); 455 changed |= redoCommands.removeIf(c -> c.getAffectedDataSet() == dataSet); 456 if (changed) { 471 if (InstanceHolder.map.remove(dataSet) != null) { 472 redoCommands.clear(); 473 commands.clear(); 457 474 fireEvent(new CommandQueueCleanedEvent(this, dataSet)); 458 475 fireCommandsChanged(); 459 476 } -
src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
50 50 import org.openstreetmap.josm.data.osm.OsmPrimitive; 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; 55 57 import org.openstreetmap.josm.tools.GBC; … … 62 64 * Dialog displaying list of all executed commands (undo/redo buffer). 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()); 68 70 private final DefaultTreeModel redoTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); … … 144 146 145 147 InputMapUtils.addEnterAction(undoTree, selectAndZoomAction); 146 148 InputMapUtils.addEnterAction(redoTree, selectAndZoomAction); 149 MainApplication.getLayerManager().addActiveLayerChangeListener(this); 147 150 } 148 151 149 152 private static class CommandCellRenderer extends DefaultTreeCellRenderer { … … 552 555 add(selectAndZoomAction); 553 556 } 554 557 } 558 559 @Override 560 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 561 hideNotify(); 562 showNotify(); 563 } 555 564 } -
test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java
27 27 */ 28 28 @Rule 29 29 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 30 public JOSMTestRules test = new JOSMTestRules().main().projection() ;30 public JOSMTestRules test = new JOSMTestRules().main().projection().preferences(); 31 31 32 32 /** 33 33 * Unit test of {@link CommandStackDialog} class - empty case.