Ignore:
Timestamp:
2008-05-11T01:59:46+02:00 (16 years ago)
Author:
framm
Message:
  • make commands able to fail (patch by DH)
  • add Command.getOrig() (patch by DH)
  • add RemoveRelationMemberCommand (patch by DH)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r627 r630  
    1010import javax.swing.tree.MutableTreeNode;
    1111
     12import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1314
     
    2324         */
    2425        private Command[] sequence;
     26        private boolean sequence_complete;
    2527        private final String name;
     28        public boolean continueOnError = false;
    2629
    2730        /**
     
    4245        }
    4346       
    44         @Override public void executeCommand() {
    45                 for (Command c : sequence)
    46                         c.executeCommand();
     47        public int executed_commands = 0;
     48        @Override public boolean executeCommand() {
     49                for (int i=0; i < sequence.length; i++) {
     50                        Command c = sequence[i];
     51                        boolean result = c.executeCommand();
     52                        if (!result)
     53                                Main.debug("SequenceCommand, executing command[" + i + "] " +  c + " result: " + result);
     54                        if (!result && !continueOnError) {
     55                                this.undoCommands(i-1);
     56                                return false;
     57                        }
     58                }
     59                sequence_complete = true;
     60                return true;
     61        }
     62
     63        private void undoCommands(int start) {
     64                // We probably aborted this halfway though the
     65                // execution sequence because of a sub-command
     66                // error.  We already undid the sub-commands.
     67                if (!sequence_complete)
     68                        return;
     69                for (int i = start; i >= 0; --i)
     70                        sequence[i].undoCommand();
    4771        }
    4872
    4973        @Override public void undoCommand() {
    50                 for (int i = sequence.length-1; i >= 0; --i)
    51                         sequence[i].undoCommand();
     74                this.undoCommands(sequence.length-1);
    5275        }
    5376
Note: See TracChangeset for help on using the changeset viewer.