Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
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 wrap: on
line diff
--- 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. /// </summary> private System.ComponentModel.Container components = null; - private Hashtable htNodes; + private Dictionary<string, TreeNode> htNodes; private System.Windows.Forms.ContextMenu contextMenu; private System.Windows.Forms.MenuItem miDelete; private System.Windows.Forms.MenuItem miEdit; - private Hashtable htUnitWindows; + private Dictionary<string, FrmUnit> 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<string, TreeNode>(); + htUnitWindows = new Dictionary<string, FrmUnit>(); 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) {