Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Commands/SetNameCommand.cs @ 232:f5009a00a50d
Re #236: Handle null game system in race
* Fix error message text
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 24 Dec 2009 14:57:32 +0000 |
parents | 391446c9b250 |
children | 650bbe79b884 |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
1 // This file (SetNameCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
15 | 4 |
82 | 5 using System; |
0 | 6 using IBBoard.Commands; |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
7 using IBBoard.Lang; |
82 | 8 using IBBoard.WarFoundry.API.Objects; |
9 | |
10 namespace IBBoard.WarFoundry.API.Commands | |
11 { | |
12 /// <summary> | |
13 /// Summary description for SetNameCommand. | |
14 /// </summary> | |
15 public class SetNameCommand : Command | |
16 { | |
17 private WarFoundryObject obj; | |
18 private string newName, oldName; | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
19 private string description; |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
20 private string undoDescription; |
82 | 21 |
22 public SetNameCommand(WarFoundryObject toRename, string name) | |
23 { | |
24 obj = toRename; | |
25 newName = name; | |
26 oldName = obj.Name; | |
27 } | |
28 | |
29 public override bool CanExecute() | |
30 { | |
31 return (obj!=null && newName!=null && newName!=""); | |
32 } | |
33 | |
34 public override string Description | |
35 { | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
36 get |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
37 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
38 if (description == null) |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
39 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
40 description = Translation.GetTranslation("setUnitNameCommandDescription", "rename \"{0}\" to \"{1}\"", oldName, newName); |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
41 } |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
42 |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
43 return description; |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
44 } |
82 | 45 } |
46 | |
47 public override string UndoDescription | |
48 { | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
49 get |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
50 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
51 if (undoDescription == null) |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
52 { |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
53 undoDescription = Translation.GetTranslation("setUnitNameCommandUndoDescription", "rename \"{0}\" to \"{1}\"", newName, oldName); |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
54 } |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
55 |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
56 return undoDescription; |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
57 } |
82 | 58 } |
59 | |
60 public override bool Execute() | |
61 { | |
62 this.Redo(); | |
63 return true; | |
64 } | |
65 | |
66 public override void Redo() | |
67 { | |
68 obj.Name = newName; | |
69 } | |
70 | |
71 public override void Undo() | |
72 { | |
73 obj.Name = oldName; | |
74 } | |
75 | |
76 public override string Name | |
77 { | |
78 get { return "Rename item"; } | |
79 } | |
80 } | |
81 } |