| | 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); |
| | 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 | /** |