changeset 49:93b3d23147ba

Fixes #160: Army tree is visible when no army is available * Show/hide Army Tree depending on whether we have an army or not Also: * Tidy up FrmArmyTree code to remove "ht" prefix on dictionaries and to fix some mistmatches of naming conventions
author IBBoard <dev@ibboard.co.uk>
date Mon, 14 Sep 2009 20:43:52 +0000
parents cf644b2c65e6
children c972fb283675
files FrmArmyTree.cs FrmMain.cs
diffstat 2 files changed, 23 insertions(+), 22 deletions(-) [+]
line diff
     1.1 --- a/FrmArmyTree.cs	Sun Sep 13 19:03:37 2009 +0000
     1.2 +++ b/FrmArmyTree.cs	Mon Sep 14 20:43:52 2009 +0000
     1.3 @@ -25,11 +25,11 @@
     1.4  		/// Required designer variable.
     1.5  		/// </summary>
     1.6  		private System.ComponentModel.Container components = null;
     1.7 -		private Dictionary<string, TreeNode> htNodes;
     1.8 +		private Dictionary<string, TreeNode> nodes;
     1.9  		private System.Windows.Forms.ContextMenu contextMenu;
    1.10  		private System.Windows.Forms.MenuItem miDelete;
    1.11  		private System.Windows.Forms.MenuItem miEdit;
    1.12 -		private Dictionary<string, FrmUnit> htUnitWindows;
    1.13 +		private Dictionary<string, FrmUnit> unitWindows;
    1.14  		
    1.15  		private ObjectAddDelegate UnitAddedMethod;
    1.16  		private ObjectRemoveDelegate UnitRemovedMethod;
    1.17 @@ -45,8 +45,8 @@
    1.18  			UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
    1.19  			ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
    1.20  			TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
    1.21 -			htNodes = new Dictionary<string, TreeNode>();
    1.22 -			htUnitWindows = new Dictionary<string, FrmUnit>();
    1.23 +			nodes = new Dictionary<string, TreeNode>();
    1.24 +			unitWindows = new Dictionary<string, FrmUnit>();
    1.25  			this.Name = "ArmyTree";			
    1.26  			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
    1.27  		}
    1.28 @@ -137,16 +137,16 @@
    1.29  
    1.30  		private void ClearArmy()
    1.31  		{
    1.32 -			htNodes.Clear();
    1.33 +			nodes.Clear();
    1.34  			treeView.Nodes.Clear();
    1.35 -			FrmUnit[] unitForms = DictionaryUtils.ToArray(htUnitWindows);
    1.36 +			FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows);
    1.37  
    1.38  			foreach (FrmUnit window in unitForms)
    1.39  			{
    1.40  				window.Close();
    1.41  			}
    1.42  
    1.43 -			htUnitWindows.Clear();
    1.44 +			unitWindows.Clear();
    1.45  		}
    1.46  
    1.47  		private void SetArmy(Army army)
    1.48 @@ -174,7 +174,7 @@
    1.49  					temp = new TreeNode(cats[i].Name, unitNodes);
    1.50  					temp.Tag = cats[i];
    1.51  					catNodes[i] = temp;
    1.52 -					htNodes[cats[i].ID] = temp;
    1.53 +					nodes[cats[i].ID] = temp;
    1.54  				}
    1.55  
    1.56  				TreeNode root = new TreeNode(army.Name, catNodes);
    1.57 @@ -189,7 +189,7 @@
    1.58  			TreeNode temp = new TreeNode(unit.Name);
    1.59  			temp.Tag = unit;
    1.60  			unit.NameChanged+= UnitNameChangedMethod;
    1.61 -			htNodes[unit.ID] = temp;
    1.62 +			nodes[unit.ID] = temp;
    1.63  			return temp;
    1.64  		}
    1.65  
    1.66 @@ -225,7 +225,7 @@
    1.67  			{
    1.68  				Unit unit = (Unit)obj;
    1.69  				ArmyCategory cat = unit.Category;
    1.70 -				TreeNode parent = htNodes[cat.ID];
    1.71 +				TreeNode parent = nodes[cat.ID];
    1.72  				TreeNode unitNode = createTreeNode(unit);
    1.73  				parent.Nodes.Add(unitNode);
    1.74  				parent.Expand(); //make sure it's expanded
    1.75 @@ -243,13 +243,13 @@
    1.76  
    1.77  		private void RemoveUnitFromTree(Unit unit)
    1.78  		{
    1.79 -			TreeNode unitNode = htNodes[unit.ID];
    1.80 +			TreeNode unitNode = nodes[unit.ID];
    1.81  			unit.NameChanged-= UnitNameChangedMethod;
    1.82  
    1.83  			if (unitNode!=null)
    1.84  			{
    1.85  				unitNode.Remove();
    1.86 -				htNodes.Remove(unit.ID);
    1.87 +				nodes.Remove(unit.ID);
    1.88  			}
    1.89  		}
    1.90  
    1.91 @@ -303,15 +303,15 @@
    1.92  
    1.93  		private void miEdit_Click(object sender, System.EventArgs e)
    1.94  		{	
    1.95 -			editUnit();
    1.96 +			EditUnit();
    1.97  		}
    1.98  
    1.99  		private void treeView_DoubleClick(object sender, System.EventArgs e)
   1.100  		{
   1.101 -			editUnit();			
   1.102 +			EditUnit();			
   1.103  		}
   1.104  
   1.105 -		private void editUnit()
   1.106 +		private void EditUnit()
   1.107  		{
   1.108  			TreeNode selected = treeView.SelectedNode;
   1.109  
   1.110 @@ -319,14 +319,14 @@
   1.111  			{
   1.112  				Unit unit = (Unit)selected.Tag;
   1.113  
   1.114 -				if (htUnitWindows.ContainsKey(unit.ID))
   1.115 +				if (unitWindows.ContainsKey(unit.ID))
   1.116  				{
   1.117 -					((FrmUnit)htUnitWindows[unit.ID]).Focus();
   1.118 +					unitWindows[unit.ID].Focus();
   1.119  				}
   1.120  				else
   1.121  				{
   1.122  					FrmUnit unitForm = new FrmUnit(unit, commandStack);
   1.123 -					htUnitWindows.Add(unit.ID, unitForm);
   1.124 +					unitWindows.Add(unit.ID, unitForm);
   1.125  					unitForm.MdiParent = this.MdiParent;
   1.126  					unitForm.Closing+=new CancelEventHandler(unitForm_Closing);
   1.127  					unitForm.Show();
   1.128 @@ -339,7 +339,7 @@
   1.129  			if (obj is Unit)
   1.130  			{
   1.131  				Unit unit = (Unit)obj;
   1.132 -				TreeNode node = htNodes[unit.ID];
   1.133 +				TreeNode node = nodes[unit.ID];
   1.134  				
   1.135  				if (node!=null)
   1.136  				{
   1.137 @@ -367,13 +367,13 @@
   1.138  			if (sender is FrmUnit)
   1.139  			{
   1.140  				FrmUnit unitForm = (FrmUnit)sender;
   1.141 -				htUnitWindows.Remove(unitForm.Unit.ID);
   1.142 +				unitWindows.Remove(unitForm.Unit.ID);
   1.143  			}
   1.144  		}
   1.145  
   1.146  		private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.147  		{
   1.148 -			TreeNode node = htNodes[obj.ID];
   1.149 +			TreeNode node = nodes[obj.ID];
   1.150  
   1.151  			if (node!=null)
   1.152  			{
     2.1 --- a/FrmMain.cs	Sun Sep 13 19:03:37 2009 +0000
     2.2 +++ b/FrmMain.cs	Mon Sep 14 20:43:52 2009 +0000
     2.3 @@ -142,7 +142,6 @@
     2.4  
     2.5  			armyTree = new FrmArmyTree(CommandStack);
     2.6  			armyTree.MdiParent = this;
     2.7 -			armyTree.Show();
     2.8  			armyTree.StartPosition = FormStartPosition.Manual;
     2.9  			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
    2.10              ControlTranslator.TranslateControl(armyTree);
    2.11 @@ -851,6 +850,7 @@
    2.12  				miCloseArmy.Enabled = false;
    2.13  				miExportArmyAs.Enabled = false;
    2.14  				DisableCategoryButtons();
    2.15 +				armyTree.Hide();
    2.16  			}
    2.17  			else
    2.18  			{
    2.19 @@ -862,6 +862,7 @@
    2.20  				miCloseArmy.Enabled = true;
    2.21  				miExportArmyAs.Enabled = true;
    2.22  				EnableCategoryButtons();
    2.23 +				armyTree.Show();
    2.24  
    2.25  				if (newArmy.Race.HasCategoryOverrides())
    2.26  				{