Changeset 17347 in josm for trunk/src/org


Ignore:
Timestamp:
2020-11-24T07:00:30+01:00 (4 years ago)
Author:
GerdP
Message:

fix #17196: Undo/Redo may change data in inactive layer

  • use separate stacks for each edit layer
  • show empty undo/redo stack when active layer isn't an edit layer
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r17342 r17347  
    44import java.util.Collections;
    55import java.util.EventObject;
     6import java.util.HashMap;
    67import java.util.LinkedList;
    78import java.util.List;
     9import java.util.Map;
    810import java.util.Objects;
    911
     
    1113import org.openstreetmap.josm.data.osm.DataSet;
    1214import org.openstreetmap.josm.data.osm.OsmDataManager;
     15import org.openstreetmap.josm.gui.MainApplication;
     16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1317import org.openstreetmap.josm.gui.util.GuiHelper;
    1418import org.openstreetmap.josm.spi.preferences.Config;
     
    4145
    4246    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
    4450    }
    4551
     
    5056     */
    5157    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;
    5365    }
    5466
     
    433445            l.commandChanged(commands.size(), redoCommands.size());
    434446        }
     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        }
    435453    }
    436454
     
    457475        if (dataSet == null)
    458476            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();
    463480            fireEvent(new CommandQueueCleanedEvent(this, dataSet));
    464481            fireCommandsChanged();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r17188 r17347  
    5151import org.openstreetmap.josm.gui.MainApplication;
    5252import org.openstreetmap.josm.gui.SideButton;
     53import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     54import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    5355import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5456import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    6365 * @since 94
    6466 */
    65 public class CommandStackDialog extends ToggleDialog implements CommandQueuePreciseListener {
     67public class CommandStackDialog extends ToggleDialog implements CommandQueuePreciseListener, ActiveLayerChangeListener {
    6668
    6769    private final DefaultTreeModel undoTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
     
    145147        InputMapUtils.addEnterAction(undoTree, selectAndZoomAction);
    146148        InputMapUtils.addEnterAction(redoTree, selectAndZoomAction);
     149        MainApplication.getLayerManager().addActiveLayerChangeListener(this);
    147150    }
    148151
     
    553556        }
    554557    }
     558
     559    @Override
     560    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     561        hideNotify();
     562        showNotify();
     563    }
    555564}
Note: See TracChangeset for help on using the changeset viewer.