- Timestamp:
- 2019-03-06T10:17:24+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r14381 r14845 284 284 * Executes the command and add it to the intern command queue. 285 285 * @param c The command to execute. Must not be {@code null}. 286 */ 287 public void addNoRedraw(final Command c) { 286 * @param execute true: Execute, else it is assumed that the command was already executed 287 */ 288 public void addNoRedraw(final Command c, boolean execute) { 288 289 CheckParameterUtil.ensureParameterNotNull(c, "c"); 289 c.executeCommand(); 290 if (execute) { 291 c.executeCommand(); 292 } 290 293 commands.add(c); 291 294 // Limit the number of commands in the undo list. … … 325 328 326 329 /** 330 * Executes the command only if wanted and add it to the intern command queue. 331 * @param c The command to execute. Must not be {@code null}. 332 * @param execute true: Execute, else it is assumed that the command was already executed 333 */ 334 public void add(final Command c, boolean execute) { 335 addNoRedraw(c, execute); 336 afterAdd(c); 337 338 } 339 340 /** 327 341 * Executes the command and add it to the intern command queue. 328 342 * @param c The command to execute. Must not be {@code null}. 329 343 */ 330 344 public synchronized void add(final Command c) { 331 addNoRedraw(c );345 addNoRedraw(c, true); 332 346 afterAdd(c); 333 347 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r14836 r14845 35 35 import org.openstreetmap.josm.actions.relation.EditRelationAction; 36 36 import org.openstreetmap.josm.command.Command; 37 import org.openstreetmap.josm.command.SequenceCommand; 37 38 import org.openstreetmap.josm.data.UndoRedoHandler; 38 39 import org.openstreetmap.josm.data.osm.DataSelectionListener; … … 604 605 protected void fixError(TestError error) throws InterruptedException, InvocationTargetException { 605 606 if (error.isFixable()) { 606 final Command fixCommand = error.getFix(); 607 if (fixCommand != null) { 608 SwingUtilities.invokeAndWait(() -> UndoRedoHandler.getInstance().addNoRedraw(fixCommand)); 609 fixCommands.add(fixCommand); 607 if (error.getPrimitives().stream().noneMatch(OsmPrimitive::isDeleted)) { 608 final Command fixCommand = error.getFix(); 609 if (fixCommand != null) { 610 SwingUtilities.invokeAndWait(fixCommand::executeCommand); 611 fixCommands.add(fixCommand); 612 } 610 613 } 611 614 // It is wanted to ignore an error if it said fixable, even if fixCommand was null … … 638 641 monitor.subTask(tr("Updating map ...")); 639 642 SwingUtilities.invokeAndWait(() -> { 640 UndoRedoHandler.getInstance().afterAdd(fixCommands); 643 if (!fixCommands.isEmpty()) { 644 UndoRedoHandler.getInstance().add( 645 fixCommands.size() > 1 ? new AutofixCommand(fixCommands) : fixCommands.get(0), false); 646 } 641 647 invalidateValidatorLayers(); 642 648 tree.resetErrors(); 643 649 }); 644 } catch (InterruptedException | InvocationTargetException e) { 650 } catch (InterruptedException e) { 651 tryUndo(); 652 throw new JosmRuntimeException(e); 653 } catch (InvocationTargetException e) { 645 654 // FIXME: signature of realRun should have a generic checked exception we could throw here 646 655 throw new JosmRuntimeException(e); 647 656 } finally { 657 if (monitor.isCanceled()) { 658 tryUndo(); 659 } 648 660 monitor.finishTask(); 649 661 } 650 662 } 663 664 /** 665 * Undo commands as they were not yet added to the UndoRedo Handler 666 */ 667 private void tryUndo() { 668 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 669 int i = fixCommands.size() - 1; 670 ds.beginUpdate(); 671 for (; i >= 0; i--) { 672 fixCommands.get(i).undoCommand(); 673 } 674 ds.endUpdate(); 675 } 676 651 677 } 652 678 … … 663 689 super.destroy(); 664 690 } 691 692 private class AutofixCommand extends SequenceCommand { 693 AutofixCommand(Collection<Command> sequenz) { 694 super(tr("auto-fixed validator issues"), sequenz, true); 695 setSequenceComplete(true); 696 } 697 698 @Override 699 public void undoCommand() { 700 getAffectedDataSet().beginUpdate(); 701 super.undoCommand(); 702 getAffectedDataSet().endUpdate(); 703 } 704 705 @Override 706 public boolean executeCommand() { 707 getAffectedDataSet().beginUpdate(); 708 boolean rc = super.executeCommand(); 709 getAffectedDataSet().endUpdate(); 710 return rc; 711 } 712 } 665 713 }
Note:
See TracChangeset
for help on using the changeset viewer.