add undo for creating stuff
[potlatch2.git] / net / systemeD / halcyon / connection / actions / CreateEntityAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class CreateEntityAction extends UndoableEntityAction {
6         private var setCreate:Function;
7         private var deleteAction:UndoableAction;
8         
9         public function CreateEntityAction(entity:Entity, setCreate:Function) {
10             super(entity, "Create");
11             this.setCreate = setCreate;
12         }
13             
14         public override function doAction():uint {
15             if ( deleteAction != null ) {
16                 deleteAction.undoAction();
17             } else {
18                 setCreate(entity, false);
19             }
20             
21             return SUCCESS;
22         }
23             
24         public override function undoAction():uint {
25             if ( deleteAction == null ) {
26                 entity.remove(setAction);
27             }
28             deleteAction.doAction();
29             
30             return SUCCESS;
31         }
32         
33         private function setAction(action:UndoableAction):void {
34             deleteAction = action;
35         }
36     }
37 }
38