Changeset 14281 in josm for trunk/src


Ignore:
Timestamp:
2018-09-30T00:46:01+02:00 (6 years ago)
Author:
Don-vip
Message:

see #12726 - accessors for undo/redo commands

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

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

    r14143 r14281  
    569569            if (addUndoRedo) {
    570570                UndoRedoHandler.getInstance().undo();
    571                 UndoRedoHandler.getInstance().redoCommands.clear();
     571                UndoRedoHandler.getInstance().getRedoCommands().clear();
    572572            }
    573573        }
     
    16011601        if (addUndoRedo) {
    16021602            UndoRedoHandler ur = UndoRedoHandler.getInstance();
    1603             int i = Math.max(ur.commands.size() - cmdsCount, 0);
    1604             for (; i < ur.commands.size(); i++) {
    1605                 cmds.add(ur.commands.get(i));
     1603            List<Command> commands = ur.getUndoCommands();
     1604            int i = Math.max(commands.size() - cmdsCount, 0);
     1605            for (; i < commands.size(); i++) {
     1606                cmds.add(commands.get(i));
    16061607            }
    16071608
  • trunk/src/org/openstreetmap/josm/actions/RedoAction.java

    r14143 r14281  
    4242    @Override
    4343    protected void updateEnabledState() {
    44         setEnabled(!UndoRedoHandler.getInstance().redoCommands.isEmpty());
     44        setEnabled(UndoRedoHandler.getInstance().hasRedoCommands());
    4545    }
    4646
    4747    @Override
    4848    public void commandChanged(int queueSize, int redoSize) {
    49         if (UndoRedoHandler.getInstance().redoCommands.isEmpty()) {
     49        if (!UndoRedoHandler.getInstance().hasRedoCommands()) {
    5050            putValue(NAME, tr("Redo"));
    5151            setTooltip(tr("Redo the last undone action."));
     
    5353            putValue(NAME, tr("Redo ..."));
    5454            setTooltip(tr("Redo {0}",
    55                     UndoRedoHandler.getInstance().redoCommands.getFirst().getDescriptionText()));
     55                    UndoRedoHandler.getInstance().getRedoCommands().getFirst().getDescriptionText()));
    5656        }
    5757    }
  • trunk/src/org/openstreetmap/josm/actions/UndoAction.java

    r14143 r14281  
    4242    @Override
    4343    protected void updateEnabledState() {
    44         setEnabled(!UndoRedoHandler.getInstance().commands.isEmpty());
     44        setEnabled(UndoRedoHandler.getInstance().hasUndoCommands());
    4545    }
    4646
    4747    @Override
    4848    public void commandChanged(int queueSize, int redoSize) {
    49         if (UndoRedoHandler.getInstance().commands.isEmpty()) {
     49        if (!UndoRedoHandler.getInstance().hasUndoCommands()) {
    5050            putValue(NAME, tr("Undo"));
    5151            setTooltip(tr("Undo the last action."));
     
    5353            putValue(NAME, tr("Undo ..."));
    5454            setTooltip(tr("Undo {0}",
    55                     UndoRedoHandler.getInstance().commands.getLast().getDescriptionText()));
     55                    UndoRedoHandler.getInstance().getLastCommand().getDescriptionText()));
    5656        }
    5757    }
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r14220 r14281  
    2525     *
    2626     * @see #getLastCommand()
     27     * @see #getUndoCommands()
    2728     */
    2829    public final LinkedList<Command> commands = new LinkedList<>();
     30
    2931    /**
    3032     * The stack for redoing commands
     33
     34     * @see #getRedoCommands()
    3135     */
    3236    public final LinkedList<Command> redoCommands = new LinkedList<>();
     
    232236
    233237    /**
     238     * Returns all commands that were made on the dataset, that can be undone.
     239     * @return all commands that were made on the dataset, that can be undone
     240     * @since 14281
     241     */
     242    public LinkedList<Command> getUndoCommands() {
     243        return new LinkedList<>(commands);
     244    }
     245
     246    /**
     247     * Returns all commands that were made and undone on the dataset, that can be redone.
     248     * @return all commands that were made and undone on the dataset, that can be redone.
     249     * @since 14281
     250     */
     251    public LinkedList<Command> getRedoCommands() {
     252        return new LinkedList<>(redoCommands);
     253    }
     254
     255    /**
    234256     * Gets the last command that was executed on the command stack.
    235257     * @return That command or <code>null</code> if there is no such command.
     
    238260    public Command getLastCommand() {
    239261        return commands.peekLast();
     262    }
     263
     264    /**
     265     * Determines if commands can be undone.
     266     * @return {14281 true} if at least a command can be undone
     267     * @since xxx
     268     */
     269    public boolean hasUndoCommands() {
     270        return !commands.isEmpty();
     271    }
     272
     273    /**
     274     * Determines if commands can be redone.
     275     * @return {@code true} if at least a command can be redone
     276     * @since 14281
     277     */
     278    public boolean hasRedoCommands() {
     279        return !redoCommands.isEmpty();
    240280    }
    241281
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r14221 r14281  
    272272
    273273    private void buildUndoTree() {
    274         List<Command> undoCommands = UndoRedoHandler.getInstance().commands;
     274        List<Command> undoCommands = UndoRedoHandler.getInstance().getUndoCommands();
    275275        undoRoot = new DefaultMutableTreeNode();
    276276        for (int i = 0; i < undoCommands.size(); ++i) {
     
    281281
    282282    private void buildRedoTree() {
    283         List<Command> redoCommands = UndoRedoHandler.getInstance().redoCommands;
     283        List<Command> redoCommands = UndoRedoHandler.getInstance().getRedoCommands();
    284284        redoRoot = new DefaultMutableTreeNode();
    285285        for (int i = 0; i < redoCommands.size(); ++i) {
     
    290290
    291291    private void ensureTreesConsistency() {
    292         List<Command> undoCommands = UndoRedoHandler.getInstance().commands;
    293         List<Command> redoCommands = UndoRedoHandler.getInstance().redoCommands;
     292        List<Command> undoCommands = UndoRedoHandler.getInstance().getUndoCommands();
     293        List<Command> redoCommands = UndoRedoHandler.getInstance().getRedoCommands();
    294294        if (redoTreeModel.getChildCount(redoRoot) > 0) {
    295295            redoTree.scrollRowToVisible(0);
Note: See TracChangeset for help on using the changeset viewer.