Ticket #17268: clear_ignored_errors.patch

File clear_ignored_errors.patch, 4.6 KB (added by taylor.smock, 6 years ago)
  • src/org/openstreetmap/josm/actions/ResetValidationIgnoreList.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions;
     3
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
     7import java.awt.Dimension;
     8import java.awt.event.ActionEvent;
     9import java.awt.event.KeyEvent;
     10import java.io.File;
     11import java.io.IOException;
     12import java.nio.charset.StandardCharsets;
     13import java.nio.file.Files;
     14import java.nio.file.Paths;
     15import java.util.List;
     16
     17import org.openstreetmap.josm.gui.ExtendedDialog;
     18import org.openstreetmap.josm.gui.MainApplication;
     19import org.openstreetmap.josm.gui.bugreport.DebugTextDisplay;
     20import org.openstreetmap.josm.gui.util.GuiHelper;
     21import org.openstreetmap.josm.spi.preferences.Config;
     22import org.openstreetmap.josm.tools.Shortcut;
     23
     24/**
     25 * Resets the ignored errors list
     26 *
     27 * @author Taylor Smock
     28 */
     29public class ResetValidationIgnoreList extends JosmAction {
     30
     31    /**
     32     * Constructs a new {@code ResetValidationIgnoreList}
     33     */
     34    public ResetValidationIgnoreList() {
     35        super(
     36                tr("Reset ignored errors list"),
     37                "fix",
     38                tr("Reset the ignored errors list"),
     39                Shortcut.registerShortcut("help:resetignorrederrors", tr("Help: {0}",
     40                        tr("Reset ignored errors")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false);
     41
     42        setHelpId(ht("/Action/ResetValidationIgnoreList"));
     43        putValue("toolbar", "help/resetvalidationignorelist");
     44        MainApplication.getToolbar().register(this);
     45    }
     46
     47    @Override
     48    public void actionPerformed(ActionEvent e) {
     49        StringBuilder text = new StringBuilder();
     50        File ignoredErrors = new File(Config.getDirs().getUserDataDirectory(true), "validator");
     51        ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors");
     52        try {
     53            List<String> lines = Files.readAllLines(Paths.get(ignoredErrors.getAbsolutePath()), StandardCharsets.UTF_8);
     54            for (String line : lines) {
     55                text.append(line);
     56                text.append(System.lineSeparator());
     57            }
     58            ignoredErrors.delete();
     59        } catch (IOException e1) {
     60            e1.printStackTrace();
     61            text.append(tr("There was no ignored errors file"));
     62        }
     63
     64        DebugTextDisplay ta = new DebugTextDisplay(text.toString());
     65        ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(),
     66                tr("Ignored Errors list for Validation has been reset"),
     67                tr("Close"));
     68        ed.setButtonIcons("cancel");
     69        ed.setContent(ta, false);
     70        ed.setMinimumSize(new Dimension(380, 200));
     71        ed.setPreferredSize(new Dimension(700, MainApplication.getMainFrame().getHeight()-50));
     72        switch (ed.showDialog().getValue()) {
     73            default:
     74        }
     75    GuiHelper.destroyComponents(ed, false);
     76    }
     77
     78}
  • src/org/openstreetmap/josm/gui/MainMenu.java

     
    8282import org.openstreetmap.josm.actions.RedoAction;
    8383import org.openstreetmap.josm.actions.ReorderImageryLayersAction;
    8484import org.openstreetmap.josm.actions.ReportBugAction;
     85import org.openstreetmap.josm.actions.ResetValidationIgnoreList;
    8586import org.openstreetmap.josm.actions.RestartAction;
    8687import org.openstreetmap.josm.actions.ReverseWayAction;
    8788import org.openstreetmap.josm.actions.SaveAction;
     
    317318    public final AboutAction about = new AboutAction();
    318319    /** Help / Show Status Report */
    319320    public final ShowStatusReportAction statusreport = new ShowStatusReportAction();
     321    /** Help / Reset validation ignore list */
     322    public final ResetValidationIgnoreList resetignore = new ResetValidationIgnoreList();
    320323    /** Help / Report bug */
    321324    public final ReportBugAction reportbug = new ReportBugAction();
    322325
     
    834837        add(helpMenu, new MenuItemSearchDialog.Action());
    835838        helpMenu.addSeparator();
    836839        add(helpMenu, statusreport);
     840        add(helpMenu, resetignore);
    837841        add(helpMenu, reportbug);
    838842        helpMenu.addSeparator();
    839843