Ignore:
Timestamp:
2015-11-02T20:27:07+01:00 (4 years ago)
Author:
simon04
Message:

fix #9491 - Ask before moving nodes that are attached to ways fully hidden by filters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r8931 r8977  
    5454import org.openstreetmap.josm.tools.Pair;
    5555import org.openstreetmap.josm.tools.Shortcut;
     56import org.openstreetmap.josm.tools.Utils;
    5657
    5758/**
     
    810811
    811812    /**
    812      * Present warning in case of large and possibly unwanted movements and undo
    813      * unwanted movements.
     813     * Present warning in the following cases and undo unwanted movements: <ul>
     814     * <li>large and possibly unwanted movements</li>
     815     * <li>movement of node with attached ways that are hidden by filters</li>
     816     * </ul>
    814817     *
    815818     * @param e the mouse event causing the action (mouse released)
    816819     */
    817820    private void confirmOrUndoMovement(MouseEvent e) {
     821        if (movesHiddenWay()) {
     822            final ExtendedDialog ed = new ConfirmMoveDialog();
     823            ed.setContent(tr("Are you sure that you want to move elements with attached ways that are hidden by filters?"));
     824            ed.toggleEnable("movedHiddenElements");
     825            ed.showDialog();
     826            if (ed.getValue() != 1) {
     827                Main.main.undoRedo.undo();
     828            }
     829        }
    818830        int max = Main.pref.getInteger("warn.move.maxelements", 20), limit = max;
    819831        for (OsmPrimitive osm : getCurrentDataSet().getSelected()) {
     
    826838        }
    827839        if (limit < 0) {
    828             ExtendedDialog ed = new ExtendedDialog(
    829                     Main.parent,
    830                     tr("Move elements"),
    831                     new String[]{tr("Move them"), tr("Undo move")});
    832             ed.setButtonIcons(new String[]{"reorder", "cancel"});
     840            final ExtendedDialog ed = new ConfirmMoveDialog();
    833841            ed.setContent(
    834842                    /* for correct i18n of plural forms - see #9110 */
     
    836844                        "You moved more than {0} elements. " + "Moving a large number of elements is often an error.\n" + "Really move them?",
    837845                        max, max));
    838             ed.setCancelButton(2);
    839846            ed.toggleEnable("movedManyElements");
    840847            ed.showDialog();
     
    849856        }
    850857        getCurrentDataSet().fireSelectionChanged();
     858    }
     859
     860    static class ConfirmMoveDialog extends ExtendedDialog {
     861        public ConfirmMoveDialog() {
     862            super(Main.parent,
     863                    tr("Move elements"),
     864                    new String[]{tr("Move them"), tr("Undo move")});
     865            setButtonIcons(new String[]{"reorder", "cancel"});
     866            setCancelButton(2);
     867
     868        }
     869    }
     870
     871    private boolean movesHiddenWay() {
     872        final Collection<OsmPrimitive> elementsToTest = new HashSet<>(getCurrentDataSet().getSelected());
     873        for (Way osm : Utils.filteredCollection(getCurrentDataSet().getSelected(), Way.class)) {
     874            elementsToTest.addAll(osm.getNodes());
     875        }
     876        for (OsmPrimitive node : Utils.filteredCollection(elementsToTest, Node.class)) {
     877            for (Way ref : Utils.filteredCollection(node.getReferrers(), Way.class)) {
     878                if (ref.isDisabledAndHidden()) {
     879                    return true;
     880                }
     881            }
     882        }
     883        return false;
    851884    }
    852885
Note: See TracChangeset for help on using the changeset viewer.