Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@ public override Type ComponentType {
get { return _xamlObject.ElementType; }
}

void SetNameInternal(string newName)
{
_xamlObject.Name = newName;
}

public override string Name {
get { return _xamlObject.Name; }
set { _xamlObject.Name = value; }
set {
UndoService undoService = this.Services.GetService<UndoService>();
if (undoService != null)
undoService.Execute(new SetNameAction(this, value));
else
SetNameInternal(value);
}
}

public override string Key {
Expand Down Expand Up @@ -174,5 +185,52 @@ public override DesignItem Clone()
}
return item;
}

sealed class SetNameAction : ITransactionItem
{
XamlDesignItem designItem;
string oldName;
string newName;

public SetNameAction(XamlDesignItem designItem, string newName)
{
this.designItem = designItem;
this.newName = newName;

oldName = designItem.Name;
}

public string Title {
get {
return "Set name";
}
}

public void Do()
{
designItem.SetNameInternal(newName);
}

public void Undo()
{
designItem.SetNameInternal(oldName);
}

public System.Collections.Generic.ICollection<DesignItem> AffectedElements {
get {
return new DesignItem[] { designItem };
}
}

public bool MergeWith(ITransactionItem other)
{
SetNameAction o = other as SetNameAction;
if (o != null && designItem == o.designItem) {
newName = o.newName;
return true;
}
return false;
}
}
}
}