Ignore:
Timestamp:
2019-04-12T08:02:04+02:00 (5 years ago)
Author:
gerdp
Message:

see #17540: created_by is not changed when reverting multiple changesets

Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/ReverterPlugin.java

    r34917 r34974  
    2525        JMenu historyMenu = MainApplication.getMenu().dataMenu;
    2626        MainMenu.add(historyMenu, new RevertChangesetAction());
    27         UploadAction.registerUploadHook(new ReverterUploadHook(this));
     27        UploadAction.registerUploadHook(new ReverterUploadHook(info));
    2828        new RemoteControl().addRequestHandler(RevertChangesetHandler.command, RevertChangesetHandler.class);
    2929    }
  • applications/editors/josm/plugins/reverter/src/reverter/ReverterUploadHook.java

    r34552 r34974  
    44import org.openstreetmap.josm.actions.upload.UploadHook;
    55import org.openstreetmap.josm.command.Command;
     6import org.openstreetmap.josm.command.SequenceCommand;
    67import org.openstreetmap.josm.data.APIDataSet;
    78import org.openstreetmap.josm.data.UndoRedoHandler;
    89import org.openstreetmap.josm.gui.MainApplication;
     10import org.openstreetmap.josm.plugins.PluginInformation;
    911
     12/**
     13 * Upload hook to add tag to new changeset.
     14 *
     15 */
    1016public class ReverterUploadHook implements UploadHook {
    11     String pluginString;
    12     public ReverterUploadHook(ReverterPlugin plugin) {
    13         pluginString = "reverter_plugin/" + plugin.getPluginInformation().version;
     17    final String pluginString;
     18
     19    /**
     20     * Create new {@link ReverterUploadHook}
     21     * @param info plugin information
     22     */
     23    public ReverterUploadHook(PluginInformation info) {
     24        pluginString = "reverter_plugin/" + info.version;
    1425    }
    1526
    1627    @Override
    1728    public boolean checkUpload(APIDataSet apiDataSet) {
    18         if (!ReverterPlugin.reverterUsed) return true;
    19         boolean hasRevertions = false;
    20         for (Command cmd : UndoRedoHandler.getInstance().commands) {
    21             if (cmd instanceof RevertChangesetCommand) {
    22                 hasRevertions = true;
    23                 break;
     29        if (ReverterPlugin.reverterUsed) {
     30            for (Command cmd : UndoRedoHandler.getInstance().commands) {
     31                if (isReverterCmd(cmd)) {
     32                    MainApplication.getLayerManager().getEditDataSet().addChangeSetTag("created_by", pluginString);
     33                    break;
     34                }
    2435            }
    25         }
    26 
    27         if (hasRevertions) {
    28             MainApplication.getLayerManager().getEditDataSet().addChangeSetTag("created_by", "reverter");
    2936        }
    3037        return true;
    3138    }
    3239
     40    private static boolean isReverterCmd(Command cmd) {
     41        if (cmd instanceof RevertChangesetCommand)
     42            return true;
     43        if (cmd instanceof SequenceCommand) {
     44            return ((SequenceCommand) cmd).getLastCommand() instanceof RevertChangesetCommand;
     45        }
     46        return false;
     47    }
    3348}
Note: See TracChangeset for help on using the changeset viewer.