private var setCreate:Function;
private var deleteAction:UndoableAction;
+ // This is a bit unusual, since we need to handle undo and specifically redo slightly differently
+ // When undo is called, instead of simply removing the entity, we work through
+ // to make a Delete[Entity]Action, call that, and store it for later
+ // Then, when this action is called again (i.e. a redo), instead of creating yet another entity, we call the deleteAction.undoAction
+
public function CreateEntityAction(entity:Entity, setCreate:Function) {
super(entity, "Create");
this.setCreate = setCreate;
}
public override function doAction():uint {
+ // check to see if this is the first pass - i.e. not a redo action.
+ // if it's redo (i.e. we've stored a deleteAction), undo the deletion
+ // if it's the first time, register the new entity with the connection
if ( deleteAction != null ) {
deleteAction.undoAction();
} else {
setCreate(entity, false);
}
- markDirty();
+ markDirty(); // if this is the first action taken, undoing it will then be able to clean the connection
return SUCCESS;
}
public override function undoAction():uint {
+ // if the undo is called for the first time, call for a deletion, and (via setAction) store the
+ // deletion action for later. We'll undo the deletion if we get asked to redo this action
if ( deleteAction == null ) {
entity.remove(setAction);
}
node.removeFromParents(effects.push);
effects.doAction();
setDeleted(true);
- markDirty();
+
+ // The Delete[entity]Action is unusual, since it can be called both to delete an entity, and is also used to undo its creation
+ // (hence preserving the negative id, if the creation is subsequently redone). Normally a deletion would mark the entity dirty, but
+ // if a newly created entity is being deleted, the entity is now clean.
+ // When the creation is "redone", it's actually an undo on the deletion of the new entity (see below),
+ // and so the connection will need to be considered dirty again. Usually it's an existing object that's deleted and restored,
+ // which would make things clean.
+ // See also CreateEntityAction
+
+ if (node.id < 0) {
+ markClean();
+ } else {
+ markDirty();
+ }
node.dispatchEvent(new EntityEvent(Connection.NODE_DELETED, node));
return SUCCESS;
}
public override function undoAction():uint {
+ var node:Node = entity as Node;
setDeleted(false);
- markClean();
+
+ // See note above
+ if (node.id < 0) {
+ markDirty();
+ } else {
+ markClean();
+ }
entity.dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
if ( effects != null )
effects.undoAction();
memberList.splice(0, memberList.length);
effects.doAction();
setDeleted(true);
- markDirty();
+
+ // see note in DeleteNodeAction
+ if (relation.id < 0) {
+ markClean();
+ } else {
+ markDirty();
+ }
relation.dispatchEvent(new EntityEvent(Connection.RELATION_DELETED, relation));
return SUCCESS;
public override function undoAction():uint {
var relation:Relation = entity as Relation;
setDeleted(false);
- markClean();
+ if (relation.id < 0) {
+ markDirty();
+ } else {
+ markClean();
+ }
relation.dispatchEvent(new EntityEvent(Connection.NEW_RELATION, relation));
effects.undoAction();
for each(var member:RelationMember in oldMemberList) {
}
effects.doAction();
setDeleted(true);
- markDirty();
+
+ // see note in DeleteNodeAction
+ if (way.id < 0) {
+ markClean();
+ } else {
+ markDirty();
+ }
way.dispatchEvent(new EntityEvent(Connection.WAY_DELETED, way));
way.resume();
var way:Way = entity as Way;
way.suspend();
setDeleted(false);
- markClean();
+ if (way.id < 0) {
+ markDirty();
+ } else {
+ markClean();
+ }
way.dispatchEvent(new EntityEvent(Connection.NEW_WAY, way));
effects.undoAction();
for each(var node:Node in oldNodeList) {