Ticket #17268: clear_ignored_errors_v8.patch
| File clear_ignored_errors_v8.patch, 7.8 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/OsmValidator.java
12 12 import java.nio.file.Files; 13 13 import java.nio.file.Path; 14 14 import java.nio.file.Paths; 15 import java.nio.file.StandardCopyOption; 15 16 import java.util.ArrayList; 16 17 import java.util.Arrays; 17 18 import java.util.Collection; … … 241 242 } 242 243 243 244 /** 245 * Get the list of all ignored errors 246 * @return The <code>Collection<String></code> of errors that are ignored 247 */ 248 public static Collection<String> getIgnoredErrors() { 249 return ignoredErrors; 250 } 251 252 /** 253 * Reset the error list by deleting ignorederrors 254 */ 255 public static void resetErrorList() { 256 saveIgnoredErrors(); 257 File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); 258 if (!ignoredErrors.isFile()) return; 259 File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); 260 try { 261 Files.move(ignoredErrors.toPath(), ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); 262 } catch (IOException e) { 263 ignoredErrors.delete(); 264 } 265 OsmValidator.initialize(); 266 } 267 268 /** 269 * Restore the error list by copying ignorederrors.bak to ignorederrors 270 */ 271 public static void restoreErrorList() { 272 saveIgnoredErrors(); 273 File ignoredErrors = new File(OsmValidator.getValidatorDir(), "ignorederrors"); 274 File ignoredErrorsBak = new File(ignoredErrors.getAbsolutePath() + ".bak"); 275 if (!ignoredErrors.isFile() || !ignoredErrorsBak.isFile()) return; 276 File ignoredErrorsBak2 = new File(ignoredErrorsBak.getAbsolutePath() + "2"); 277 try { 278 Files.move(ignoredErrors.toPath(), 279 ignoredErrorsBak2.toPath(), 280 StandardCopyOption.REPLACE_EXISTING); 281 if (ignoredErrorsBak.isFile()) { 282 Files.move(ignoredErrorsBak.toPath(), 283 ignoredErrors.toPath(), StandardCopyOption.REPLACE_EXISTING); 284 } 285 Files.move(ignoredErrorsBak2.toPath(), 286 ignoredErrorsBak.toPath(), StandardCopyOption.REPLACE_EXISTING); 287 } catch (IOException e) { 288 Logging.debug(e); 289 } 290 OsmValidator.initialize(); 291 } 292 293 /** 244 294 * Saves the names of the ignored errors to a file 245 295 */ 246 296 public static void saveIgnoredErrors() { -
src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 8 import java.awt.event.MouseEvent; 9 import java.io.File; 9 10 import java.io.IOException; 10 11 import java.lang.reflect.InvocationTargetException; 11 12 import java.util.ArrayList; … … 46 47 import org.openstreetmap.josm.data.validation.OsmValidator; 47 48 import org.openstreetmap.josm.data.validation.TestError; 48 49 import org.openstreetmap.josm.data.validation.ValidatorVisitor; 50 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 49 51 import org.openstreetmap.josm.gui.MainApplication; 50 52 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 51 53 import org.openstreetmap.josm.gui.PopupMenuHandler; … … 85 87 private final SideButton fixButton; 86 88 /** The ignore button */ 87 89 private final SideButton ignoreButton; 90 /** The reset ignorelist button */ 91 private final SideButton resetignorelistButton; 88 92 /** The select button */ 89 93 private final SideButton selectButton; 90 94 /** The lookup button */ … … 174 178 }); 175 179 ignoreButton.setEnabled(false); 176 180 buttons.add(ignoreButton); 181 resetignorelistButton = new SideButton(new AbstractAction() { 182 int reset = 0; 183 { 184 toggle(); 185 } 186 187 public void toggle() { 188 this.setEnabled(true); 189 if (!OsmValidator.getIgnoredErrors().isEmpty()) { 190 putValue(NAME, tr("Clear Ignore")); 191 putValue(SHORT_DESCRIPTION, tr("Clear ignore list")); 192 new ImageProvider("dialogs", "fix").getResource().attachImageIcon(this, true); 193 reset = 1; 194 } else { 195 File ignoredErrors = new File(OsmValidator.getValidatorDir()); 196 ignoredErrors = new File(ignoredErrors.getAbsolutePath() + File.separator + "ignorederrors.bak"); 197 if (ignoredErrors.isFile()) { 198 putValue(NAME, tr("Restore Ignore")); 199 putValue(SHORT_DESCRIPTION, tr("Restore ignore list")); 200 new ImageProvider("copy").getResource().attachImageIcon(this, true); 201 reset = 2; 202 } else if (!OsmValidator.getIgnoredErrors().isEmpty()) { 203 putValue(NAME, tr("Save Ignore")); 204 putValue(SHORT_DESCRIPTION, tr("Save ignore list")); 205 new ImageProvider("save").getResource().attachImageIcon(this, true); 206 reset = 3; 207 } else { 208 putValue(NAME, tr("Ignore list modification")); 209 putValue(SHORT_DESCRIPTION, tr("Clear/Restore/Save the ignore list, depending upon various conditions")); 210 new ImageProvider("dialogs", "validator").getResource().attachImageIcon(this, true); 211 //this.setEnabled(false); // TODO enable when I figure out how to call from ignore 212 } 213 } 214 } 215 216 @Override 217 public void actionPerformed(ActionEvent e) { 218 if (reset == 1) { 219 OsmValidator.resetErrorList(); 220 } else if (reset == 2) { 221 OsmValidator.restoreErrorList(); 222 } else if (reset == 3 && !OsmValidator.getIgnoredErrors().isEmpty()) { 223 OsmValidator.saveIgnoredErrors(); 224 } else if (reset == 0) { 225 // Do nothing 226 } 227 if (reset == 1 || reset == 2) rerunValidatorPrompt(); 228 toggle(); 229 } 230 }); 231 buttons.add(resetignorelistButton); 177 232 } else { 178 233 ignoreButton = null; 234 resetignorelistButton = null; 179 235 } 236 180 237 createLayout(tree, true, buttons); 181 238 } 182 239 … … 285 342 } 286 343 287 344 /** 345 * Prompt to rerun the validator when the ignore list changes 346 */ 347 public void rerunValidatorPrompt() { 348 if (!validateAction.isEnabled()) return; 349 final int answer = ConditionalOptionPaneUtil.showOptionDialog( 350 "rerun_validation_when_ignorelist_changed", 351 MainApplication.getMainFrame(), 352 "<hmtl><h3>" + tr("Should the validation be rerun?") + "</h3></html>", 353 tr("Ignored error filter changed"), 354 JOptionPane.YES_NO_CANCEL_OPTION, 355 JOptionPane.QUESTION_MESSAGE, 356 null, 357 null); 358 if (answer == JOptionPane.YES_OPTION) { 359 validateAction.doValidate(true); 360 } 361 } 362 363 /** 288 364 * Sets the selection of the map to the current selected items. 289 365 */ 290 366 @SuppressWarnings("unchecked")
