Changeset 35842 in osm


Ignore:
Timestamp:
2021-11-02T07:40:02+01:00 (3 years ago)
Author:
GerdP
Message:

fix #21491: Split Object (Alt+X) action sometimes adds multiple commands to stack
If multiple commands were generated, combine them into a single "Split Object" command

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java

    r35841 r35842  
    9090        List<Relation> selectedRelations = new ArrayList<>(ds.getSelectedRelations());
    9191
    92         Relation selectedMultipolygon = null;
    9392        Way selectedWay = null;
    9493        Way splitWay = null;
     
    119118
    120119        if ((selectedRelations.size() == 1) && selectedRelations.get(0).isMultipolygon()) {
    121             selectedMultipolygon = selectedRelations.get(0);
    122         }
    123 
    124         if (selectedMultipolygon != null) {
     120            Relation selectedMultipolygon = selectedRelations.get(0);
    125121            if (splitWay == null) {
    126122                showWarningNotification(tr("Splitting multipolygons requires a split way to be selected"));
     
    261257            SplitWayCommand result = SplitWayCommand.splitWay(
    262258                    selectedWay, wayChunks, Collections.<OsmPrimitive>emptyList());
    263             UndoRedoHandler.getInstance().add(result);
    264             if (splitWay != null)
    265                 UndoRedoHandler.getInstance().add(new DeleteCommand(splitWay));
     259            if (splitWay != null) {
     260                result.executeCommand();
     261                DeleteCommand delCmd = new DeleteCommand(splitWay);
     262                delCmd.executeCommand();
     263                UndoRedoHandler.getInstance().add(new SplitObjectCommand(Arrays.asList(result, delCmd)), false);
     264            } else {
     265                UndoRedoHandler.getInstance().add(result);
     266            }
    266267            getLayerManager().getEditDataSet().setSelected(result.getNewSelection());
    267268        }
     269
    268270    }
    269271
     
    326328                }
    327329            }
    328 
    329             for (Command mpSplitCommand : commands) {
    330                 UndoRedoHandler.getInstance().add(mpSplitCommand, false);
    331             }
     330            if (commands.size() > 1)
     331                UndoRedoHandler.getInstance().add(new SplitObjectCommand(commands), false);
     332            else
     333                UndoRedoHandler.getInstance().add(commands.iterator().next(), false);
    332334
    333335            mpRelation.getDataSet().setSelected(mpRelations);
     
    501503                mpCreationCommands.add(new ChangeMembersCommand(mpRelation, mpMembers));
    502504                mpCreationCommands.add(new AddCommand(mpRelation.getDataSet(), newMpRelation));
    503 
    504                 SequenceCommand sequenceCommand = new SequenceCommand(mpRelation.getDataSet(), "Split Multipolygon", mpCreationCommands, false);
    505                 sequenceCommand.executeCommand();
    506                 commands.add(sequenceCommand);
     505                mpCreationCommands.forEach(Command::executeCommand);
     506                commands.addAll(mpCreationCommands);
    507507
    508508                mpRelations.add(newMpRelation);
     
    595595        .setIcon(JOptionPane.WARNING_MESSAGE).show();
    596596    }
     597
     598    private static class SplitObjectCommand extends SequenceCommand {
     599        SplitObjectCommand(Collection<Command> sequenz) {
     600            super(tr("Split Object"), sequenz, true);
     601            setSequenceComplete(true);
     602        }
     603    }
    597604}
Note: See TracChangeset for help on using the changeset viewer.