Ignore:
Timestamp:
2017-09-04T00:50:22+02:00 (7 years ago)
Author:
Don-vip
Message:

see #13036 - see #15229 - see #15182 - make Commands depends only on a DataSet, not a Layer. This removes a lot of GUI dependencies

File:
1 edited

Legend:

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

    r12691 r12718  
    1111import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    13 import org.openstreetmap.josm.gui.MainApplication;
    14 import org.openstreetmap.josm.gui.layer.Layer;
    15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
    17 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    19 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    20 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2113import org.openstreetmap.josm.tools.CheckParameterUtil;
    2214
    2315/**
    24  * This is the global undo/redo handler for all {@link OsmDataLayer}s.
     16 * This is the global undo/redo handler for all {@link DataSet}s.
    2517 * <p>
    26  * If you want to change a data layer, you can use {@link #add(Command)} to execute a command on it and make that command undoable.
     18 * If you want to change a data set, you can use {@link #add(Command)} to execute a command on it and make that command undoable.
    2719 */
    28 public class UndoRedoHandler implements LayerChangeListener {
     20public class UndoRedoHandler {
    2921
    3022    /**
     
    4537     */
    4638    public UndoRedoHandler() {
    47         MainApplication.getLayerManager().addLayerChangeListener(this);
     39        // Do nothing
     40    }
     41
     42    /**
     43     * A listener that gets notified of command queue (undo/redo) size changes.
     44     * @since 12718 (moved from {@code OsmDataLayer}
     45     */
     46    @FunctionalInterface
     47    public interface CommandQueueListener {
     48        /**
     49         * Notifies the listener about the new queue size
     50         * @param queueSize Undo stack size
     51         * @param redoSize Redo stack size
     52         */
     53        void commandChanged(int queueSize, int redoSize);
    4854    }
    4955
     
    9298        }
    9399        addNoRedraw(c);
    94         c.invalidateAffectedLayers();
    95100        afterAdd();
    96101
     
    125130                final Command c = commands.removeLast();
    126131                c.undoCommand();
    127                 c.invalidateAffectedLayers();
    128132                redoCommands.addFirst(c);
    129133                if (commands.isEmpty()) {
     
    161165            final Command c = redoCommands.removeFirst();
    162166            c.executeCommand();
    163             c.invalidateAffectedLayers();
    164167            commands.add(c);
    165168            if (redoCommands.isEmpty()) {
     
    197200
    198201    /**
    199      * Resets all commands that affect the given layer.
    200      * @param layer The layer that was affected.
    201      */
    202     public void clean(Layer layer) {
    203         if (layer == null)
     202     * Resets all commands that affect the given dataset.
     203     * @param dataSet The data set that was affected.
     204     * @since 12718
     205     */
     206    public void clean(DataSet dataSet) {
     207        if (dataSet == null)
    204208            return;
    205209        boolean changed = false;
    206210        for (Iterator<Command> it = commands.iterator(); it.hasNext();) {
    207             if (it.next().invalidBecauselayerRemoved(layer)) {
     211            if (it.next().getAffectedDataSet() == dataSet) {
    208212                it.remove();
    209213                changed = true;
     
    211215        }
    212216        for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) {
    213             if (it.next().invalidBecauselayerRemoved(layer)) {
     217            if (it.next().getAffectedDataSet() == dataSet) {
    214218                it.remove();
    215219                changed = true;
     
    219223            fireCommandsChanged();
    220224        }
    221     }
    222 
    223     @Override
    224     public void layerRemoving(LayerRemoveEvent e) {
    225         clean(e.getRemovedLayer());
    226     }
    227 
    228     @Override
    229     public void layerAdded(LayerAddEvent e) {
    230         // Do nothing
    231     }
    232 
    233     @Override
    234     public void layerOrderChanged(LayerOrderChangeEvent e) {
    235         // Do nothing
    236225    }
    237226
Note: See TracChangeset for help on using the changeset viewer.