changeset 33:67c283ea77a7

* Code cleanup (line endings) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sun, 09 Aug 2009 12:05:24 +0000
parents e97867236672
children 3ceb0efd261f
files FrmArmyTree.cs FrmSelectSystem.cs
diffstat 2 files changed, 479 insertions(+), 479 deletions(-) [+]
line diff
     1.1 --- a/FrmArmyTree.cs	Tue Aug 04 19:40:20 2009 +0000
     1.2 +++ b/FrmArmyTree.cs	Sun Aug 09 12:05:24 2009 +0000
     1.3 @@ -1,383 +1,383 @@
     1.4 -// This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
     1.5 -//
     1.6 -// 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.
     1.7 -
     1.8 -using System;
     1.9 -using System.Drawing;
    1.10 -using System.Collections;
    1.11 -using System.ComponentModel;
    1.12 -using System.Windows.Forms;
    1.13 -using IBBoard.Commands;
    1.14 -using IBBoard.WarFoundry.API;
    1.15 -using IBBoard.WarFoundry.API.Commands;
    1.16 -using IBBoard.Windows.Forms;
    1.17 +// This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
    1.18 +//
    1.19 +// 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.
    1.20 +
    1.21 +using System;
    1.22 +using System.Drawing;
    1.23 +using System.Collections;
    1.24 +using System.ComponentModel;
    1.25 +using System.Windows.Forms;
    1.26 +using IBBoard.Commands;
    1.27 +using IBBoard.WarFoundry.API;
    1.28 +using IBBoard.WarFoundry.API.Commands;
    1.29 +using IBBoard.Windows.Forms;
    1.30  using IBBoard.WarFoundry.API.Objects;
    1.31  
    1.32 -namespace IBBoard.WarFoundry.WinForms
    1.33 -{
    1.34 -	/// <summary>
    1.35 -	/// Summary description for FrmArmyTree.
    1.36 -	/// </summary>
    1.37 -	public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
    1.38 -	{
    1.39 -		private System.Windows.Forms.TreeView treeView;
    1.40 -		/// <summary>
    1.41 -		/// Required designer variable.
    1.42 -		/// </summary>
    1.43 -		private System.ComponentModel.Container components = null;
    1.44 -		private Hashtable htNodes;
    1.45 -		private System.Windows.Forms.ContextMenu contextMenu;
    1.46 -		private System.Windows.Forms.MenuItem miDelete;
    1.47 -		private System.Windows.Forms.MenuItem miEdit;
    1.48 -		private Hashtable htUnitWindows;
    1.49 -		
    1.50 -		private ObjectAddDelegate UnitAddedMethod;
    1.51 -		private ObjectRemoveDelegate UnitRemovedMethod;
    1.52 -		private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
    1.53 -		private CommandStack commandStack;
    1.54 -
    1.55 -		public FrmArmyTree(CommandStack cmdStack)
    1.56 -		{
    1.57 -			commandStack = cmdStack;
    1.58 -			InitializeComponent();
    1.59 -			UnitAddedMethod = new ObjectAddDelegate(AddUnit);
    1.60 -			UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit);
    1.61 -			UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
    1.62 -			ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
    1.63 -			TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
    1.64 -			htNodes = new Hashtable();
    1.65 -			htUnitWindows = new Hashtable();
    1.66 -			this.Name = "ArmyTree";			
    1.67 -			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
    1.68 -		}
    1.69 -
    1.70 -		public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
    1.71 -		{
    1.72 -			SetArmy(army);
    1.73 -		}
    1.74 -
    1.75 -		/// <summary>
    1.76 -		/// Clean up any resources being used.
    1.77 -		/// </summary>
    1.78 -		protected override void Dispose( bool disposing )
    1.79 -		{
    1.80 -			if( disposing )
    1.81 -			{
    1.82 -				if(components != null)
    1.83 -				{
    1.84 -					components.Dispose();
    1.85 -				}
    1.86 -			}
    1.87 -			base.Dispose( disposing );
    1.88 -		}
    1.89 -
    1.90 -		#region Windows Form Designer generated code
    1.91 -		/// <summary>
    1.92 -		/// Required method for Designer support - do not modify
    1.93 -		/// the contents of this method with the code editor.
    1.94 -		/// </summary>
    1.95 -		private void InitializeComponent()
    1.96 -		{
    1.97 -			this.treeView = new System.Windows.Forms.TreeView();
    1.98 -			this.contextMenu = new System.Windows.Forms.ContextMenu();
    1.99 -			this.miEdit = new System.Windows.Forms.MenuItem();
   1.100 -			this.miDelete = new System.Windows.Forms.MenuItem();
   1.101 -			this.SuspendLayout();
   1.102 -			// 
   1.103 -			// treeView
   1.104 -			// 
   1.105 -			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
   1.106 -				| System.Windows.Forms.AnchorStyles.Left) 
   1.107 -				| System.Windows.Forms.AnchorStyles.Right)));
   1.108 -			this.treeView.ContextMenu = this.contextMenu;
   1.109 -			this.treeView.FullRowSelect = true;
   1.110 -			this.treeView.ImageIndex = -1;
   1.111 -			this.treeView.Location = new System.Drawing.Point(0, 0);
   1.112 -			this.treeView.Name = "treeView";
   1.113 -			this.treeView.SelectedImageIndex = -1;
   1.114 -			this.treeView.Size = new System.Drawing.Size(240, 278);
   1.115 -			this.treeView.TabIndex = 0;
   1.116 -			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
   1.117 -			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
   1.118 -			// 
   1.119 -			// contextMenu
   1.120 -			// 
   1.121 -			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
   1.122 -																						this.miEdit,
   1.123 -																						this.miDelete});
   1.124 -			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
   1.125 -			// 
   1.126 -			// miEdit
   1.127 -			// 
   1.128 -			this.miEdit.Index = 0;
   1.129 -			this.miEdit.Text = "&Edit unit";
   1.130 -			this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
   1.131 -			// 
   1.132 -			// miDelete
   1.133 -			// 
   1.134 -			this.miDelete.Index = 1;
   1.135 -			this.miDelete.Text = "&Delete unit";
   1.136 -			this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
   1.137 -			// 
   1.138 -			// FrmArmyTree
   1.139 -			// 
   1.140 -			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.141 -			this.ClientSize = new System.Drawing.Size(240, 277);
   1.142 -			this.ControlBox = false;
   1.143 -			this.Controls.Add(this.treeView);
   1.144 -			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
   1.145 -			this.MaximizeBox = false;
   1.146 -			this.MinimizeBox = false;
   1.147 -			this.Name = "FrmArmyTree";
   1.148 -			this.Text = "FrmArmyTree";
   1.149 -			this.ResumeLayout(false);
   1.150 -
   1.151 -		}
   1.152 -		#endregion
   1.153 -
   1.154 -		private void ClearArmy()
   1.155 -		{
   1.156 -			htNodes.Clear();
   1.157 -			treeView.Nodes.Clear();
   1.158 -
   1.159 -			foreach (FrmUnit window in htUnitWindows.Values)
   1.160 -			{
   1.161 -				window.Close();
   1.162 -			}
   1.163 -
   1.164 -			htUnitWindows.Clear();
   1.165 -		}
   1.166 -
   1.167 -		private void SetArmy(Army army)
   1.168 -		{
   1.169 -			ClearArmy();
   1.170 -
   1.171 -			if (army != null)
   1.172 -			{
   1.173 -				ArmyCategory[] cats = army.Categories;
   1.174 -				TreeNode[] catNodes = new TreeNode[cats.Length];
   1.175 -				Unit[] units;
   1.176 -
   1.177 -				for (int i = 0; i < cats.Length; i++)
   1.178 -				{
   1.179 -					units = army.GetUnits(cats[i]);
   1.180 -					cats[i].NameChanged += TreeNameChangedMethod;
   1.181 -					TreeNode[] unitNodes = new TreeNode[units.Length];
   1.182 -					TreeNode temp;
   1.183 -
   1.184 -					for (int j = 0; j < units.Length; j++)
   1.185 -					{
   1.186 -						unitNodes[j] = createTreeNode(units[j]);
   1.187 -					}
   1.188 -
   1.189 -					temp = new TreeNode(cats[i].Name, unitNodes);
   1.190 -					temp.Tag = cats[i];
   1.191 -					catNodes[i] = temp;
   1.192 -					htNodes[cats[i].ID] = temp;
   1.193 -				}
   1.194 -
   1.195 -				TreeNode root = new TreeNode(army.Name, catNodes);
   1.196 -				root.Tag = army;
   1.197 -				treeView.Nodes.Add(root);
   1.198 -				root.ExpandAll();
   1.199 -			}
   1.200 -		}
   1.201 -
   1.202 -		private TreeNode createTreeNode(Unit unit)
   1.203 -		{
   1.204 -			TreeNode temp = new TreeNode(unit.Name);
   1.205 -			temp.Tag = unit;
   1.206 -			unit.NameChanged+= UnitNameChangedMethod;
   1.207 -			htNodes[unit.ID] = temp;
   1.208 -			return temp;
   1.209 -		}
   1.210 -
   1.211 -		/*private void FrmArmyTree_Move(object sender, System.EventArgs e)
   1.212 -		{
   1.213 -			if (ParentForm is FrmMain)
   1.214 -			{
   1.215 -				FrmMain main = (FrmMain)ParentForm;
   1.216 -				main.Invoke(new MethodInvoker(main.MdiChildMoved));
   1.217 -			}
   1.218 -		}*/
   1.219 -
   1.220 -		public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy)
   1.221 -		{
   1.222 -			if (oldArmy != null)
   1.223 -			{
   1.224 -				oldArmy.UnitAdded -= UnitAddedMethod;
   1.225 -				oldArmy.UnitRemoved -= UnitRemovedMethod;
   1.226 -			}
   1.227 -
   1.228 -			if (newArmy != null)
   1.229 -			{
   1.230 -				newArmy.UnitAdded += UnitAddedMethod;
   1.231 -				newArmy.UnitRemoved += UnitRemovedMethod;
   1.232 -			}
   1.233 -
   1.234 -			SetArmy(newArmy);
   1.235 -		}
   1.236 -		
   1.237 -		private void AddUnit(object obj)
   1.238 -		{
   1.239 -			if (obj is Unit)
   1.240 -			{
   1.241 -				Unit unit = (Unit)obj;
   1.242 -				ArmyCategory cat = unit.Category;
   1.243 -				TreeNode parent = (TreeNode)htNodes[cat.ID];
   1.244 -				TreeNode unitNode = createTreeNode(unit);
   1.245 -				parent.Nodes.Add(unitNode);
   1.246 -				parent.Expand(); //make sure it's expanded
   1.247 -			}
   1.248 -		}
   1.249 -
   1.250 -		private void RemoveUnit(object obj)
   1.251 -		{
   1.252 -			if (obj is Unit)
   1.253 -			{
   1.254 -				Unit unit = (Unit)obj;
   1.255 -				removeUnit(unit);
   1.256 -			}
   1.257 -		}
   1.258 -
   1.259 -		private void removeUnit(Unit unit)
   1.260 -		{
   1.261 -			TreeNode unitNode = (TreeNode)htNodes[unit.ID];
   1.262 -			unit.NameChanged-= UnitNameChangedMethod;
   1.263 -
   1.264 -			if (unitNode!=null)
   1.265 -			{
   1.266 -				unitNode.Remove();
   1.267 -				htNodes.Remove(unit.ID);
   1.268 -			}
   1.269 -		}
   1.270 -
   1.271 -
   1.272 -		private void contextMenu_Popup(object sender, System.EventArgs e)
   1.273 -		{
   1.274 -			TreeNode node = treeView.SelectedNode;
   1.275 -			if (node!=null && node.Tag is Unit)
   1.276 -			{
   1.277 -				foreach(MenuItem item in contextMenu.MenuItems)
   1.278 -				{
   1.279 -					item.Visible = true;
   1.280 -				}
   1.281 -			}
   1.282 -			else
   1.283 -			{
   1.284 -				foreach(MenuItem item in contextMenu.MenuItems)
   1.285 -				{
   1.286 -					item.Visible = false;
   1.287 -				}
   1.288 -			}
   1.289 -		}
   1.290 -
   1.291 -		private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
   1.292 -		{
   1.293 -			if (e.Button == MouseButtons.Right)
   1.294 -			{
   1.295 -				TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
   1.296 -
   1.297 -				if (tn!=null)
   1.298 -				{
   1.299 -					treeView.SelectedNode = tn;
   1.300 -				}
   1.301 -				else
   1.302 -				{
   1.303 -					treeView.SelectedNode = null;
   1.304 -				}
   1.305 -			}
   1.306 -		}
   1.307 -
   1.308 -		private void miDelete_Click(object sender, System.EventArgs e)
   1.309 -		{
   1.310 -			TreeNode selected = treeView.SelectedNode;
   1.311 -
   1.312 -			if (selected.Tag!=null && selected.Tag is Unit)
   1.313 -			{
   1.314 -				Unit unit = (Unit)selected.Tag;
   1.315 -				commandStack.Execute(new RemoveUnitCommand(unit));
   1.316 -			}
   1.317 -		}
   1.318 -
   1.319 -		private void miEdit_Click(object sender, System.EventArgs e)
   1.320 -		{	
   1.321 -			editUnit();
   1.322 -		}
   1.323 -
   1.324 -		private void treeView_DoubleClick(object sender, System.EventArgs e)
   1.325 -		{
   1.326 -			editUnit();			
   1.327 -		}
   1.328 -
   1.329 -		private void editUnit()
   1.330 -		{
   1.331 -			TreeNode selected = treeView.SelectedNode;
   1.332 -
   1.333 -			if (selected.Tag!=null && selected.Tag is Unit)
   1.334 -			{
   1.335 -				Unit unit = (Unit)selected.Tag;
   1.336 -
   1.337 -				if (htUnitWindows.ContainsKey(unit.ID))
   1.338 -				{
   1.339 -					((FrmUnit)htUnitWindows[unit.ID]).Focus();
   1.340 -				}
   1.341 -				else
   1.342 -				{
   1.343 -					FrmUnit unitForm = new FrmUnit(unit, commandStack);
   1.344 -					htUnitWindows.Add(unit.ID, unitForm);
   1.345 -					unitForm.MdiParent = this.MdiParent;
   1.346 -					unitForm.Closing+=new CancelEventHandler(unitForm_Closing);
   1.347 -					unitForm.Show();
   1.348 -				}
   1.349 -			}
   1.350 -		}
   1.351 -
   1.352 -		private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
   1.353 -		{
   1.354 -			if (obj is Unit)
   1.355 -			{
   1.356 -				Unit unit = (Unit)obj;
   1.357 -				TreeNode node = (TreeNode)htNodes[unit.ID];
   1.358 -				
   1.359 -				if (node!=null)
   1.360 -				{
   1.361 -					node.Text = unit.Name;
   1.362 -				}
   1.363 -			}
   1.364 -		}
   1.365 -
   1.366 -		private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue)
   1.367 -		{
   1.368 -			if (obj is Army)
   1.369 -			{
   1.370 -				Army army = (Army)obj;
   1.371 -				TreeNode node = treeView.Nodes[0];
   1.372 -				
   1.373 -				if (node!=null)
   1.374 -				{
   1.375 -					node.Text = army.Name;
   1.376 -				}
   1.377 -			}
   1.378 -		}
   1.379 -
   1.380 -		private void unitForm_Closing(object sender, CancelEventArgs e)
   1.381 -		{
   1.382 -			if (sender is FrmUnit)
   1.383 -			{
   1.384 -				FrmUnit unitForm = (FrmUnit)sender;
   1.385 -				htUnitWindows.Remove(unitForm.Unit.ID);
   1.386 -			}
   1.387 -		}
   1.388 -
   1.389 -		private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.390 -		{
   1.391 -			TreeNode node = (TreeNode)htNodes[obj.ID];
   1.392 -
   1.393 -			if (node!=null)
   1.394 -			{
   1.395 -				node.Text = obj.Name;
   1.396 -			}
   1.397 -		}
   1.398 -	}
   1.399 -}
   1.400 +namespace IBBoard.WarFoundry.WinForms
   1.401 +{
   1.402 +	/// <summary>
   1.403 +	/// Summary description for FrmArmyTree.
   1.404 +	/// </summary>
   1.405 +	public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
   1.406 +	{
   1.407 +		private System.Windows.Forms.TreeView treeView;
   1.408 +		/// <summary>
   1.409 +		/// Required designer variable.
   1.410 +		/// </summary>
   1.411 +		private System.ComponentModel.Container components = null;
   1.412 +		private Hashtable htNodes;
   1.413 +		private System.Windows.Forms.ContextMenu contextMenu;
   1.414 +		private System.Windows.Forms.MenuItem miDelete;
   1.415 +		private System.Windows.Forms.MenuItem miEdit;
   1.416 +		private Hashtable htUnitWindows;
   1.417 +		
   1.418 +		private ObjectAddDelegate UnitAddedMethod;
   1.419 +		private ObjectRemoveDelegate UnitRemovedMethod;
   1.420 +		private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
   1.421 +		private CommandStack commandStack;
   1.422 +
   1.423 +		public FrmArmyTree(CommandStack cmdStack)
   1.424 +		{
   1.425 +			commandStack = cmdStack;
   1.426 +			InitializeComponent();
   1.427 +			UnitAddedMethod = new ObjectAddDelegate(AddUnit);
   1.428 +			UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit);
   1.429 +			UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
   1.430 +			ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
   1.431 +			TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
   1.432 +			htNodes = new Hashtable();
   1.433 +			htUnitWindows = new Hashtable();
   1.434 +			this.Name = "ArmyTree";			
   1.435 +			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
   1.436 +		}
   1.437 +
   1.438 +		public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
   1.439 +		{
   1.440 +			SetArmy(army);
   1.441 +		}
   1.442 +
   1.443 +		/// <summary>
   1.444 +		/// Clean up any resources being used.
   1.445 +		/// </summary>
   1.446 +		protected override void Dispose( bool disposing )
   1.447 +		{
   1.448 +			if( disposing )
   1.449 +			{
   1.450 +				if(components != null)
   1.451 +				{
   1.452 +					components.Dispose();
   1.453 +				}
   1.454 +			}
   1.455 +			base.Dispose( disposing );
   1.456 +		}
   1.457 +
   1.458 +		#region Windows Form Designer generated code
   1.459 +		/// <summary>
   1.460 +		/// Required method for Designer support - do not modify
   1.461 +		/// the contents of this method with the code editor.
   1.462 +		/// </summary>
   1.463 +		private void InitializeComponent()
   1.464 +		{
   1.465 +			this.treeView = new System.Windows.Forms.TreeView();
   1.466 +			this.contextMenu = new System.Windows.Forms.ContextMenu();
   1.467 +			this.miEdit = new System.Windows.Forms.MenuItem();
   1.468 +			this.miDelete = new System.Windows.Forms.MenuItem();
   1.469 +			this.SuspendLayout();
   1.470 +			// 
   1.471 +			// treeView
   1.472 +			// 
   1.473 +			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
   1.474 +				| System.Windows.Forms.AnchorStyles.Left) 
   1.475 +				| System.Windows.Forms.AnchorStyles.Right)));
   1.476 +			this.treeView.ContextMenu = this.contextMenu;
   1.477 +			this.treeView.FullRowSelect = true;
   1.478 +			this.treeView.ImageIndex = -1;
   1.479 +			this.treeView.Location = new System.Drawing.Point(0, 0);
   1.480 +			this.treeView.Name = "treeView";
   1.481 +			this.treeView.SelectedImageIndex = -1;
   1.482 +			this.treeView.Size = new System.Drawing.Size(240, 278);
   1.483 +			this.treeView.TabIndex = 0;
   1.484 +			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
   1.485 +			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
   1.486 +			// 
   1.487 +			// contextMenu
   1.488 +			// 
   1.489 +			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
   1.490 +																						this.miEdit,
   1.491 +																						this.miDelete});
   1.492 +			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
   1.493 +			// 
   1.494 +			// miEdit
   1.495 +			// 
   1.496 +			this.miEdit.Index = 0;
   1.497 +			this.miEdit.Text = "&Edit unit";
   1.498 +			this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
   1.499 +			// 
   1.500 +			// miDelete
   1.501 +			// 
   1.502 +			this.miDelete.Index = 1;
   1.503 +			this.miDelete.Text = "&Delete unit";
   1.504 +			this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
   1.505 +			// 
   1.506 +			// FrmArmyTree
   1.507 +			// 
   1.508 +			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.509 +			this.ClientSize = new System.Drawing.Size(240, 277);
   1.510 +			this.ControlBox = false;
   1.511 +			this.Controls.Add(this.treeView);
   1.512 +			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
   1.513 +			this.MaximizeBox = false;
   1.514 +			this.MinimizeBox = false;
   1.515 +			this.Name = "FrmArmyTree";
   1.516 +			this.Text = "FrmArmyTree";
   1.517 +			this.ResumeLayout(false);
   1.518 +
   1.519 +		}
   1.520 +		#endregion
   1.521 +
   1.522 +		private void ClearArmy()
   1.523 +		{
   1.524 +			htNodes.Clear();
   1.525 +			treeView.Nodes.Clear();
   1.526 +
   1.527 +			foreach (FrmUnit window in htUnitWindows.Values)
   1.528 +			{
   1.529 +				window.Close();
   1.530 +			}
   1.531 +
   1.532 +			htUnitWindows.Clear();
   1.533 +		}
   1.534 +
   1.535 +		private void SetArmy(Army army)
   1.536 +		{
   1.537 +			ClearArmy();
   1.538 +
   1.539 +			if (army != null)
   1.540 +			{
   1.541 +				ArmyCategory[] cats = army.Categories;
   1.542 +				TreeNode[] catNodes = new TreeNode[cats.Length];
   1.543 +				Unit[] units;
   1.544 +
   1.545 +				for (int i = 0; i < cats.Length; i++)
   1.546 +				{
   1.547 +					units = army.GetUnits(cats[i]);
   1.548 +					cats[i].NameChanged += TreeNameChangedMethod;
   1.549 +					TreeNode[] unitNodes = new TreeNode[units.Length];
   1.550 +					TreeNode temp;
   1.551 +
   1.552 +					for (int j = 0; j < units.Length; j++)
   1.553 +					{
   1.554 +						unitNodes[j] = createTreeNode(units[j]);
   1.555 +					}
   1.556 +
   1.557 +					temp = new TreeNode(cats[i].Name, unitNodes);
   1.558 +					temp.Tag = cats[i];
   1.559 +					catNodes[i] = temp;
   1.560 +					htNodes[cats[i].ID] = temp;
   1.561 +				}
   1.562 +
   1.563 +				TreeNode root = new TreeNode(army.Name, catNodes);
   1.564 +				root.Tag = army;
   1.565 +				treeView.Nodes.Add(root);
   1.566 +				root.ExpandAll();
   1.567 +			}
   1.568 +		}
   1.569 +
   1.570 +		private TreeNode createTreeNode(Unit unit)
   1.571 +		{
   1.572 +			TreeNode temp = new TreeNode(unit.Name);
   1.573 +			temp.Tag = unit;
   1.574 +			unit.NameChanged+= UnitNameChangedMethod;
   1.575 +			htNodes[unit.ID] = temp;
   1.576 +			return temp;
   1.577 +		}
   1.578 +
   1.579 +		/*private void FrmArmyTree_Move(object sender, System.EventArgs e)
   1.580 +		{
   1.581 +			if (ParentForm is FrmMain)
   1.582 +			{
   1.583 +				FrmMain main = (FrmMain)ParentForm;
   1.584 +				main.Invoke(new MethodInvoker(main.MdiChildMoved));
   1.585 +			}
   1.586 +		}*/
   1.587 +
   1.588 +		public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy)
   1.589 +		{
   1.590 +			if (oldArmy != null)
   1.591 +			{
   1.592 +				oldArmy.UnitAdded -= UnitAddedMethod;
   1.593 +				oldArmy.UnitRemoved -= UnitRemovedMethod;
   1.594 +			}
   1.595 +
   1.596 +			if (newArmy != null)
   1.597 +			{
   1.598 +				newArmy.UnitAdded += UnitAddedMethod;
   1.599 +				newArmy.UnitRemoved += UnitRemovedMethod;
   1.600 +			}
   1.601 +
   1.602 +			SetArmy(newArmy);
   1.603 +		}
   1.604 +		
   1.605 +		private void AddUnit(object obj)
   1.606 +		{
   1.607 +			if (obj is Unit)
   1.608 +			{
   1.609 +				Unit unit = (Unit)obj;
   1.610 +				ArmyCategory cat = unit.Category;
   1.611 +				TreeNode parent = (TreeNode)htNodes[cat.ID];
   1.612 +				TreeNode unitNode = createTreeNode(unit);
   1.613 +				parent.Nodes.Add(unitNode);
   1.614 +				parent.Expand(); //make sure it's expanded
   1.615 +			}
   1.616 +		}
   1.617 +
   1.618 +		private void RemoveUnit(object obj)
   1.619 +		{
   1.620 +			if (obj is Unit)
   1.621 +			{
   1.622 +				Unit unit = (Unit)obj;
   1.623 +				removeUnit(unit);
   1.624 +			}
   1.625 +		}
   1.626 +
   1.627 +		private void removeUnit(Unit unit)
   1.628 +		{
   1.629 +			TreeNode unitNode = (TreeNode)htNodes[unit.ID];
   1.630 +			unit.NameChanged-= UnitNameChangedMethod;
   1.631 +
   1.632 +			if (unitNode!=null)
   1.633 +			{
   1.634 +				unitNode.Remove();
   1.635 +				htNodes.Remove(unit.ID);
   1.636 +			}
   1.637 +		}
   1.638 +
   1.639 +
   1.640 +		private void contextMenu_Popup(object sender, System.EventArgs e)
   1.641 +		{
   1.642 +			TreeNode node = treeView.SelectedNode;
   1.643 +			if (node!=null && node.Tag is Unit)
   1.644 +			{
   1.645 +				foreach(MenuItem item in contextMenu.MenuItems)
   1.646 +				{
   1.647 +					item.Visible = true;
   1.648 +				}
   1.649 +			}
   1.650 +			else
   1.651 +			{
   1.652 +				foreach(MenuItem item in contextMenu.MenuItems)
   1.653 +				{
   1.654 +					item.Visible = false;
   1.655 +				}
   1.656 +			}
   1.657 +		}
   1.658 +
   1.659 +		private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
   1.660 +		{
   1.661 +			if (e.Button == MouseButtons.Right)
   1.662 +			{
   1.663 +				TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
   1.664 +
   1.665 +				if (tn!=null)
   1.666 +				{
   1.667 +					treeView.SelectedNode = tn;
   1.668 +				}
   1.669 +				else
   1.670 +				{
   1.671 +					treeView.SelectedNode = null;
   1.672 +				}
   1.673 +			}
   1.674 +		}
   1.675 +
   1.676 +		private void miDelete_Click(object sender, System.EventArgs e)
   1.677 +		{
   1.678 +			TreeNode selected = treeView.SelectedNode;
   1.679 +
   1.680 +			if (selected.Tag!=null && selected.Tag is Unit)
   1.681 +			{
   1.682 +				Unit unit = (Unit)selected.Tag;
   1.683 +				commandStack.Execute(new RemoveUnitCommand(unit));
   1.684 +			}
   1.685 +		}
   1.686 +
   1.687 +		private void miEdit_Click(object sender, System.EventArgs e)
   1.688 +		{	
   1.689 +			editUnit();
   1.690 +		}
   1.691 +
   1.692 +		private void treeView_DoubleClick(object sender, System.EventArgs e)
   1.693 +		{
   1.694 +			editUnit();			
   1.695 +		}
   1.696 +
   1.697 +		private void editUnit()
   1.698 +		{
   1.699 +			TreeNode selected = treeView.SelectedNode;
   1.700 +
   1.701 +			if (selected.Tag!=null && selected.Tag is Unit)
   1.702 +			{
   1.703 +				Unit unit = (Unit)selected.Tag;
   1.704 +
   1.705 +				if (htUnitWindows.ContainsKey(unit.ID))
   1.706 +				{
   1.707 +					((FrmUnit)htUnitWindows[unit.ID]).Focus();
   1.708 +				}
   1.709 +				else
   1.710 +				{
   1.711 +					FrmUnit unitForm = new FrmUnit(unit, commandStack);
   1.712 +					htUnitWindows.Add(unit.ID, unitForm);
   1.713 +					unitForm.MdiParent = this.MdiParent;
   1.714 +					unitForm.Closing+=new CancelEventHandler(unitForm_Closing);
   1.715 +					unitForm.Show();
   1.716 +				}
   1.717 +			}
   1.718 +		}
   1.719 +
   1.720 +		private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
   1.721 +		{
   1.722 +			if (obj is Unit)
   1.723 +			{
   1.724 +				Unit unit = (Unit)obj;
   1.725 +				TreeNode node = (TreeNode)htNodes[unit.ID];
   1.726 +				
   1.727 +				if (node!=null)
   1.728 +				{
   1.729 +					node.Text = unit.Name;
   1.730 +				}
   1.731 +			}
   1.732 +		}
   1.733 +
   1.734 +		private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue)
   1.735 +		{
   1.736 +			if (obj is Army)
   1.737 +			{
   1.738 +				Army army = (Army)obj;
   1.739 +				TreeNode node = treeView.Nodes[0];
   1.740 +				
   1.741 +				if (node!=null)
   1.742 +				{
   1.743 +					node.Text = army.Name;
   1.744 +				}
   1.745 +			}
   1.746 +		}
   1.747 +
   1.748 +		private void unitForm_Closing(object sender, CancelEventArgs e)
   1.749 +		{
   1.750 +			if (sender is FrmUnit)
   1.751 +			{
   1.752 +				FrmUnit unitForm = (FrmUnit)sender;
   1.753 +				htUnitWindows.Remove(unitForm.Unit.ID);
   1.754 +			}
   1.755 +		}
   1.756 +
   1.757 +		private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.758 +		{
   1.759 +			TreeNode node = (TreeNode)htNodes[obj.ID];
   1.760 +
   1.761 +			if (node!=null)
   1.762 +			{
   1.763 +				node.Text = obj.Name;
   1.764 +			}
   1.765 +		}
   1.766 +	}
   1.767 +}
     2.1 --- a/FrmSelectSystem.cs	Tue Aug 04 19:40:20 2009 +0000
     2.2 +++ b/FrmSelectSystem.cs	Sun Aug 09 12:05:24 2009 +0000
     2.3 @@ -1,74 +1,74 @@
     2.4 -// This file (FrmSelectSystem.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
     2.5 -//
     2.6 -// 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.
     2.7 -
     2.8 -using System;
     2.9 -using System.IO;
    2.10 -using System.Drawing;
    2.11 -using System.Collections;
    2.12 -using System.ComponentModel;
    2.13 -using System.Windows.Forms;
    2.14 -using IBBoard;
    2.15 -using IBBoard.Lang;
    2.16 -using IBBoard.WarFoundry.API;
    2.17 -using IBBoard.Windows.Forms;
    2.18 -using IBBoard.WarFoundry.API.Objects;
    2.19 -using IBBoard.Windows.Forms.I18N;
    2.20 -
    2.21 -namespace IBBoard.WarFoundry
    2.22 -{
    2.23 -	/// <summary>
    2.24 -	/// Summary description for FrmSelectSystem.
    2.25 -	/// </summary>
    2.26 -	public class FrmSelectSystem : IBBoard.Windows.Forms.IBBForm
    2.27 -	{
    2.28 -		private System.Windows.Forms.ListBox lstSystems;
    2.29 -		private IBBoard.Windows.Forms.IBBLabel lblSystemList;
    2.30 -		/// <summary>
    2.31 -		/// Required designer variable.
    2.32 -		/// </summary>
    2.33 -		private System.ComponentModel.Container components = null;
    2.34 -		private IBBoard.Windows.Forms.IBBButton bttnCancel;
    2.35 -		private IBBoard.Windows.Forms.IBBButton bttnSelectSystem;
    2.36 -		private GameSystem selectedSystem;
    2.37 -
    2.38 -
    2.39 -        public FrmSelectSystem()
    2.40 -		{
    2.41 -			//
    2.42 -			// Required for Windows Form Designer support
    2.43 -			//
    2.44 -			InitializeComponent();
    2.45 -
    2.46 -            ControlTranslator.TranslateControl(this);
    2.47 -
    2.48 -			lstSystems.Items.Clear();
    2.49 -            GameSystem[] systems = WarFoundryLoader.GetDefault().GetGameSystems();
    2.50 -            lstSystems.DataSource = systems;
    2.51 -			lstSystems.DisplayMember = "Name";
    2.52 -		}
    2.53 -
    2.54 -		/// <summary>
    2.55 -		/// Clean up any resources being used.
    2.56 -		/// </summary>
    2.57 -		protected override void Dispose( bool disposing )
    2.58 -		{
    2.59 -			if( disposing )
    2.60 -			{
    2.61 -				if(components != null)
    2.62 -				{
    2.63 -					components.Dispose();
    2.64 -				}
    2.65 -			}
    2.66 -			base.Dispose( disposing );
    2.67 -		}
    2.68 -
    2.69 -		#region Windows Form Designer generated code
    2.70 -		/// <summary>
    2.71 -		/// Required method for Designer support - do not modify
    2.72 -		/// the contents of this method with the code editor.
    2.73 -		/// </summary>
    2.74 -		private void InitializeComponent()
    2.75 +// This file (FrmSelectSystem.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
    2.76 +//
    2.77 +// 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.
    2.78 +
    2.79 +using System;
    2.80 +using System.IO;
    2.81 +using System.Drawing;
    2.82 +using System.Collections;
    2.83 +using System.ComponentModel;
    2.84 +using System.Windows.Forms;
    2.85 +using IBBoard;
    2.86 +using IBBoard.Lang;
    2.87 +using IBBoard.WarFoundry.API;
    2.88 +using IBBoard.Windows.Forms;
    2.89 +using IBBoard.WarFoundry.API.Objects;
    2.90 +using IBBoard.Windows.Forms.I18N;
    2.91 +
    2.92 +namespace IBBoard.WarFoundry
    2.93 +{
    2.94 +	/// <summary>
    2.95 +	/// Summary description for FrmSelectSystem.
    2.96 +	/// </summary>
    2.97 +	public class FrmSelectSystem : IBBoard.Windows.Forms.IBBForm
    2.98 +	{
    2.99 +		private System.Windows.Forms.ListBox lstSystems;
   2.100 +		private IBBoard.Windows.Forms.IBBLabel lblSystemList;
   2.101 +		/// <summary>
   2.102 +		/// Required designer variable.
   2.103 +		/// </summary>
   2.104 +		private System.ComponentModel.Container components = null;
   2.105 +		private IBBoard.Windows.Forms.IBBButton bttnCancel;
   2.106 +		private IBBoard.Windows.Forms.IBBButton bttnSelectSystem;
   2.107 +		private GameSystem selectedSystem;
   2.108 +
   2.109 +
   2.110 +        public FrmSelectSystem()
   2.111 +		{
   2.112 +			//
   2.113 +			// Required for Windows Form Designer support
   2.114 +			//
   2.115 +			InitializeComponent();
   2.116 +
   2.117 +            ControlTranslator.TranslateControl(this);
   2.118 +
   2.119 +			lstSystems.Items.Clear();
   2.120 +            GameSystem[] systems = WarFoundryLoader.GetDefault().GetGameSystems();
   2.121 +            lstSystems.DataSource = systems;
   2.122 +			lstSystems.DisplayMember = "Name";
   2.123 +		}
   2.124 +
   2.125 +		/// <summary>
   2.126 +		/// Clean up any resources being used.
   2.127 +		/// </summary>
   2.128 +		protected override void Dispose( bool disposing )
   2.129 +		{
   2.130 +			if( disposing )
   2.131 +			{
   2.132 +				if(components != null)
   2.133 +				{
   2.134 +					components.Dispose();
   2.135 +				}
   2.136 +			}
   2.137 +			base.Dispose( disposing );
   2.138 +		}
   2.139 +
   2.140 +		#region Windows Form Designer generated code
   2.141 +		/// <summary>
   2.142 +		/// Required method for Designer support - do not modify
   2.143 +		/// the contents of this method with the code editor.
   2.144 +		/// </summary>
   2.145 +		private void InitializeComponent()
   2.146  		{
   2.147  			this.lstSystems = new System.Windows.Forms.ListBox();
   2.148  			this.bttnSelectSystem = new IBBoard.Windows.Forms.IBBButton();
   2.149 @@ -134,35 +134,35 @@
   2.150  			this.Text = "FrmSelectSystem";
   2.151  			this.ResumeLayout(false);
   2.152  
   2.153 -		}
   2.154 -		#endregion
   2.155 -
   2.156 -		private void lstSystems_SelectedIndexChanged(object sender, System.EventArgs e)
   2.157 -		{
   2.158 -			bttnSelectSystem.Enabled = (lstSystems.SelectedIndex>-1);
   2.159 -		}
   2.160 -
   2.161 -		private void bttnSelectSystem_Click(object sender, System.EventArgs e)
   2.162 -		{
   2.163 -            selectedSystem = (GameSystem) lstSystems.SelectedItem;
   2.164 -            this.DialogResult = DialogResult.OK;
   2.165 -			this.Close();
   2.166 -		}
   2.167 -
   2.168 -		private void bttnCancel_Click(object sender, System.EventArgs e)
   2.169 -		{
   2.170 -			this.DialogResult = DialogResult.Cancel;
   2.171 -			this.Close();
   2.172 -		}
   2.173 -
   2.174 -		public GameSystem GameSystem
   2.175 -		{
   2.176 -			get { return selectedSystem; }
   2.177 +		}
   2.178 +		#endregion
   2.179 +
   2.180 +		private void lstSystems_SelectedIndexChanged(object sender, System.EventArgs e)
   2.181 +		{
   2.182 +			bttnSelectSystem.Enabled = (lstSystems.SelectedIndex>-1);
   2.183 +		}
   2.184 +
   2.185 +		private void bttnSelectSystem_Click(object sender, System.EventArgs e)
   2.186 +		{
   2.187 +            selectedSystem = (GameSystem) lstSystems.SelectedItem;
   2.188 +            this.DialogResult = DialogResult.OK;
   2.189 +			this.Close();
   2.190 +		}
   2.191 +
   2.192 +		private void bttnCancel_Click(object sender, System.EventArgs e)
   2.193 +		{
   2.194 +			this.DialogResult = DialogResult.Cancel;
   2.195 +			this.Close();
   2.196 +		}
   2.197 +
   2.198 +		public GameSystem GameSystem
   2.199 +		{
   2.200 +			get { return selectedSystem; }
   2.201  		}
   2.202  
   2.203  		private void lstSystems_DoubleClick(object sender, EventArgs e)
   2.204  		{
   2.205  			bttnSelectSystem_Click(null, null);
   2.206 -		}
   2.207 -	}
   2.208 -}
   2.209 +		}
   2.210 +	}
   2.211 +}