diff FrmMain.cs @ 159:964f946d3cac

Fixes #288: WarFoundry WinForms assumes that army tree will be open * Add a getter method that returns a new army tree if the old one was disposed or non exists * Unhook the army tree from the army changed events on dispose
author IBBoard <dev@ibboard.co.uk>
date Fri, 04 Jun 2010 19:31:02 +0000
parents 0ae6aff8c862
children 7de7890bf079
line wrap: on
line diff
--- a/FrmMain.cs	Mon May 31 20:09:12 2010 +0000
+++ b/FrmMain.cs	Fri Jun 04 19:31:02 2010 +0000
@@ -149,11 +149,6 @@
 			sbErrorPanel.Color = Color.Red;
 			sbPointsPanel.ToolTipText = Translation.GetTranslation("statusPanelPointsToolTip", "total points value");
 
-			armyTree = new FrmArmyTree(CommandStack);
-			armyTree.MdiParent = this;
-			armyTree.StartPosition = FormStartPosition.Manual;
-			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
-
 			// hack to load default files
 			WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
 			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
@@ -161,6 +156,24 @@
 			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
 		}
 
+		private FrmArmyTree GetArmyTree()
+		{
+			if (armyTree == null || armyTree.IsDisposed)
+			{
+				CreateArmyTree();
+			}
+
+			return armyTree;
+		}
+
+		private void CreateArmyTree()
+		{
+			armyTree = new FrmArmyTree(CommandStack);
+			armyTree.MdiParent = this;
+			armyTree.StartPosition = FormStartPosition.Manual;
+			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
+		}
+
 		private void TranslateControls()
 		{
 			ControlTranslator.TranslateControls(Controls);
@@ -924,7 +937,7 @@
 			miCloseArmy.Enabled = false;
 			miExportArmyAs.Enabled = false;
 			DisableCategoryButtons();
-			armyTree.Hide();
+			GetArmyTree().Hide();
 		}
 
 		private void SetNonNullArmyState(Army newArmy)
@@ -934,7 +947,7 @@
 			miSaveArmyAs.Enabled = true;
 			miCloseArmy.Enabled = true;
 			miExportArmyAs.Enabled = true;
-			armyTree.Show();
+			GetArmyTree().Show();
 		}
 
 		private void SetCategoryButtons(Category[] cats)