Ticket #17401: 17401-v6.patch

File 17401-v6.patch, 4.2 KB (added by GerdP, 7 years ago)
  • src/org/openstreetmap/josm/data/UndoRedoHandler.java

     
    283283    /**
    284284     * Executes the command and add it to the intern command queue.
    285285     * @param c The command to execute. Must not be {@code null}.
     286     * @param execute true: Execute, else it is assumed that the command was already executed
    286287     */
    287     public void addNoRedraw(final Command c) {
     288    public void addNoRedraw(final Command c, boolean execute) {
    288289        CheckParameterUtil.ensureParameterNotNull(c, "c");
    289         c.executeCommand();
     290        if (execute) {
     291            c.executeCommand();
     292        }
    290293        commands.add(c);
    291294        // Limit the number of commands in the undo list.
    292295        // Currently you have to undo the commands one by one. If
     
    324327    }
    325328
    326329    /**
     330     * Executes the command only if wanted and add it to the intern command queue.
     331     * @param c The command to execute. Must not be {@code null}.
     332     * @param execute true: Execute, else it is assumed that the command was already executed
     333     */
     334    public void add(final Command c, boolean execute) {
     335        addNoRedraw(c, execute);
     336        afterAdd(c);
     337
     338    }
     339
     340    /**
    327341     * Executes the command and add it to the intern command queue.
    328342     * @param c The command to execute. Must not be {@code null}.
    329343     */
    330344    public synchronized void add(final Command c) {
    331         addNoRedraw(c);
     345        addNoRedraw(c, true);
    332346        afterAdd(c);
    333347    }
    334348
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

     
    3434import org.openstreetmap.josm.actions.ValidateAction;
    3535import org.openstreetmap.josm.actions.relation.EditRelationAction;
    3636import org.openstreetmap.josm.command.Command;
     37import org.openstreetmap.josm.command.SequenceCommand;
    3738import org.openstreetmap.josm.data.UndoRedoHandler;
    3839import org.openstreetmap.josm.data.osm.DataSelectionListener;
    3940import org.openstreetmap.josm.data.osm.DataSet;
     
    603604
    604605        protected void fixError(TestError error) throws InterruptedException, InvocationTargetException {
    605606            if (error.isFixable()) {
    606                 final Command fixCommand = error.getFix();
    607                 if (fixCommand != null) {
    608                     SwingUtilities.invokeAndWait(() -> UndoRedoHandler.getInstance().addNoRedraw(fixCommand));
    609                     fixCommands.add(fixCommand);
     607                if (error.getPrimitives().stream().noneMatch(OsmPrimitive::isDeleted)) {
     608                    final Command fixCommand = error.getFix();
     609                    if (fixCommand != null) {
     610                        SwingUtilities.invokeAndWait(() -> fixCommand.executeCommand());
     611                        fixCommands.add(fixCommand);
     612                    }
    610613                }
    611614                // It is wanted to ignore an error if it said fixable, even if fixCommand was null
    612615                // This is to fix #5764 and #5773:
     
    637640                }
    638641                monitor.subTask(tr("Updating map ..."));
    639642                SwingUtilities.invokeAndWait(() -> {
    640                     UndoRedoHandler.getInstance().afterAdd(fixCommands);
     643                    if (!fixCommands.isEmpty()) {
     644                        UndoRedoHandler.getInstance().add(
     645                                fixCommands.size() > 1 ? new AutofixCommand(fixCommands) : fixCommands.get(0), false);
     646                    }
    641647                    invalidateValidatorLayers();
    642648                    tree.resetErrors();
    643649                });
     
    662668        }
    663669        super.destroy();
    664670    }
     671
     672    private class AutofixCommand extends SequenceCommand {
     673        AutofixCommand(Collection<Command> sequenz) {
     674            super(tr("auto-fixed validator issues"), sequenz, true);
     675            setSequenceComplete(true);
     676        }
     677    }
    665678}