diff api/Commands/SetNameCommand.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 306558904c2a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/api/Commands/SetNameCommand.cs	Fri Dec 19 15:57:51 2008 +0000
@@ -0,0 +1,58 @@
+using System;
+using IBBoard.Commands;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Commands
+{
+	/// <summary>
+	/// Summary description for SetNameCommand.
+	/// </summary>
+	public class SetNameCommand : Command
+	{
+		private WarFoundryObject obj;
+		private string newName, oldName;
+
+		public SetNameCommand(WarFoundryObject toRename, string name)
+		{
+			obj = toRename;
+			newName = name;
+			oldName = obj.Name;
+		}
+
+		public override bool CanExecute()
+		{
+			return (obj!=null && newName!=null && newName!="");
+		}
+
+		public override string Description
+		{
+			get { return "Rename "+oldName; }
+		}
+
+		public override string UndoDescription
+		{
+			get { return "Revert name of "+newName; }
+		}
+
+		public override bool Execute()
+		{
+			this.Redo();
+			return true;
+		}
+
+		public override void Redo()
+		{
+			obj.Name = newName;
+		}
+
+		public override void Undo()
+		{
+			obj.Name = oldName;
+		}
+
+		public override string Name
+		{
+			get { return "Rename item"; }
+		}
+	}
+}