Ticket #21491: 21491.patch

File 21491.patch, 3.6 KB (added by GerdP, 3 years ago)

create single "Split Object" command, no new I18N string

  • src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java

     
    8989        List<Way> selectedWays = new ArrayList<>(ds.getSelectedWays());
    9090        List<Relation> selectedRelations = new ArrayList<>(ds.getSelectedRelations());
    9191
    92         Relation selectedMultipolygon = null;
    9392        Way selectedWay = null;
    9493        Way splitWay = null;
    9594
     
    118117        }
    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"));
    127123                return;
     
    260256            }
    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
    270272    /**
     
    325327                    }
    326328                }
    327329            }
     330            if (commands.size() > 1)
     331                UndoRedoHandler.getInstance().add(new SplitObjectCommand(commands), false);
     332            else
     333                UndoRedoHandler.getInstance().add(commands.iterator().next(), false);
    328334
    329             for (Command mpSplitCommand : commands) {
    330                 UndoRedoHandler.getInstance().add(mpSplitCommand, false);
    331             }
    332 
    333335            mpRelation.getDataSet().setSelected(mpRelations);
    334336            return splitResult;
    335337
     
    500502                List<Command> mpCreationCommands = new ArrayList<>();
    501503                mpCreationCommands.add(new ChangeMembersCommand(mpRelation, mpMembers));
    502504                mpCreationCommands.add(new AddCommand(mpRelation.getDataSet(), newMpRelation));
     505                mpCreationCommands.forEach(Command::executeCommand);
     506                commands.addAll(mpCreationCommands);
    503507
    504                 SequenceCommand sequenceCommand = new SequenceCommand(mpRelation.getDataSet(), "Split Multipolygon", mpCreationCommands, false);
    505                 sequenceCommand.executeCommand();
    506                 commands.add(sequenceCommand);
    507 
    508508                mpRelations.add(newMpRelation);
    509509            }
    510510        }
     
    594594        new Notification(msg)
    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}