Ignore:
Timestamp:
2016-11-13T14:49:39+01:00 (7 years ago)
Author:
Don-vip
Message:

see #10387 - refactor actions to fix taginfo script

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

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

    r11240 r11252  
    760760            return;
    761761        case 1:
    762             Main.main.undoRedo.add(cmds.getFirst());
     762            commitCommand(cmds.getFirst());
    763763            break;
    764764        default:
    765             Command c = new SequenceCommand(tr(description), cmds);
    766             Main.main.undoRedo.add(c);
     765            commitCommand(new SequenceCommand(tr(description), cmds));
    767766            break;
    768767        }
     
    770769        cmds.clear();
    771770        cmdsCount++;
     771    }
     772
     773    private static void commitCommand(Command c) {
     774        if (Main.main != null) {
     775            Main.main.undoRedo.add(c);
     776        } else {
     777            c.executeCommand();
     778        }
    772779    }
    773780
     
    12791286            if (!way.insideToTheRight) {
    12801287                ReverseWayResult res = ReverseWayAction.reverseWay(way.way);
    1281                 Main.main.undoRedo.add(res.getReverseCommand());
     1288                commitCommand(res.getReverseCommand());
    12821289                cmdsCount++;
    12831290            }
     
    12861293        Pair<Way, Command> result = CombineWayAction.combineWaysWorker(actionWays);
    12871294
    1288         Main.main.undoRedo.add(result.b);
     1295        commitCommand(result.b);
    12891296        cmdsCount++;
    12901297
     
    15361543     */
    15371544    private void makeCommitsOneAction(String message) {
    1538         UndoRedoHandler ur = Main.main.undoRedo;
    15391545        cmds.clear();
    1540         int i = Math.max(ur.commands.size() - cmdsCount, 0);
    1541         for (; i < ur.commands.size(); i++) {
    1542             cmds.add(ur.commands.get(i));
    1543         }
    1544 
    1545         for (i = 0; i < cmds.size(); i++) {
    1546             ur.undo();
     1546        if (Main.main != null) {
     1547            UndoRedoHandler ur = Main.main.undoRedo;
     1548            int i = Math.max(ur.commands.size() - cmdsCount, 0);
     1549            for (; i < ur.commands.size(); i++) {
     1550                cmds.add(ur.commands.get(i));
     1551            }
     1552
     1553            for (i = 0; i < cmds.size(); i++) {
     1554                ur.undo();
     1555            }
    15471556        }
    15481557
  • trunk/src/org/openstreetmap/josm/actions/PurgeAction.java

    r11240 r11252  
    7272    protected transient OsmDataLayer layer;
    7373    protected JCheckBox cbClearUndoRedo;
     74    protected boolean modified;
    7475
    7576    protected transient Set<OsmPrimitive> toPurge;
     
    9394            return;
    9495
    95         doPurge(getLayerManager().getEditDataSet().getAllSelected(), true);
    96     }
    97 
    98     /**
    99      * Performs purge on selected OSM primitives.
     96        PurgeCommand cmd = getPurgeCommand(getLayerManager().getEditDataSet().getAllSelected());
     97        boolean clearUndoRedo = false;
     98
     99        if (!GraphicsEnvironment.isHeadless()) {
     100            final boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
     101                    "purge", Main.parent, buildPanel(modified), tr("Confirm Purging"),
     102                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION);
     103            if (!answer)
     104                return;
     105
     106            clearUndoRedo = cbClearUndoRedo.isSelected();
     107            Main.pref.put("purge.clear_undo_redo", clearUndoRedo);
     108        }
     109
     110        Main.main.undoRedo.add(cmd);
     111        if (clearUndoRedo) {
     112            Main.main.undoRedo.clean();
     113            getLayerManager().getEditDataSet().clearSelectionHistory();
     114        }
     115    }
     116
     117    /**
     118     * Creates command to purge selected OSM primitives.
    100119     * @param sel selected OSM primitives
    101      * @param confirm asks user confirmation through a popup dialog
    102      * @since 11240
    103      */
    104     public void doPurge(Collection<OsmPrimitive> sel, boolean confirm) {
     120     * @return command to purge selected OSM primitives
     121     * @since 11252
     122     */
     123    public PurgeCommand getPurgeCommand(Collection<OsmPrimitive> sel) {
    105124        layer = Main.getLayerManager().getEditLayer();
    106125
     
    204223        }
    205224
    206         boolean modified = false;
     225        modified = false;
    207226        for (OsmPrimitive osm : toPurgeChecked) {
    208227            if (osm.isModified()) {
     
    212231        }
    213232
    214         boolean clearUndoRedo = false;
    215 
    216         if (!GraphicsEnvironment.isHeadless() && confirm) {
    217             final boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    218                     "purge", Main.parent, buildPanel(modified), tr("Confirm Purging"),
    219                     JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION);
    220             if (!answer)
    221                 return;
    222 
    223             clearUndoRedo = cbClearUndoRedo.isSelected();
    224             Main.pref.put("purge.clear_undo_redo", clearUndoRedo);
    225         }
    226 
    227         Main.main.undoRedo.add(layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) :
    228             new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete));
    229 
    230         if (clearUndoRedo) {
    231             Main.main.undoRedo.clean();
    232             getLayerManager().getEditDataSet().clearSelectionHistory();
    233         }
     233        return layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) :
     234            new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete);
    234235    }
    235236
Note: See TracChangeset for help on using the changeset viewer.