]> git.openstreetmap.org Git - potlatch2.git/blob - net/systemeD/halcyon/connection/actions/AddMemberToRelationAction.as
Bugfix - index can be -ve. Fixes problem with undo/redo leading to ever increasingly...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / AddMemberToRelationAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class AddMemberToRelationAction extends UndoableEntityAction {
6         private var rel:Relation;
7         private var index:int;
8         private var member:RelationMember;
9         private var memberList:Array;
10         
11         public function AddMemberToRelationAction(rel:Relation, index:int, member:RelationMember, memberList:Array) {
12             super(rel, "Add " + member.entity.getType() + " " + member.entity.id + " at position " + index + " to ");
13             this.rel = rel;
14             this.index = index;
15             this.member = member;
16             this.memberList = memberList;
17         }
18         
19         public override function doAction():uint {
20             memberList.splice(index, 0, member);
21             member.entity.addParent(rel);
22             markDirty();
23             rel.dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_ADDED, member.entity, rel, index));
24             
25             return SUCCESS;
26         }
27         
28         public override function undoAction():uint {
29             memberList.splice(index, 1);
30             member.entity.removeParent(rel);
31             markClean();
32             rel.dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_REMOVED, member.entity, rel, index));
33             
34             return SUCCESS;
35         }
36     }
37 }