Ticket #17196: 17196.patch

File 17196.patch, 2.8 KB (added by GerdP, 5 years ago)

Possible solution

  • src/org/openstreetmap/josm/data/UndoRedoHandler.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.util.EventObject;
    57import java.util.Iterator;
    68import java.util.LinkedList;
     
    79import java.util.List;
    810import java.util.Objects;
    911
     12import javax.swing.JOptionPane;
     13
    1014import org.openstreetmap.josm.command.Command;
    1115import org.openstreetmap.josm.data.osm.DataSet;
    1216import org.openstreetmap.josm.data.osm.OsmDataManager;
     17import org.openstreetmap.josm.gui.Notification;
    1318import org.openstreetmap.josm.gui.util.GuiHelper;
    1419import org.openstreetmap.josm.spi.preferences.Config;
    1520import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    348353            return;
    349354        GuiHelper.runInEDTAndWait(() -> {
    350355            DataSet ds = OsmDataManager.getInstance().getEditDataSet();
     356
    351357            if (ds != null) {
    352358                ds.beginUpdate();
    353359            }
     
    354360            try {
    355361                for (int i = 1; i <= num; ++i) {
    356362                    final Command c = commands.removeLast();
     363                    if (c.getAffectedDataSet() != ds) {
     364                        new Notification(tr("Cannot undo change in inactive data layer."))
     365                                .setIcon(JOptionPane.WARNING_MESSAGE).setDuration(Notification.TIME_SHORT).show();
     366                        commands.add(c);
     367                        break;
     368                    }
    357369                    c.undoCommand();
    358370                    redoCommands.addFirst(c);
    359371                    fireEvent(new CommandUndoneEvent(this, c));
     
    371383    }
    372384
    373385    /**
    374      * Redoes the last undoed command.
     386     * Redoes the last undone command.
    375387     */
    376388    public void redo() {
    377389        redo(1);
     
    384396    public synchronized void redo(int num) {
    385397        if (redoCommands.isEmpty())
    386398            return;
     399        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
     400
    387401        for (int i = 0; i < num; ++i) {
    388402            final Command c = redoCommands.removeFirst();
     403            if (c.getAffectedDataSet() != ds) {
     404                new Notification(tr("Cannot redo change in inactive data layer."))
     405                        .setIcon(JOptionPane.INFORMATION_MESSAGE).setDuration(Notification.TIME_SHORT).show();
     406                redoCommands.addFirst(c);
     407                break;
     408            }
    389409            c.executeCommand();
    390410            commands.add(c);
    391411            fireEvent(new CommandRedoneEvent(this, c));