| 1 | // License: GPL. For details, see LICENSE file. |
| 2 | package org.openstreetmap.josm.actions; |
| 3 | |
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht; |
| 5 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 6 | |
| 7 | import java.awt.Dimension; |
| 8 | import java.awt.event.ActionEvent; |
| 9 | import java.awt.event.KeyEvent; |
| 10 | import java.io.File; |
| 11 | import java.io.IOException; |
| 12 | import java.nio.charset.StandardCharsets; |
| 13 | import java.nio.file.Files; |
| 14 | import java.nio.file.Paths; |
| 15 | import java.util.List; |
| 16 | |
| 17 | import org.openstreetmap.josm.gui.ExtendedDialog; |
| 18 | import org.openstreetmap.josm.gui.MainApplication; |
| 19 | import org.openstreetmap.josm.gui.bugreport.DebugTextDisplay; |
| 20 | import org.openstreetmap.josm.gui.util.GuiHelper; |
| 21 | import org.openstreetmap.josm.spi.preferences.Config; |
| 22 | import org.openstreetmap.josm.tools.Shortcut; |
| 23 | |
| 24 | /** |
| 25 | * Resets the ignored errors list |
| 26 | * |
| 27 | * @author Taylor Smock |
| 28 | */ |
| 29 | public 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 | } |