Ticket #7239: multijoin.diff

File multijoin.diff, 3.1 KB (added by *Martin*, 13 years ago)

the patch

  • src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

     
    3535    public void actionPerformed(ActionEvent e) {
    3636        if (!isEnabled())
    3737            return;
    38         Collection<Node> selectedNodes = getCurrentDataSet().getSelectedNodes();
    39         // Allow multiple selected nodes too?
    40         if (selectedNodes.size() != 1) return;
     38       
     39        Collection<Command> cmds2 = new LinkedList<Command>();
     40        for (Node node : getCurrentDataSet().getSelectedNodes()) {
    4141
    42         Node node = selectedNodes.iterator().next();
     42            Collection<Command> cmds = new LinkedList<Command>();
    4343
    44         Collection<Command> cmds = new LinkedList<Command>();
     44            // If the user has selected some ways, only join the node to these.
     45            boolean restrictToSelectedWays =
     46                getCurrentDataSet().getSelectedWays().size() > 0;
    4547
    46         // If the user has selected some ways, only join the node to these.
    47         boolean restrictToSelectedWays =
    48             getCurrentDataSet().getSelectedWays().size() > 0;
    49 
    5048            List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
    5149                    Main.map.mapView.getPoint(node), OsmPrimitive.isSelectablePredicate);
    5250            HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
     
    8684                wnew.setNodes(nodesToAdd);
    8785                cmds.add(new ChangeCommand(w, wnew));
    8886            }
    89             if (cmds.size() == 0) return;
    90             Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds));
    91             Main.map.repaint();
     87           
     88            if (!cmds.isEmpty()) {
     89                SequenceCommand sc = new SequenceCommand(tr("Join Node and Line Segment"), cmds) {
     90                    int state = 0;
     91                   
     92                    /*
     93                     * override it to prevent the re-execution on final Main.main.undoRedo.add
     94                     */
     95                    @Override
     96                    public boolean executeCommand() {
     97                        switch (state) {
     98                        case 0: // point A
     99                            state = 1;
     100                            return super.executeCommand();
     101                        case 1:
     102                            state = 2; // point B - skip the execution
     103                            return true;
     104                        default:
     105                            return super.executeCommand(); // redo execution point
     106                        }
     107                    }
     108                };
     109                sc.executeCommand(); // execute it so that next iteration work on modified data (reaches point A)
     110                cmds2.add(sc);
     111            }
     112        }
     113       
     114        Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds2)); // reaches point B
     115        Main.map.repaint();
    92116    }
    93117
    94118    private static void pruneSuccsAndReverse(List<Integer> is) {