Changeset 17399 in josm for trunk


Ignore:
Timestamp:
2020-12-09T08:27:45+01:00 (3 months ago)
Author:
GerdP
Message:

fix #20213: Command stack: Edits in relation editor are listed in wrong stack and lead to exception

  • revert changes for #17196, this approach was too simple because relation editor may save changes for an inactive edit layer
Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

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

    r17379 r17399  
    44import java.util.Collections;
    55import java.util.EventObject;
    6 import java.util.HashMap;
    76import java.util.LinkedList;
    87import java.util.List;
    9 import java.util.Map;
    108import java.util.Objects;
    119
     
    1311import org.openstreetmap.josm.data.osm.DataSet;
    1412import org.openstreetmap.josm.data.osm.OsmDataManager;
    15 import org.openstreetmap.josm.gui.MainApplication;
    16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1713import org.openstreetmap.josm.gui.util.GuiHelper;
    1814import org.openstreetmap.josm.spi.preferences.Config;
     
    4541
    4642    private static class InstanceHolder {
    47         static final UndoRedoHandler NO_DATA_SET_INSTANCE = new UndoRedoHandler();
    48         static final Map<DataSet, UndoRedoHandler> map = new HashMap<>();
    49 
     43        static final UndoRedoHandler INSTANCE = new UndoRedoHandler();
    5044    }
    5145
     
    5650     */
    5751    public static UndoRedoHandler getInstance() {
    58         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    59         if (editLayer != null && editLayer == MainApplication.getLayerManager().getActiveLayer()) {
    60             return InstanceHolder.map.computeIfAbsent(editLayer.data, k -> new UndoRedoHandler());
    61         }
    62         return InstanceHolder.NO_DATA_SET_INSTANCE;
     52        return InstanceHolder.INSTANCE;
    6353    }
    6454
     
    443433            l.commandChanged(commands.size(), redoCommands.size());
    444434        }
    445         if (getInstance() != InstanceHolder.NO_DATA_SET_INSTANCE) {
    446             for (final CommandQueueListener l : InstanceHolder.NO_DATA_SET_INSTANCE.listenerCommands) {
    447                 l.commandChanged(commands.size(), redoCommands.size());
    448             }
    449 
    450         }
    451435    }
    452436
     
    470454     * @since 12718
    471455     */
    472     public static synchronized void clean(DataSet dataSet) {
     456    public synchronized void clean(DataSet dataSet) {
    473457        if (dataSet == null)
    474458            return;
    475         UndoRedoHandler old = InstanceHolder.map.remove(dataSet);
    476         if (old != null) {
    477             old.clean();
     459        boolean changed = false;
     460        changed |= commands.removeIf(c -> c.getAffectedDataSet() == dataSet);
     461        changed |= redoCommands.removeIf(c -> c.getAffectedDataSet() == dataSet);
     462        if (changed) {
     463            fireEvent(new CommandQueueCleanedEvent(this, dataSet));
     464            fireCommandsChanged();
    478465        }
    479466    }
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r17390 r17399  
    222222            Layer layer = e.getRemovedLayer();
    223223            if (layer instanceof OsmDataLayer) {
    224                 UndoRedoHandler.clean(((OsmDataLayer) layer).getDataSet());
     224                UndoRedoHandler.getInstance().clean(((OsmDataLayer) layer).getDataSet());
    225225            }
    226226        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r17374 r17399  
    5151import org.openstreetmap.josm.gui.MainApplication;
    5252import org.openstreetmap.josm.gui.SideButton;
    53 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    54 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    5553import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5654import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    6563 * @since 94
    6664 */
    67 public class CommandStackDialog extends ToggleDialog implements CommandQueuePreciseListener, ActiveLayerChangeListener {
     65public class CommandStackDialog extends ToggleDialog implements CommandQueuePreciseListener {
    6866
    6967    private final DefaultTreeModel undoTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
     
    147145        InputMapUtils.addEnterAction(undoTree, selectAndZoomAction);
    148146        InputMapUtils.addEnterAction(redoTree, selectAndZoomAction);
    149         MainApplication.getLayerManager().addActiveLayerChangeListener(this);
    150147    }
    151148
     
    556553        }
    557554    }
    558 
    559     @Override
    560     public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    561         hideNotify();
    562         showNotify();
    563     }
    564555}
  • trunk/src/org/openstreetmap/josm/gui/io/AsynchronousUploadPrimitivesTask.java

    r17379 r17399  
    121121        GuiHelper.runInEDTAndWait(() -> {
    122122            // Remove the commands from the undo stack
    123             UndoRedoHandler.clean(uploadDataLayer.getDataSet());
     123            UndoRedoHandler.getInstance().clean(uploadDataLayer.getDataSet());
    124124            MainApplication.getLayerManager().prepareLayerForUpload(uploadDataLayer);
    125125
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r17379 r17399  
    654654            return;
    655655
    656         UndoRedoHandler.clean(data);
     656        UndoRedoHandler.getInstance().clean(data);
    657657
    658658        // if uploaded, clean the modified flags as well
Note: See TracChangeset for help on using the changeset viewer.