Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
annotate FrmArmyTree.cs @ 237:ea5cb50ebe5e
Fixes #384: Validation warnings don't get cleared when creating new armies
* Check whether army is valid when it changes (also means we validate on load as well as clearing on close)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Jan 2012 16:51:07 +0000 |
parents | c06d0865ff27 |
children | 2c3474d652e1 |
rev | line source |
---|---|
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
1 using System; |
190 | 2 using System.Collections.Generic; |
3 using System.ComponentModel; | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
4 using System.Data; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
5 using System.Drawing; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
6 using System.Text; |
190 | 7 using System.Windows.Forms; |
8 using IBBoard.Commands; | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
9 using IBBoard.WarFoundry.API.Objects; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
10 using IBBoard.WarFoundry.API; |
190 | 11 using IBBoard.Lang; |
12 using IBBoard.Windows.Forms.I18N; | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
13 using IBBoard.WarFoundry.API.Commands; |
190 | 14 using IBBoard.Windows.Forms; |
15 | |
16 namespace IBBoard.WarFoundry.GUI.WinForms | |
17 { | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
18 public partial class FrmArmyTree : IBBoard.Windows.Forms.IBBForm |
190 | 19 { |
20 private Dictionary<string, TreeNode> nodes; | |
21 private ObjectAddDelegate UnitAddedMethod; | |
22 private ObjectRemoveDelegate UnitRemovedMethod; | |
23 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod; | |
24 private CommandStack commandStack; | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
25 public GameSystem CurrentGameSystem |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
26 { |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
27 get { return WarFoundryCore.CurrentGameSystem; } |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
28 set { WarFoundryCore.CurrentGameSystem = value; } |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
29 } |
190 | 30 |
31 public FrmArmyTree(CommandStack cmdStack) | |
32 { | |
33 commandStack = cmdStack; | |
34 InitializeComponent(); | |
35 UnitAddedMethod = new ObjectAddDelegate(UnitAdded); | |
36 UnitRemovedMethod = new ObjectRemoveDelegate(UnitRemoved); | |
37 UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName); | |
38 ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName); | |
39 TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged); | |
40 nodes = new Dictionary<string, TreeNode>(); | |
222
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
41 this.Name = "ArmyTree"; |
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
42 miDeleteUnit.Name = "miDeleteUnit"; |
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
43 miEditUnit.Name = "miEditUnit"; |
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
44 miEditArmy.Name = "miEditArmy"; |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
45 WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmArmyTree_ArmyChanged); |
190 | 46 TranslateForm(); |
47 Translation.TranslationChanged += new MethodInvoker(TranslateForm); | |
48 } | |
49 | |
50 private void TranslateForm() | |
51 { | |
52 ControlTranslator.TranslateControl(this); | |
53 | |
54 foreach (Component comp in components.Components) | |
55 { | |
56 ControlTranslator.TranslateComponent(comp); | |
57 } | |
58 | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
59 foreach (IBBToolStripMenuItem mi in contextMenuStrip.Items) |
190 | 60 { |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
61 ControlTranslator.TranslateComponent(mi); |
190 | 62 } |
222
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
63 |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
64 foreach (TreeNode node in nodes.Values) |
190 | 65 { |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
66 node.Text = CreateNodeName((ICostedWarFoundryObject)node.Tag); |
190 | 67 } |
68 } | |
69 private void ClearArmy() | |
70 { | |
71 nodes.Clear(); | |
72 treeView.Nodes.Clear(); | |
73 } | |
74 | |
75 private void SetArmy(Army army) | |
76 { | |
77 ClearArmy(); | |
78 | |
79 if (army != null) | |
80 { | |
81 ArmyCategory[] cats = army.Categories; | |
82 TreeNode[] catNodes = new TreeNode[cats.Length]; | |
83 Unit[] units; | |
84 | |
85 for (int i = 0; i < cats.Length; i++) | |
86 { | |
87 ArmyCategory cat = cats[i]; | |
88 units = army.GetUnits(cat); | |
89 cat.NameChanged += TreeNameChangedMethod; | |
90 cat.PointsValueChanged += NodePointsValueChanged; | |
91 TreeNode[] unitNodes = new TreeNode[units.Length]; | |
92 TreeNode temp; | |
93 | |
94 for (int j = 0; j < units.Length; j++) | |
95 { | |
96 unitNodes[j] = CreateTreeNode(units[j]); | |
97 } | |
98 | |
99 temp = new TreeNode(CreateNodeName(cat), unitNodes); | |
100 temp.Tag = cat; | |
101 catNodes[i] = temp; | |
102 nodes[cat.ID] = temp; | |
103 } | |
104 | |
105 TreeNode root = new TreeNode(CreateNodeName(army), catNodes); | |
106 root.Tag = army; | |
107 army.PointsValueChanged += NodePointsValueChanged; | |
108 nodes[army.ID] = root; | |
109 treeView.Nodes.Add(root); | |
110 root.ExpandAll(); | |
111 } | |
112 } | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
113 |
190 | 114 private string CreateNodeName(ICostedWarFoundryObject obj) |
115 { | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
116 return Translation.GetTranslation("treeNodeText", "{0} ({1} pts)", obj.Name, obj.Points, CurrentGameSystem.GetPointsAbbrev(obj.Points)); |
190 | 117 } |
118 | |
119 private void NodePointsValueChanged(WarFoundryObject obj, double oldValue, double newValue) | |
120 { | |
121 if (obj is ICostedWarFoundryObject) | |
122 { | |
123 SetNodeName(obj); | |
124 } | |
125 } | |
126 | |
127 private void SetNodeName(WarFoundryObject obj) | |
128 { | |
129 TreeNode node = nodes[obj.ID]; | |
130 | |
131 if (node != null) | |
132 { | |
133 node.Text = CreateNodeName((ICostedWarFoundryObject)obj); | |
134 } | |
135 } | |
136 | |
137 private TreeNode CreateTreeNode(Unit unit) | |
138 { | |
139 TreeNode temp = new TreeNode(CreateNodeName(unit)); | |
140 temp.Tag = unit; | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
141 unit.NameChanged += UnitNameChangedMethod; |
190 | 142 unit.PointsValueChanged += NodePointsValueChanged; |
143 nodes[unit.ID] = temp; | |
144 return temp; | |
145 } | |
146 | |
147 public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy) | |
148 { | |
149 if (oldArmy != null) | |
150 { | |
222
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
151 oldArmy.NameChanged -= ArmyNameChangedMethod; |
190 | 152 oldArmy.UnitAdded -= UnitAddedMethod; |
153 oldArmy.UnitRemoved -= UnitRemovedMethod; | |
154 oldArmy.PointsValueChanged -= NodePointsValueChanged; | |
155 } | |
156 | |
157 if (newArmy != null) | |
158 { | |
222
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
159 newArmy.NameChanged += ArmyNameChangedMethod; |
190 | 160 newArmy.UnitAdded += UnitAddedMethod; |
161 newArmy.UnitRemoved += UnitRemovedMethod; | |
162 newArmy.PointsValueChanged += NodePointsValueChanged; | |
163 } | |
164 | |
165 SetArmy(newArmy); | |
166 } | |
167 | |
168 private void UnitAdded(WarFoundryObject obj) | |
169 { | |
170 if (obj is Unit) | |
171 { | |
172 Unit unit = (Unit)obj; | |
173 ArmyCategory cat = unit.Category; | |
174 TreeNode parent = nodes[cat.ID]; | |
175 TreeNode unitNode = CreateTreeNode(unit); | |
176 parent.Nodes.Add(unitNode); | |
177 parent.Expand(); //make sure it's expanded | |
178 } | |
179 } | |
180 | |
181 public new FrmMain MdiParent | |
182 { | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
183 get { return (FrmMain)base.MdiParent; } |
190 | 184 set { base.MdiParent = value; } |
185 } | |
186 | |
187 private void UnitRemoved(WarFoundryObject obj) | |
188 { | |
189 if (obj is Unit) | |
190 { | |
191 Unit unit = (Unit)obj; | |
192 RemoveUnitFromTree(unit); | |
193 } | |
194 } | |
195 | |
196 private void RemoveUnitFromTree(Unit unit) | |
197 { | |
198 TreeNode unitNode = nodes[unit.ID]; | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
199 unit.NameChanged -= UnitNameChangedMethod; |
190 | 200 |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
201 if (unitNode != null) |
190 | 202 { |
203 unitNode.Remove(); | |
204 nodes.Remove(unit.ID); | |
205 } | |
206 } | |
207 | |
208 private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) | |
209 { | |
210 if (e.Button == MouseButtons.Right) | |
211 { | |
212 TreeNode tn = treeView.GetNodeAt(e.X, e.Y); | |
213 | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
214 if (tn != null) |
190 | 215 { |
216 treeView.SelectedNode = tn; | |
217 } | |
218 else | |
219 { | |
220 treeView.SelectedNode = null; | |
221 } | |
222 } | |
223 } | |
224 | |
225 private void miDelete_Click(object sender, System.EventArgs e) | |
226 { | |
227 DeleteUnit(); | |
228 } | |
229 | |
230 private void DeleteUnit() | |
231 { | |
232 | |
233 TreeNode selected = treeView.SelectedNode; | |
234 | |
235 if (selected.Tag != null && selected.Tag is Unit) | |
236 { | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
237 Unit unit = (Unit)selected.Tag; |
190 | 238 commandStack.Execute(new RemoveUnitCommand(unit)); |
239 } | |
240 } | |
241 | |
242 private void miEdit_Click(object sender, System.EventArgs e) | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
243 { |
221
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
244 EditTreeItem(); |
190 | 245 } |
246 | |
247 private void treeView_DoubleClick(object sender, System.EventArgs e) | |
248 { | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
249 EditTreeItem(); |
190 | 250 } |
251 | |
221
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
252 private void EditTreeItem() |
190 | 253 { |
254 TreeNode selected = treeView.SelectedNode; | |
255 object tagData = selected.Tag; | |
256 | |
257 if (tagData is Unit) | |
258 { | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
259 Unit unit = (Unit)tagData; |
190 | 260 MdiParent.OpenUnitDialog(unit); |
261 } | |
221
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
262 else if (tagData is Army) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
263 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
264 EditArmy((Army)tagData); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
265 } |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
266 else if (tagData is ArmyCategory) |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
267 { |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
268 AddUnitFromCategory((ArmyCategory)tagData); |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
269 } |
190 | 270 } |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
271 |
190 | 272 private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue) |
273 { | |
274 if (obj is ICostedWarFoundryObject) | |
275 { | |
276 SetNodeName(obj); | |
277 } | |
278 } | |
279 | |
280 private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue) | |
281 { | |
282 if (obj is Army) | |
283 { | |
222
4ada3252d1ea
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
221
diff
changeset
|
284 SetNodeName((Army)obj); |
190 | 285 } |
286 } | |
287 | |
288 private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
289 { | |
290 TreeNode node = nodes[obj.ID]; | |
291 | |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
292 if (node != null) |
190 | 293 { |
294 node.Text = obj.Name; | |
295 } | |
296 } | |
297 | |
298 private void treeView_AfterSelect(object sender, TreeViewEventArgs e) | |
299 { | |
300 TreeNode node = treeView.SelectedNode; | |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
301 bttnAdd.Enabled = (node != null && node.Tag is ArmyCategory); |
190 | 302 bttnDelete.Enabled = (node != null && node.Tag is Unit); |
221
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
303 bttnEdit.Enabled = (node != null && (node.Tag is Unit || node.Tag is Army)); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
304 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
305 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
306 private void miEditArmy_Click(object sender, EventArgs e) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
307 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
308 Army army = treeView.SelectedNode.Tag as Army; |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
309 EditArmy(army); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
310 } |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
311 |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
312 private void EditArmy(Army army) |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
313 { |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
314 FrmEditArmy editForm = new FrmEditArmy(commandStack, army); |
5233147ca7e4
Re #101: Make army names and sizes modifiable after creation
IBBoard <dev@ibboard.co.uk>
parents:
198
diff
changeset
|
315 editForm.ShowDialog(this.ParentForm); |
190 | 316 } |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
317 |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
318 private void bttnEdit_Click(object sender, EventArgs e) |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
319 { |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
320 EditTreeItem(); |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
321 } |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
322 |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
323 private void bttnDelete_Click(object sender, EventArgs e) |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
324 { |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
325 DeleteUnit(); |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
326 } |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
327 |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
328 private void contextMenuStrip_Opening(object sender, CancelEventArgs e) |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
329 { |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
330 TreeNode node = treeView.SelectedNode; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
331 Object tag = (node != null) ? node.Tag : null; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
332 bool tagIsUnit = (tag is Unit); |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
333 bool tagIsArmy = (tag is Army); |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
334 bool tagIsCategory = (tag is ArmyCategory); |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
335 |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
336 if (!tagIsUnit && !tagIsArmy && !tagIsCategory) |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
337 { |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
338 e.Cancel = true; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
339 } |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
340 else |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
341 { |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
342 miDeleteUnit.Visible = tagIsUnit; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
343 miEditUnit.Visible = tagIsUnit; |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
344 miEditArmy.Visible = tagIsArmy; |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
345 miAddUnit.Visible = tagIsCategory; |
229
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
346 } |
870877498db9
Re #382: WinForms builds from Linux/Mono fail on Windows/.Net
IBBoard <dev@ibboard.co.uk>
parents:
222
diff
changeset
|
347 } |
234
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
348 |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
349 private void miAddUnit_Click(object sender, EventArgs e) |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
350 { |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
351 AddUnit(); |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
352 } |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
353 |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
354 private void AddUnit() |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
355 { |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
356 ArmyCategory tagData = treeView.SelectedNode.Tag as ArmyCategory; |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
357 AddUnitFromCategory(tagData); |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
358 } |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
359 |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
360 private void AddUnitFromCategory(ArmyCategory tagData) |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
361 { |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
362 MdiParent.AddUnitFromCategory(tagData.Category); |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
363 } |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
364 |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
365 private void bttnAdd_Click(object sender, EventArgs e) |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
366 { |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
367 AddUnit(); |
c06d0865ff27
Fixes #388: Add "Add unit" options to army tree
IBBoard <dev@ibboard.co.uk>
parents:
229
diff
changeset
|
368 } |
190 | 369 } |
370 } |