Changeset 16303 in josm for trunk/src


Ignore:
Timestamp:
2020-04-15T11:38:48+02:00 (5 years ago)
Author:
GerdP
Message:

see #18670: fix error introduced with r16300
Ungluing an unconnected tagged node (e.g. natural=tree) caused exception instead of "not glued to anything" message

File:
1 edited

Legend:

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

    r16300 r16303  
    109109                // If there aren't enough ways, maybe the user wanted to unglue the nodes
    110110                // (= copy tags to a new node)
    111                 if (!selfCrossing) {
    112                     if (selection.size() == 1 && selectedNode.isTagged()) {
     111                if (!selfCrossing)
     112                    if (checkForUnglueNode(selection)) {
    113113                        unglueOneNodeAtMostOneWay(e);
    114114                    } else {
     
    116116                        errMsg = tr("This node is not glued to anything else.");
    117117                    }
    118                 }
    119118            } else {
    120119                // and then do the work.
     
    244243        getLayerManager().getEditDataSet().setSelected(moveSelectedNode ? selectedNode : unglued);
    245244        mv.repaint();
     245    }
     246
     247    /**
     248     * Checks if selection is suitable for ungluing. This is the case when there's a single,
     249     * tagged node selected that's part of at least one way (ungluing an unconnected node does
     250     * not make sense. Due to the call order in actionPerformed, this is only called when the
     251     * node is only part of one or less ways.
     252     *
     253     * @param selection The selection to check against
     254     * @return {@code true} if selection is suitable
     255     */
     256    private boolean checkForUnglueNode(Collection<? extends OsmPrimitive> selection) {
     257        if (selection.size() != 1)
     258            return false;
     259        OsmPrimitive n = (OsmPrimitive) selection.toArray()[0];
     260        if (!(n instanceof Node))
     261            return false;
     262        if (((Node) n).getParentWays().isEmpty())
     263            return false;
     264
     265        selectedNode = (Node) n;
     266        return selectedNode.isTagged();
    246267    }
    247268
Note: See TracChangeset for help on using the changeset viewer.