Changeset 9387 in josm


Ignore:
Timestamp:
2016-01-10T14:29:30+01:00 (4 years ago)
Author:
simon04
Message:

fix #12304 - Show notification about relations when unglueing

File:
1 edited

Legend:

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

    r9315 r9387  
    3737import org.openstreetmap.josm.data.osm.RelationMember;
    3838import org.openstreetmap.josm.data.osm.Way;
     39import org.openstreetmap.josm.gui.DefaultNameFormatter;
    3940import org.openstreetmap.josm.gui.ExtendedDialog;
    4041import org.openstreetmap.josm.gui.MapView;
     
    7879    @Override
    7980    public void actionPerformed(ActionEvent e) {
     81        try {
     82            unglue(e);
     83        } catch (UserCancelException ignore) {
     84            Main.debug(ignore.getMessage());
     85        } finally {
     86            cleanup();
     87        }
     88    }
     89
     90    protected void unglue(ActionEvent e) throws UserCancelException {
    8091
    8192        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
     
    8495        int errorTime = Notification.TIME_DEFAULT;
    8596        if (checkSelectionOneNodeAtMostOneWay(selection)) {
    86             if (!checkAndConfirmOutlyingUnglue()) {
    87                 // FIXME: Leaving action without clearing selectedNode, selectedWay, selectedNodes
    88                 return;
    89             }
     97            checkAndConfirmOutlyingUnglue();
    9098            int count = 0;
    9199            for (Way w : OsmPrimitive.getFilteredList(selectedNode.getReferrers(), Way.class)) {
     
    115123            }
    116124        } else if (checkSelectionOneWayAnyNodes(selection)) {
    117             if (!checkAndConfirmOutlyingUnglue()) {
    118                 // FIXME: Leaving action without clearing selectedNode, selectedWay, selectedNodes
    119                 return;
    120             }
     125            checkAndConfirmOutlyingUnglue();
    121126            Set<Node> tmpNodes = new HashSet<>();
    122127            for (Node n : selectedNodes) {
     
    167172                    .show();
    168173        }
    169 
     174    }
     175
     176    private void cleanup() {
    170177        selectedNode = null;
    171178        selectedWay = null;
     
    535542                cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes)));
    536543            }
     544            notifyWayPartOfRelation(parentWays);
    537545        } else {
    538546            cmds.add(new ChangeCommand(selectedWay, modifyWay(selectedNode, selectedWay, cmds, newNodes)));
     547            notifyWayPartOfRelation(Collections.singleton(selectedWay));
    539548        }
    540549
     
    599608        }
    600609        cmds.add(new ChangeNodesCommand(way, newNodes));
     610        notifyWayPartOfRelation(Collections.singleton(way));
    601611        try {
    602612            final PropertiesMembershipDialog dialog = PropertiesMembershipDialog.showIfNecessary(Collections.singleton(selectedNode), false);
     
    637647        }
    638648        cmds.add(new ChangeCommand(selectedWay, tmpWay)); // only one changeCommand for a way, else garbage will happen
     649        notifyWayPartOfRelation(Collections.singleton(selectedWay));
    639650
    640651        Main.main.undoRedo.add(new SequenceCommand(
     
    658669    }
    659670
    660     protected boolean checkAndConfirmOutlyingUnglue() {
     671    protected void checkAndConfirmOutlyingUnglue() throws UserCancelException {
    661672        List<OsmPrimitive> primitives = new ArrayList<>(2 + (selectedNodes == null ? 0 : selectedNodes.size()));
    662673        if (selectedNodes != null)
     
    664675        if (selectedNode != null)
    665676            primitives.add(selectedNode);
    666         return Command.checkAndConfirmOutlyingOperation("unglue",
     677        final boolean ok = Command.checkAndConfirmOutlyingOperation("unglue",
    667678                tr("Unglue confirmation"),
    668679                tr("You are about to unglue nodes outside of the area you have downloaded."
     
    676687                        + "<br>" + "Do you really want to unglue?"),
    677688                primitives, null);
     689        if (!ok) {
     690            throw new UserCancelException();
     691        }
     692    }
     693
     694    protected void notifyWayPartOfRelation(final Iterable<Way> ways) {
     695        final Set<String> affectedRelations = new HashSet<>();
     696        for (Way way : ways) {
     697            for (OsmPrimitive ref : way.getReferrers()) {
     698                if (ref instanceof Relation && ref.isUsable()) {
     699                    affectedRelations.add((ref.getDisplayName(DefaultNameFormatter.getInstance())));
     700                }
     701            }
     702        }
     703        final String msg1 = trn("Unglueing affected {0} relation: {1}", "Unglueing affected {0} relations: {1}",
     704                affectedRelations.size(), affectedRelations.size(), Utils.joinAsHtmlUnorderedList(affectedRelations));
     705        final String msg2 = trn("Ensure that the relation has not been broken!", "Ensure that the relations have not been broken!",
     706                affectedRelations.size());
     707        new Notification("<html>" + msg1 + msg2).setIcon(JOptionPane.WARNING_MESSAGE).show();
    678708    }
    679709}
Note: See TracChangeset for help on using the changeset viewer.