Ticket #20899: w-confirmMovement.patch

File w-confirmMovement.patch, 4.4 KB (added by ljdelight, 5 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    diff --git src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
    index c4895b556..2ab6d49a9 100644
    public class ImproveWayAccuracyAction extends MapMode implements DataSelectionLi  
    511511
    512512                UndoRedoHandler.getInstance().add(
    513513                        new MoveCommand(candidateNode, cursorEN.east() - nodeEN.east(), cursorEN.north() - nodeEN.north()));
     514
     515                SelectAction.checkCommandForLargeDistance(UndoRedoHandler.getInstance().getLastCommand());
    514516            }
    515517        }
    516518
  • src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    diff --git src/org/openstreetmap/josm/actions/mapmode/SelectAction.java src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
    index bd7e9c22f..6983b3d58 100644
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    837837            ed.toggleEnable("movedHiddenElements");
    838838            showConfirmMoveDialog(ed);
    839839        }
     840
    840841        final Command lastCommand = UndoRedoHandler.getInstance().getLastCommand();
    841842        if (lastCommand == null) {
    842843            Logging.warn("No command found in undo/redo history, skipping confirmOrUndoMovement");
    843844            return;
    844845        }
     846
     847        SelectAction.checkCommandForLargeDistance(lastCommand);
     848
    845849        final int moveCount = lastCommand.getParticipatingPrimitives().size();
    846         if (lastCommand instanceof MoveCommand) {
    847             final double moveDistance = ((MoveCommand) lastCommand).getDistance(n -> !n.isNew());
    848             if (Double.isFinite(moveDistance) && moveDistance > Config.getPref().getInt("warn.move.maxdistance", 200)) {
    849                 final ConfirmMoveDialog ed = new ConfirmMoveDialog();
    850                 ed.setContent(trn(
    851                         "You moved {0} element by a distance of {1}. "
    852                                 + "Moving elements by a large distance is often an error.\n" + "Really move them?",
    853                         "You moved {0} elements by a distance of {1}. "
    854                                 + "Moving elements by a large distance is often an error.\n" + "Really move them?",
    855                         moveCount, moveCount, SystemOfMeasurement.getSystemOfMeasurement().getDistText(moveDistance)));
    856                 ed.toggleEnable("movedLargeDistance");
    857                 showConfirmMoveDialog(ed);
    858             }
    859         }
    860         int max = Config.getPref().getInt("warn.move.maxelements", 20);
     850        final int max = Config.getPref().getInt("warn.move.maxelements", 20);
    861851        if (moveCount > max) {
    862852            final ConfirmMoveDialog ed = new ConfirmMoveDialog();
    863853            ed.setContent(
    public class SelectAction extends MapMode implements ModifierExListener, KeyPres  
    874864        }
    875865    }
    876866
    877     private void showConfirmMoveDialog(ConfirmMoveDialog ed) {
     867    static void checkCommandForLargeDistance(Command lastCommand) {
     868        final int moveCount = lastCommand.getParticipatingPrimitives().size();
     869        if (lastCommand instanceof MoveCommand) {
     870            final double moveDistance = ((MoveCommand) lastCommand).getDistance(n -> !n.isNew());
     871            if (Double.isFinite(moveDistance) && moveDistance > Config.getPref().getInt("warn.move.maxdistance", 200)) {
     872                final ConfirmMoveDialog ed = new ConfirmMoveDialog();
     873                ed.setContent(trn(
     874                        "You moved {0} element by a distance of {1}. "
     875                                + "Moving elements by a large distance is often an error.\n" + "Really move them?",
     876                        "You moved {0} elements by a distance of {1}. "
     877                                + "Moving elements by a large distance is often an error.\n" + "Really move them?",
     878                        moveCount, moveCount, SystemOfMeasurement.getSystemOfMeasurement().getDistText(moveDistance)));
     879                ed.toggleEnable("movedLargeDistance");
     880                showConfirmMoveDialog(ed);
     881            }
     882        }
     883    }
     884
     885    private static void showConfirmMoveDialog(ConfirmMoveDialog ed) {
    878886        if (ed.showDialog().getValue() != 1) {
    879887            UndoRedoHandler.getInstance().undo();
    880888        }