annotate FrmArmyTree.cs @ 44:1486ccd744dc

Fixes #135: Closing army crashes WinForms * Simple solution: Cache the open windows as an array then close them from the array to avoid iterating over an collection that gets modified!
author IBBoard <dev@ibboard.co.uk>
date Wed, 09 Sep 2009 19:37:14 +0000
parents 740350673006
children 1c74b51abac1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1 // This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
2 //
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 33
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.
33
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
4
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
5 using System;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
6 using System.Drawing;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
7 using System.Collections;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
8 using System.ComponentModel;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
9 using System.Windows.Forms;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
10 using IBBoard.Commands;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
11 using IBBoard.WarFoundry.API;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
12 using IBBoard.WarFoundry.API.Commands;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
13 using IBBoard.Windows.Forms;
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
14 using IBBoard.WarFoundry.API.Objects;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
15
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
16 namespace IBBoard.WarFoundry.GUI.WinForms
33
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
17 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
18 /// <summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
19 /// Summary description for FrmArmyTree.
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
20 /// </summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
21 public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
22 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
23 private System.Windows.Forms.TreeView treeView;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
24 /// <summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
25 /// Required designer variable.
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
26 /// </summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
27 private System.ComponentModel.Container components = null;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
28 private Hashtable htNodes;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
29 private System.Windows.Forms.ContextMenu contextMenu;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
30 private System.Windows.Forms.MenuItem miDelete;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
31 private System.Windows.Forms.MenuItem miEdit;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
32 private Hashtable htUnitWindows;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
33
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
34 private ObjectAddDelegate UnitAddedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
35 private ObjectRemoveDelegate UnitRemovedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
36 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
37 private CommandStack commandStack;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
38
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
39 public FrmArmyTree(CommandStack cmdStack)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
40 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
41 commandStack = cmdStack;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
42 InitializeComponent();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
43 UnitAddedMethod = new ObjectAddDelegate(AddUnit);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
44 UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
45 UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
46 ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
47 TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
48 htNodes = new Hashtable();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
49 htUnitWindows = new Hashtable();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
50 this.Name = "ArmyTree";
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
51 WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
52 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
53
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
54 public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
55 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
56 SetArmy(army);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
57 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
58
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
59 /// <summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
60 /// Clean up any resources being used.
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
61 /// </summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
62 protected override void Dispose( bool disposing )
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
63 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
64 if( disposing )
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
65 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
66 if(components != null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
67 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
68 components.Dispose();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
69 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
70 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
71 base.Dispose( disposing );
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
72 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
73
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
74 #region Windows Form Designer generated code
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
75 /// <summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
76 /// Required method for Designer support - do not modify
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
77 /// the contents of this method with the code editor.
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
78 /// </summary>
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
79 private void InitializeComponent()
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
80 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
81 this.treeView = new System.Windows.Forms.TreeView();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
82 this.contextMenu = new System.Windows.Forms.ContextMenu();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
83 this.miEdit = new System.Windows.Forms.MenuItem();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
84 this.miDelete = new System.Windows.Forms.MenuItem();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
85 this.SuspendLayout();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
86 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
87 // treeView
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
88 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
89 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
90 | System.Windows.Forms.AnchorStyles.Left)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
91 | System.Windows.Forms.AnchorStyles.Right)));
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
92 this.treeView.ContextMenu = this.contextMenu;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
93 this.treeView.FullRowSelect = true;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
94 this.treeView.ImageIndex = -1;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
95 this.treeView.Location = new System.Drawing.Point(0, 0);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
96 this.treeView.Name = "treeView";
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
97 this.treeView.SelectedImageIndex = -1;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
98 this.treeView.Size = new System.Drawing.Size(240, 278);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
99 this.treeView.TabIndex = 0;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
100 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
101 this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
102 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
103 // contextMenu
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
104 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
105 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
106 this.miEdit,
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
107 this.miDelete});
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
108 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
109 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
110 // miEdit
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
111 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
112 this.miEdit.Index = 0;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
113 this.miEdit.Text = "&Edit unit";
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
114 this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
115 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
116 // miDelete
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
117 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
118 this.miDelete.Index = 1;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
119 this.miDelete.Text = "&Delete unit";
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
120 this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
121 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
122 // FrmArmyTree
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
123 //
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
124 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
125 this.ClientSize = new System.Drawing.Size(240, 277);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
126 this.ControlBox = false;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
127 this.Controls.Add(this.treeView);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
128 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
129 this.MaximizeBox = false;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
130 this.MinimizeBox = false;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
131 this.Name = "FrmArmyTree";
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
132 this.Text = "FrmArmyTree";
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
133 this.ResumeLayout(false);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
134
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
135 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
136 #endregion
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
137
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
138 private void ClearArmy()
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
139 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
140 htNodes.Clear();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
141 treeView.Nodes.Clear();
44
1486ccd744dc Fixes #135: Closing army crashes WinForms
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
142 ICollection unitFormsCollection = htUnitWindows.Values;
1486ccd744dc Fixes #135: Closing army crashes WinForms
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
143 FrmUnit[] unitForms = new FrmUnit[unitFormsCollection.Count];
1486ccd744dc Fixes #135: Closing army crashes WinForms
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
144 unitFormsCollection.CopyTo(unitForms, 0);
33
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
145
44
1486ccd744dc Fixes #135: Closing army crashes WinForms
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
146 foreach (FrmUnit window in unitForms)
33
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
147 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
148 window.Close();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
149 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
150
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
151 htUnitWindows.Clear();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
152 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
153
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
154 private void SetArmy(Army army)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
155 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
156 ClearArmy();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
157
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
158 if (army != null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
159 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
160 ArmyCategory[] cats = army.Categories;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
161 TreeNode[] catNodes = new TreeNode[cats.Length];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
162 Unit[] units;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
163
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
164 for (int i = 0; i < cats.Length; i++)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
165 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
166 units = army.GetUnits(cats[i]);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
167 cats[i].NameChanged += TreeNameChangedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
168 TreeNode[] unitNodes = new TreeNode[units.Length];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
169 TreeNode temp;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
170
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
171 for (int j = 0; j < units.Length; j++)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
172 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
173 unitNodes[j] = createTreeNode(units[j]);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
174 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
175
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
176 temp = new TreeNode(cats[i].Name, unitNodes);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
177 temp.Tag = cats[i];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
178 catNodes[i] = temp;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
179 htNodes[cats[i].ID] = temp;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
180 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
181
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
182 TreeNode root = new TreeNode(army.Name, catNodes);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
183 root.Tag = army;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
184 treeView.Nodes.Add(root);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
185 root.ExpandAll();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
186 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
187 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
188
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
189 private TreeNode createTreeNode(Unit unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
190 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
191 TreeNode temp = new TreeNode(unit.Name);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
192 temp.Tag = unit;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
193 unit.NameChanged+= UnitNameChangedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
194 htNodes[unit.ID] = temp;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
195 return temp;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
196 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
197
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
198 /*private void FrmArmyTree_Move(object sender, System.EventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
199 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
200 if (ParentForm is FrmMain)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
201 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
202 FrmMain main = (FrmMain)ParentForm;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
203 main.Invoke(new MethodInvoker(main.MdiChildMoved));
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
204 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
205 }*/
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
206
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
207 public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
208 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
209 if (oldArmy != null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
210 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
211 oldArmy.UnitAdded -= UnitAddedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
212 oldArmy.UnitRemoved -= UnitRemovedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
213 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
214
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
215 if (newArmy != null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
216 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
217 newArmy.UnitAdded += UnitAddedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
218 newArmy.UnitRemoved += UnitRemovedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
219 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
220
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
221 SetArmy(newArmy);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
222 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
223
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
224 private void AddUnit(object obj)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
225 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
226 if (obj is Unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
227 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
228 Unit unit = (Unit)obj;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
229 ArmyCategory cat = unit.Category;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
230 TreeNode parent = (TreeNode)htNodes[cat.ID];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
231 TreeNode unitNode = createTreeNode(unit);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
232 parent.Nodes.Add(unitNode);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
233 parent.Expand(); //make sure it's expanded
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
234 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
235 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
236
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
237 private void RemoveUnit(object obj)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
238 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
239 if (obj is Unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
240 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
241 Unit unit = (Unit)obj;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
242 removeUnit(unit);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
243 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
244 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
245
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
246 private void removeUnit(Unit unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
247 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
248 TreeNode unitNode = (TreeNode)htNodes[unit.ID];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
249 unit.NameChanged-= UnitNameChangedMethod;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
250
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
251 if (unitNode!=null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
252 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
253 unitNode.Remove();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
254 htNodes.Remove(unit.ID);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
255 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
256 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
257
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
258
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
259 private void contextMenu_Popup(object sender, System.EventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
260 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
261 TreeNode node = treeView.SelectedNode;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
262 if (node!=null && node.Tag is Unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
263 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
264 foreach(MenuItem item in contextMenu.MenuItems)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
265 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
266 item.Visible = true;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
267 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
268 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
269 else
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
270 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
271 foreach(MenuItem item in contextMenu.MenuItems)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
272 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
273 item.Visible = false;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
274 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
275 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
276 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
277
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
278 private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
279 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
280 if (e.Button == MouseButtons.Right)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
281 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
282 TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
283
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
284 if (tn!=null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
285 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
286 treeView.SelectedNode = tn;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
287 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
288 else
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
289 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
290 treeView.SelectedNode = null;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
291 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
292 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
293 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
294
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
295 private void miDelete_Click(object sender, System.EventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
296 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
297 TreeNode selected = treeView.SelectedNode;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
298
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
299 if (selected.Tag!=null && selected.Tag is Unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
300 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
301 Unit unit = (Unit)selected.Tag;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
302 commandStack.Execute(new RemoveUnitCommand(unit));
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
303 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
304 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
305
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
306 private void miEdit_Click(object sender, System.EventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
307 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
308 editUnit();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
309 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
310
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
311 private void treeView_DoubleClick(object sender, System.EventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
312 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
313 editUnit();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
314 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
315
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
316 private void editUnit()
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
317 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
318 TreeNode selected = treeView.SelectedNode;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
319
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
320 if (selected.Tag!=null && selected.Tag is Unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
321 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
322 Unit unit = (Unit)selected.Tag;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
323
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
324 if (htUnitWindows.ContainsKey(unit.ID))
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
325 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
326 ((FrmUnit)htUnitWindows[unit.ID]).Focus();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
327 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
328 else
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
329 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
330 FrmUnit unitForm = new FrmUnit(unit, commandStack);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
331 htUnitWindows.Add(unit.ID, unitForm);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
332 unitForm.MdiParent = this.MdiParent;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
333 unitForm.Closing+=new CancelEventHandler(unitForm_Closing);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
334 unitForm.Show();
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
335 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
336 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
337 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
338
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
339 private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
340 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
341 if (obj is Unit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
342 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
343 Unit unit = (Unit)obj;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
344 TreeNode node = (TreeNode)htNodes[unit.ID];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
345
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
346 if (node!=null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
347 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
348 node.Text = unit.Name;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
349 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
350 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
351 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
352
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
353 private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
354 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
355 if (obj is Army)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
356 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
357 Army army = (Army)obj;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
358 TreeNode node = treeView.Nodes[0];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
359
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
360 if (node!=null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
361 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
362 node.Text = army.Name;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
363 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
364 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
365 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
366
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
367 private void unitForm_Closing(object sender, CancelEventArgs e)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
368 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
369 if (sender is FrmUnit)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
370 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
371 FrmUnit unitForm = (FrmUnit)sender;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
372 htUnitWindows.Remove(unitForm.Unit.ID);
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
373 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
374 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
375
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
376 private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
377 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
378 TreeNode node = (TreeNode)htNodes[obj.ID];
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
379
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
380 if (node!=null)
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
381 {
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
382 node.Text = obj.Name;
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
383 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
384 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
385 }
67c283ea77a7 * Code cleanup (line endings)
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
386 }