changeset 45:1c74b51abac1

Re #137: Remove use of old collections * Replace hashtables with dictionaries in FrmArmyTree Also: * Correct some delegate method definitions * Rename a private "remove" method so that name doesn't only differ by capitalisation
author IBBoard <dev@ibboard.co.uk>
date Wed, 09 Sep 2009 19:56:24 +0000
parents 1486ccd744dc
children 1576f669b3eb
files FrmArmyTree.cs
diffstat 1 files changed, 15 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/FrmArmyTree.cs	Wed Sep 09 19:37:14 2009 +0000
     1.2 +++ b/FrmArmyTree.cs	Wed Sep 09 19:56:24 2009 +0000
     1.3 @@ -4,7 +4,7 @@
     1.4  
     1.5  using System;
     1.6  using System.Drawing;
     1.7 -using System.Collections;
     1.8 +using System.Collections.Generic;
     1.9  using System.ComponentModel;
    1.10  using System.Windows.Forms;
    1.11  using IBBoard.Commands;
    1.12 @@ -25,11 +25,11 @@
    1.13  		/// Required designer variable.
    1.14  		/// </summary>
    1.15  		private System.ComponentModel.Container components = null;
    1.16 -		private Hashtable htNodes;
    1.17 +		private Dictionary<string, TreeNode> htNodes;
    1.18  		private System.Windows.Forms.ContextMenu contextMenu;
    1.19  		private System.Windows.Forms.MenuItem miDelete;
    1.20  		private System.Windows.Forms.MenuItem miEdit;
    1.21 -		private Hashtable htUnitWindows;
    1.22 +		private Dictionary<string, FrmUnit> htUnitWindows;
    1.23  		
    1.24  		private ObjectAddDelegate UnitAddedMethod;
    1.25  		private ObjectRemoveDelegate UnitRemovedMethod;
    1.26 @@ -45,8 +45,8 @@
    1.27  			UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
    1.28  			ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
    1.29  			TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
    1.30 -			htNodes = new Hashtable();
    1.31 -			htUnitWindows = new Hashtable();
    1.32 +			htNodes = new Dictionary<string, TreeNode>();
    1.33 +			htUnitWindows = new Dictionary<string, FrmUnit>();
    1.34  			this.Name = "ArmyTree";			
    1.35  			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
    1.36  		}
    1.37 @@ -139,9 +139,7 @@
    1.38  		{
    1.39  			htNodes.Clear();
    1.40  			treeView.Nodes.Clear();
    1.41 -			ICollection unitFormsCollection = htUnitWindows.Values;
    1.42 -			FrmUnit[] unitForms = new FrmUnit[unitFormsCollection.Count];
    1.43 -			unitFormsCollection.CopyTo(unitForms, 0);
    1.44 +			FrmUnit[] unitForms = DictionaryUtils.ToArray(htUnitWindows);
    1.45  
    1.46  			foreach (FrmUnit window in unitForms)
    1.47  			{
    1.48 @@ -220,32 +218,32 @@
    1.49  
    1.50  			SetArmy(newArmy);
    1.51  		}
    1.52 -		
    1.53 -		private void AddUnit(object obj)
    1.54 +
    1.55 +		private void AddUnit(WarFoundryObject obj)
    1.56  		{
    1.57  			if (obj is Unit)
    1.58  			{
    1.59  				Unit unit = (Unit)obj;
    1.60  				ArmyCategory cat = unit.Category;
    1.61 -				TreeNode parent = (TreeNode)htNodes[cat.ID];
    1.62 +				TreeNode parent = htNodes[cat.ID];
    1.63  				TreeNode unitNode = createTreeNode(unit);
    1.64  				parent.Nodes.Add(unitNode);
    1.65  				parent.Expand(); //make sure it's expanded
    1.66  			}
    1.67  		}
    1.68  
    1.69 -		private void RemoveUnit(object obj)
    1.70 +		private void RemoveUnit(WarFoundryObject obj)
    1.71  		{
    1.72  			if (obj is Unit)
    1.73  			{
    1.74  				Unit unit = (Unit)obj;
    1.75 -				removeUnit(unit);
    1.76 +				RemoveUnitFromTree(unit);
    1.77  			}
    1.78  		}
    1.79  
    1.80 -		private void removeUnit(Unit unit)
    1.81 +		private void RemoveUnitFromTree(Unit unit)
    1.82  		{
    1.83 -			TreeNode unitNode = (TreeNode)htNodes[unit.ID];
    1.84 +			TreeNode unitNode = htNodes[unit.ID];
    1.85  			unit.NameChanged-= UnitNameChangedMethod;
    1.86  
    1.87  			if (unitNode!=null)
    1.88 @@ -341,7 +339,7 @@
    1.89  			if (obj is Unit)
    1.90  			{
    1.91  				Unit unit = (Unit)obj;
    1.92 -				TreeNode node = (TreeNode)htNodes[unit.ID];
    1.93 +				TreeNode node = htNodes[unit.ID];
    1.94  				
    1.95  				if (node!=null)
    1.96  				{
    1.97 @@ -375,7 +373,7 @@
    1.98  
    1.99  		private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.100  		{
   1.101 -			TreeNode node = (TreeNode)htNodes[obj.ID];
   1.102 +			TreeNode node = htNodes[obj.ID];
   1.103  
   1.104  			if (node!=null)
   1.105  			{