change relation.appendMember to use the undo system, and update various places as...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / SetTagAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class SetTagAction extends UndoableEntityAction {
6         private var oldValue:String;
7         private var key:String;
8         private var value:String;
9         
10         public function SetTagAction(entity:Entity, key:String, value:String) {
11             super(entity, "Set "+key+"="+value);
12             this.key = key;
13             this.value = value;
14         }
15             
16         public override function doAction():uint {
17             var tags:Object = entity.getTagsHash();
18             oldValue = tags[key];
19             if ( oldValue != value ) {
20                 if ( value == null || value == "" )
21                     delete tags[key];
22                 else
23                     tags[key] = value;
24                 markDirty();
25                 entity.dispatchEvent(new TagEvent(Connection.TAG_CHANGED, entity, key, key, oldValue, value));
26                 return SUCCESS;
27             } else {
28                 return NO_CHANGE;
29             }
30         }
31             
32         public override function undoAction():uint {
33             var tags:Object = entity.getTagsHash();
34             if ( oldValue == null || oldValue == "" )
35                 delete tags[key];
36             else
37                 tags[key] = oldValue;
38             markClean();
39             entity.dispatchEvent(new TagEvent(Connection.TAG_CHANGED, entity, key, key, value, oldValue));
40             
41             return SUCCESS;
42         }
43         
44         public override function mergePrevious(prev:UndoableAction):Boolean {
45             if ( !(prev is SetTagAction) )
46                 return false;
47                 
48             var prevSet:SetTagAction = prev as SetTagAction;
49             if ( prevSet.entity == entity && prevSet.key == key ) {
50                 oldValue = prevSet.oldValue;
51                 return true;
52             }
53             return false;
54         }
55     }
56 }
57