Ticket #17268: clear_ignored_errors_v3.patch

File clear_ignored_errors_v3.patch, 5.8 KB (added by taylor.smock, 7 years ago)

Move the buttons and logic to the Validation Results pane. It (still) does not ask for confirmation, but I don't think it is necessary at this point (it toggles between save/restore until a new ignore is added).

  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    241241    }
    242242
    243243    /**
     244     * Get the list of all ignored errors
     245     * @return The <code>Collection<String></code> of errors that are ignored
     246     */
     247    public static Collection<String> getIgnoredErrors() {
     248        return ignoredErrors;
     249    }
     250
     251    /**
    244252     * Saves the names of the ignored errors to a file
    245253     */
    246254    public static void saveIgnoredErrors() {
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

     
    66import java.awt.event.ActionEvent;
    77import java.awt.event.KeyEvent;
    88import java.awt.event.MouseEvent;
     9import java.io.File;
    910import java.io.IOException;
    1011import java.lang.reflect.InvocationTargetException;
     12import java.nio.file.Files;
     13import java.nio.file.StandardCopyOption;
    1114import java.util.ArrayList;
    1215import java.util.Collection;
    1316import java.util.Enumeration;
     
    8588    private final SideButton fixButton;
    8689    /** The ignore button */
    8790    private final SideButton ignoreButton;
     91    /** The reset ignorelist button */
     92    private final SideButton resetignorelistButton;
    8893    /** The select button */
    8994    private final SideButton selectButton;
    9095    /** The lookup button */
     
    177182        } else {
    178183            ignoreButton = null;
    179184        }
     185
     186        resetignorelistButton = new SideButton(new AbstractAction() {
     187            int reset = 0;
     188            {
     189                toggle();
     190            }
     191            public void toggle() {
     192                if (OsmValidator.getIgnoredErrors().size() > 0) {
     193                    putValue(NAME, tr("Reset Ignore"));
     194                    putValue(SHORT_DESCRIPTION, tr("Reset the ignore list"));
     195                    new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true);
     196                    reset = 1;
     197                    this.setEnabled(true);
     198                } else {
     199                    File ignoredErrors = new File(Config.getDirs().getUserDataDirectory(true), "validator");
     200                    ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors.bak");
     201                    if (ignoredErrors.isFile()) {
     202                        putValue(NAME, tr("Restore Ignore"));
     203                        putValue(SHORT_DESCRIPTION, tr("Restore the ignore list"));
     204                        new ImageProvider("dialogs", "copy").getResource().attachImageIcon(this, true);
     205                        reset = -1;
     206                        this.setEnabled(true);
     207                    } else {
     208                        this.setEnabled(false);
     209                    }
     210                }
     211            }
     212            @Override
     213            public void actionPerformed(ActionEvent e) {
     214                if (reset == 1) {
     215                    resetErrorList();
     216                } else if (reset == -1) {
     217                    restoreErrorList();
     218                } else if (reset == 0) {
     219                    // Do nothing
     220                }
     221                toggle();
     222            }
     223        });
     224        buttons.add(resetignorelistButton);
    180225        createLayout(tree, true, buttons);
    181226    }
    182227
     
    285330    }
    286331
    287332    /**
     333     * Reset the error list by deleting ignorederrors
     334     */
     335    public void resetErrorList() {
     336        OsmValidator.saveIgnoredErrors();
     337        File ignoredErrors = new File(Config.getDirs().getUserDataDirectory(true), "validator");
     338        ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors");
     339        if (!ignoredErrors.isFile()) return;
     340        File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak");
     341        try {
     342            Files.move(ignoredErrors.toPath(), ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING);
     343        } catch (IOException e) {
     344            System.out.println(tr("We couldn''t save ignorederrors"));
     345            ignoredErrors.delete();
     346        }
     347        OsmValidator.initialize();
     348    }
     349
     350    /**
     351     * Restore the error list by copying ignorederrors.bak to ignorederrors
     352     */
     353    public void restoreErrorList() {
     354        OsmValidator.saveIgnoredErrors();
     355        File ignoredErrors = new File(Config.getDirs().getUserDataDirectory(true), "validator");
     356        ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors");
     357        if (!ignoredErrors.isFile()) return;
     358        File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak");
     359        File ignoredErrorsBak2 = new File(ignoredErrorsBak.getAbsolutePath() + "2");
     360        try {
     361            Files.move(ignoredErrors.toPath(),
     362                    ignoredErrorsBak2.toPath(),
     363                    StandardCopyOption.REPLACE_EXISTING);
     364            if (ignoredErrorsBak.isFile()) {
     365                Files.move(ignoredErrorsBak.toPath(),
     366                        ignoredErrors.toPath(), StandardCopyOption.REPLACE_EXISTING);
     367            }
     368            Files.move(ignoredErrorsBak2.toPath(),
     369                    ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING);
     370        } catch (IOException e) {
     371            System.out.println(tr("We were unable to restore ignorederrors"));
     372            e.printStackTrace();
     373        }
     374        OsmValidator.initialize();
     375    }
     376
     377    /**
    288378     * Sets the selection of the map to the current selected items.
    289379     */
    290380    @SuppressWarnings("unchecked")