15
|
1 // This file (SetNameCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
|
|
2 //
|
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
|
|
4
|
0
|
5 using System;
|
|
6 using IBBoard.Commands;
|
|
7 using IBBoard.WarFoundry.API.Objects;
|
|
8
|
|
9 namespace IBBoard.WarFoundry.API.Commands
|
|
10 {
|
|
11 /// <summary>
|
|
12 /// Summary description for SetNameCommand.
|
|
13 /// </summary>
|
|
14 public class SetNameCommand : Command
|
|
15 {
|
|
16 private WarFoundryObject obj;
|
|
17 private string newName, oldName;
|
|
18
|
|
19 public SetNameCommand(WarFoundryObject toRename, string name)
|
|
20 {
|
|
21 obj = toRename;
|
|
22 newName = name;
|
|
23 oldName = obj.Name;
|
|
24 }
|
|
25
|
|
26 public override bool CanExecute()
|
|
27 {
|
|
28 return (obj!=null && newName!=null && newName!="");
|
|
29 }
|
|
30
|
|
31 public override string Description
|
|
32 {
|
|
33 get { return "Rename "+oldName; }
|
|
34 }
|
|
35
|
|
36 public override string UndoDescription
|
|
37 {
|
|
38 get { return "Revert name of "+newName; }
|
|
39 }
|
|
40
|
|
41 public override bool Execute()
|
|
42 {
|
|
43 this.Redo();
|
|
44 return true;
|
|
45 }
|
|
46
|
|
47 public override void Redo()
|
|
48 {
|
|
49 obj.Name = newName;
|
|
50 }
|
|
51
|
|
52 public override void Undo()
|
|
53 {
|
|
54 obj.Name = oldName;
|
|
55 }
|
|
56
|
|
57 public override string Name
|
|
58 {
|
|
59 get { return "Rename item"; }
|
|
60 }
|
|
61 }
|
|
62 }
|