diff FrmMainWindow.cs @ 15:85db2c9a1546

Fixes #95: Can't re-open GTK# tabs * Make Unit for UnitDisplayWidget visible as a property * Hook in to Destroyed event of UnitDisplayWidget to remove it from the map of tabs
author IBBoard <dev@ibboard.co.uk>
date Sat, 27 Jun 2009 20:13:21 +0000
parents abbf8a3ac431
children 7653fab9d70e
line wrap: on
line diff
--- a/FrmMainWindow.cs	Sat Jun 27 19:39:41 2009 +0000
+++ b/FrmMainWindow.cs	Sat Jun 27 20:13:21 2009 +0000
@@ -130,7 +130,6 @@
 			PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged);
 			FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement);
 			UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged);
-			logger.Debug("Initialising complete - trying to load default army or system");
 			
 			//FIXME: Temporary hack to add paths and factories
 			WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + "data"));
@@ -147,6 +146,8 @@
 			{
 				WarFoundryLoader.GetDefault().RegisterNonNativeFactory((INonNativeWarFoundryFactory)factory);
 			}
+			
+			logger.Debug("Initialising complete - seeing if we can load default army or system");
 								
 			if (args.Length == 1)
 			{
@@ -918,6 +919,7 @@
 					widget = new UnitDisplayWidget(unit, CommandStack);
 					logger.Debug("Adding page for "+unit.Name);
 					unitToWidgetMap[unit] = widget;
+					widget.Destroyed+= new EventHandler(UnitWidgetDestroyed);
 					int pageNum = NotebookUtil.AddPageToNotebookWithCloseButton(unitsNotebook, widget, unit.Name);
 					logger.Debug("Page added at index "+pageNum);
 					unitsNotebook.ShowAll();
@@ -925,5 +927,13 @@
 				}
 			}
 		}
+
+		private void UnitWidgetDestroyed(object sender, EventArgs e)
+		{
+			if (sender is UnitDisplayWidget)
+			{
+				unitToWidgetMap.Remove(((UnitDisplayWidget)sender).Unit);
+			}
+		}
 	}
 }