# HG changeset patch # User IBBoard # Date 1252526184 0 # Node ID 1c74b51abac1293d45e1ade8faacefb971b96a2e # Parent 1486ccd744dc1cc714eab7e4e3649f611e60f397 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 diff -r 1486ccd744dc -r 1c74b51abac1 FrmArmyTree.cs --- a/FrmArmyTree.cs Wed Sep 09 19:37:14 2009 +0000 +++ b/FrmArmyTree.cs Wed Sep 09 19:56:24 2009 +0000 @@ -4,7 +4,7 @@ using System; using System.Drawing; -using System.Collections; +using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using IBBoard.Commands; @@ -25,11 +25,11 @@ /// Required designer variable. /// private System.ComponentModel.Container components = null; - private Hashtable htNodes; + private Dictionary htNodes; private System.Windows.Forms.ContextMenu contextMenu; private System.Windows.Forms.MenuItem miDelete; private System.Windows.Forms.MenuItem miEdit; - private Hashtable htUnitWindows; + private Dictionary htUnitWindows; private ObjectAddDelegate UnitAddedMethod; private ObjectRemoveDelegate UnitRemovedMethod; @@ -45,8 +45,8 @@ UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName); ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName); TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged); - htNodes = new Hashtable(); - htUnitWindows = new Hashtable(); + htNodes = new Dictionary(); + htUnitWindows = new Dictionary(); this.Name = "ArmyTree"; WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged); } @@ -139,9 +139,7 @@ { htNodes.Clear(); treeView.Nodes.Clear(); - ICollection unitFormsCollection = htUnitWindows.Values; - FrmUnit[] unitForms = new FrmUnit[unitFormsCollection.Count]; - unitFormsCollection.CopyTo(unitForms, 0); + FrmUnit[] unitForms = DictionaryUtils.ToArray(htUnitWindows); foreach (FrmUnit window in unitForms) { @@ -220,32 +218,32 @@ SetArmy(newArmy); } - - private void AddUnit(object obj) + + private void AddUnit(WarFoundryObject obj) { if (obj is Unit) { Unit unit = (Unit)obj; ArmyCategory cat = unit.Category; - TreeNode parent = (TreeNode)htNodes[cat.ID]; + TreeNode parent = htNodes[cat.ID]; TreeNode unitNode = createTreeNode(unit); parent.Nodes.Add(unitNode); parent.Expand(); //make sure it's expanded } } - private void RemoveUnit(object obj) + private void RemoveUnit(WarFoundryObject obj) { if (obj is Unit) { Unit unit = (Unit)obj; - removeUnit(unit); + RemoveUnitFromTree(unit); } } - private void removeUnit(Unit unit) + private void RemoveUnitFromTree(Unit unit) { - TreeNode unitNode = (TreeNode)htNodes[unit.ID]; + TreeNode unitNode = htNodes[unit.ID]; unit.NameChanged-= UnitNameChangedMethod; if (unitNode!=null) @@ -341,7 +339,7 @@ if (obj is Unit) { Unit unit = (Unit)obj; - TreeNode node = (TreeNode)htNodes[unit.ID]; + TreeNode node = htNodes[unit.ID]; if (node!=null) { @@ -375,7 +373,7 @@ private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue) { - TreeNode node = (TreeNode)htNodes[obj.ID]; + TreeNode node = htNodes[obj.ID]; if (node!=null) {