| | 186 | |
| | 187 | resetignorelistButton = new SideButton(new AbstractAction() { |
| | 188 | int reset = 0; |
| | 189 | { |
| | 190 | toggle(); |
| | 191 | } |
| | 192 | |
| | 193 | public void toggle() { |
| | 194 | this.setEnabled(true); |
| | 195 | if (!OsmValidator.getIgnoredErrors().isEmpty()) { |
| | 196 | putValue(NAME, tr("Clear Ignore")); |
| | 197 | putValue(SHORT_DESCRIPTION, tr("Clear ignore list")); |
| | 198 | new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); |
| | 199 | reset = 1; |
| | 200 | } else { |
| | 201 | File ignoredErrors = new File(OsmValidator.getValidatorDir()); |
| | 202 | ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors.bak"); |
| | 203 | if (ignoredErrors.isFile()) { |
| | 204 | putValue(NAME, tr("Restore Ignore")); |
| | 205 | putValue(SHORT_DESCRIPTION, tr("Restore ignore list")); |
| | 206 | new ImageProvider("copy").getResource().attachImageIcon(this, true); |
| | 207 | reset = 2; |
| | 208 | } else if (!OsmValidator.getIgnoredErrors().isEmpty()) { |
| | 209 | putValue(NAME, tr("Save Ignore")); |
| | 210 | putValue(SHORT_DESCRIPTION, tr("Save ignore list")); |
| | 211 | new ImageProvider("save").getResource().attachImageIcon(this, true); |
| | 212 | reset = 3; |
| | 213 | } else { |
| | 214 | putValue(NAME, tr("Ignore list modification")); |
| | 215 | putValue(SHORT_DESCRIPTION, tr("Clear/Restore/Save the ignore list, depending upon various conditions")); |
| | 216 | new ImageProvider("dialogs", "validator").getResource().attachImageIcon(this, true); |
| | 217 | //this.setEnabled(false); // TODO enable when I figure out how to call from ignore |
| | 218 | } |
| | 219 | } |
| | 220 | } |
| | 221 | |
| | 222 | @Override |
| | 223 | public void actionPerformed(ActionEvent e) { |
| | 224 | if (reset == 1) { |
| | 225 | resetErrorList(); |
| | 226 | } else if (reset == 2) { |
| | 227 | restoreErrorList(); |
| | 228 | } else if (reset == 3 && !OsmValidator.getIgnoredErrors().isEmpty()) { |
| | 229 | OsmValidator.saveIgnoredErrors(); |
| | 230 | } else if (reset == 0) { |
| | 231 | // Do nothing |
| | 232 | } |
| | 233 | toggle(); |
| | 234 | } |
| | 235 | }); |
| | 236 | buttons.add(resetignorelistButton); |
| | 345 | * Reset the error list by deleting ignorederrors |
| | 346 | */ |
| | 347 | public void resetErrorList() { |
| | 348 | OsmValidator.saveIgnoredErrors(); |
| | 349 | File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); |
| | 350 | if (!ignoredErrors.isFile()) return; |
| | 351 | File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); |
| | 352 | try { |
| | 353 | Files.move(ignoredErrors.toPath(), ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | 354 | } catch (IOException e) { |
| | 355 | ignoredErrors.delete(); |
| | 356 | } |
| | 357 | OsmValidator.initialize(); |
| | 358 | } |
| | 359 | |
| | 360 | /** |
| | 361 | * Restore the error list by copying ignorederrors.bak to ignorederrors |
| | 362 | */ |
| | 363 | public void restoreErrorList() { |
| | 364 | OsmValidator.saveIgnoredErrors(); |
| | 365 | File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); |
| | 366 | File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); |
| | 367 | if (!ignoredErrors.isFile() || !ignoredErrorsBak.isFile()) return; |
| | 368 | File ignoredErrorsBak2 = new File(ignoredErrorsBak.getAbsolutePath() + "2"); |
| | 369 | try { |
| | 370 | Files.move(ignoredErrors.toPath(), |
| | 371 | ignoredErrorsBak2.toPath(), |
| | 372 | StandardCopyOption.REPLACE_EXISTING); |
| | 373 | if (ignoredErrorsBak.isFile()) { |
| | 374 | Files.move(ignoredErrorsBak.toPath(), |
| | 375 | ignoredErrors.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | 376 | } |
| | 377 | Files.move(ignoredErrorsBak2.toPath(), |
| | 378 | ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | 379 | } catch (IOException e) { |
| | 380 | Logging.debug(e); |
| | 381 | } |
| | 382 | OsmValidator.initialize(); |
| | 383 | } |
| | 384 | |
| | 385 | /** |