first stage of undo/redo functionality -- there are still a number of actions that...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / SetTagKeyAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class SetTagKeyAction extends UndoableEntityAction {
6         private var oldKey:String;
7         private var newKey:String;
8         
9         public function SetTagKeyAction(entity:Entity, oldKey:String, newKey:String) {
10             super(entity, "Rename tag "+oldKey+"->"+newKey);
11             this.oldKey = oldKey;
12             this.newKey = newKey;
13         }
14             
15         public override function doAction():uint {
16             var tags:Object = entity.getTagsHash();
17             var value:String = tags[oldKey];
18             if ( oldKey != newKey ) {
19                 delete tags[oldKey];
20                 tags[newKey] = value;
21                 markDirty();
22                 entity.dispatchEvent(new TagEvent(Connection.TAG_CHANGED, entity, oldKey, newKey, value, value));
23                 return SUCCESS;
24             } else {
25                 return NO_CHANGE;
26             }
27         }
28             
29         public override function undoAction():uint {
30             var tags:Object = entity.getTagsHash();
31             var value:String = tags[newKey];
32             delete tags[newKey];
33             tags[oldKey] = value;
34             markClean();
35             entity.dispatchEvent(new TagEvent(Connection.TAG_CHANGED, entity, newKey, oldKey, value, value));
36             
37             return SUCCESS;
38         }
39     }
40 }
41