changeset 21:2cf1af4c9baf

Re #53: Add XML saver * Add initial stub behind "save as" that saves to a fixed location
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Aug 2009 19:10:37 +0000
parents 1e301a6234fd
children 40485c6e5cb0
files FrmMainWindow.cs
diffstat 1 files changed, 115 insertions(+), 135 deletions(-) [+]
line diff
     1.1 --- a/FrmMainWindow.cs	Sat Aug 15 10:50:07 2009 +0000
     1.2 +++ b/FrmMainWindow.cs	Mon Aug 17 19:10:37 2009 +0000
     1.3 @@ -27,7 +27,7 @@
     1.4  using log4net;
     1.5  
     1.6  namespace IBBoard.WarFoundry.GTK
     1.7 -{	
     1.8 +{
     1.9  	public partial class FrmMainWindow: Gtk.Window
    1.10  	{
    1.11  		private static readonly string AppTitle = "WarFoundry";
    1.12 @@ -45,14 +45,14 @@
    1.13  		private DoubleValChangedDelegate PointsValueChangedMethod;
    1.14  		private FailedUnitRequirementDelegate FailedUnitRequirementMethod;
    1.15  		private StringValChangedDelegate UnitNameChangedMethod;
    1.16 -		
    1.17 +
    1.18  		private GameSystem system;
    1.19  		private string loadedArmyPath;
    1.20 -		
    1.21 +
    1.22  		private MenuToolButton undoMenuButton, redoMenuButton;
    1.23 -		
    1.24 +
    1.25  		public static void Main (string[] args)
    1.26 -		{			
    1.27 +		{
    1.28  			try
    1.29  			{
    1.30  				Application.Init();
    1.31 @@ -66,12 +66,12 @@
    1.32  				LogManager.GetLogger(typeof(FrmMainWindow)).Fatal("("+ex.GetType().Name+") "+ex.Message + Environment.NewLine + ex.StackTrace);
    1.33  			}
    1.34  		}
    1.35 -		
    1.36 +
    1.37  		public FrmMainWindow() : this(new string[0])
    1.38  		{
    1.39  			//Do nothing extra
    1.40  		}
    1.41 -			
    1.42 +
    1.43  		public FrmMainWindow (string[] args): base (Gtk.WindowType.Toplevel)
    1.44  		{
    1.45  			logger.Info("Opening FrmMainWindow");
    1.46 @@ -90,7 +90,7 @@
    1.47  			toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX-1]);
    1.48  			toolbar.Remove(toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX-2]);
    1.49  			toolbar.ShowAll();
    1.50 -			
    1.51 +
    1.52  			Title = AppTitle;
    1.53  			TreeViewColumn mainColumn = new TreeViewColumn ();
    1.54  			mainColumn.Title = "Army Categories";
    1.55 @@ -102,7 +102,7 @@
    1.56  			logger.Debug("Loading preferences");
    1.57  			Preferences = new Preferences("WarFoundryGTK");
    1.58  			logger.Debug("Loading translations");
    1.59 -			
    1.60 +
    1.61  			try
    1.62  			{
    1.63  				Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
    1.64 @@ -115,7 +115,7 @@
    1.65  				dialog.Run();
    1.66  				dialog.Destroy();
    1.67  			}
    1.68 -			
    1.69 +
    1.70  			logger.Debug("Initialising");
    1.71  			commandStack = new CommandStack();
    1.72  			commandStack.CommandStackUpdated+=new MethodInvoker(commandStack_CommandStackUpdated);
    1.73 @@ -128,19 +128,20 @@
    1.74  			PointsValueChangedMethod = new DoubleValChangedDelegate(OnPointsValueChanged);
    1.75  			FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(OnFailedUnitRequirement);
    1.76  			UnitNameChangedMethod = new StringValChangedDelegate(OnUnitNameChanged);
    1.77 -			
    1.78 +
    1.79  			//FIXME: Temporary hack to add paths and factories before we get preferences and plugins
    1.80  			WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + "data"));
    1.81  			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
    1.82  			WarFoundryLoader.GetDefault().RegisterNonNativeFactory(RollcallFactory.GetFactory());
    1.83 -			
    1.84 +			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
    1.85 +
    1.86  			logger.Debug("Initialising complete - seeing if we can load default army or system");
    1.87 -								
    1.88 +
    1.89  			if (args.Length == 1)
    1.90  			{
    1.91 -				logger.Debug("Attempting to load from file");				
    1.92 +				logger.Debug("Attempting to load from file");
    1.93  				FileInfo file = new FileInfo(args[0]);
    1.94 -				
    1.95 +
    1.96  				try
    1.97  				{
    1.98  					ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file);
    1.99 @@ -150,7 +151,7 @@
   1.100  						List<IWarFoundryObject> objectList = new List<IWarFoundryObject>();
   1.101  						objectList.AddRange(objects);
   1.102  						IWarFoundryObject loadedObject = objectList[0];
   1.103 -						
   1.104 +
   1.105  						if (loadedObject is Army)
   1.106  						{
   1.107  							WarFoundryCore.CurrentArmy = (Army)loadedObject;
   1.108 @@ -177,7 +178,7 @@
   1.109  				{
   1.110  					logger.Debug("Attempting to load current game system from properties");
   1.111  					GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
   1.112 -					
   1.113 +
   1.114  					if (sys!=null)
   1.115  					{
   1.116  						WarFoundryCore.CurrentGameSystem = sys;
   1.117 @@ -186,16 +187,16 @@
   1.118  				}
   1.119  			}
   1.120  		}
   1.121 -		
   1.122 +
   1.123  		private void RenderCategoryTreeObjectName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
   1.124  		{
   1.125  			object o = model.GetValue(iter, 0);
   1.126 -			
   1.127 +
   1.128  			if (o is ArmyCategory)
   1.129  			{
   1.130  				ArmyCategory c = (ArmyCategory)o;
   1.131  				string name = "";
   1.132 -				
   1.133 +
   1.134  				if (Preferences.GetBooleanProperty("ShowCatPercentage"))
   1.135  				{
   1.136  					name = Translation.GetTranslation("categoryTreeCatName", "{0} - {1}pts", c.Name, c.PointsTotal);
   1.137 @@ -204,7 +205,7 @@
   1.138  				{
   1.139  					name = Translation.GetTranslation("categoryTreeCatNamePercentage", "{0} - {1}pts ({2}%)", c.Name, c.PointsTotal, (c.ParentArmy.PointsTotal > 0 ? Math.Round((c.PointsTotal / c.ParentArmy.PointsTotal) * 100) : 0));
   1.140  				}
   1.141 -				
   1.142 +
   1.143  				(cell as CellRendererText).Text = name;
   1.144  			}
   1.145  			else if (o is IBBoard.WarFoundry.API.Objects.Unit)
   1.146 @@ -214,46 +215,46 @@
   1.147  				(cell as CellRendererText).Text = name;
   1.148  			}
   1.149  		}
   1.150 -		
   1.151 +
   1.152  		private void OnWindowDestroyed(object source, EventArgs args)
   1.153  		{
   1.154  			logger.Info("Exiting");
   1.155  			Application.Quit();
   1.156  		}
   1.157 -		
   1.158 +
   1.159  		private void OnUnitNameChanged(WarFoundryObject val, string oldValue, string newValue)
   1.160  		{
   1.161  			IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)val;
   1.162  			UnitDisplayWidget widget;
   1.163  			unitToWidgetMap.TryGetValue(unit, out widget);
   1.164 -			
   1.165 +
   1.166  			if (widget!=null)
   1.167  			{
   1.168  				unitsNotebook.SetTabLabelText(widget, newValue);
   1.169  			}
   1.170  		}
   1.171 -		
   1.172 +
   1.173  		private void OnUnitAdded(WarFoundryObject val)
   1.174  		{
   1.175  			IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)val;
   1.176  			unit.NameChanged+= UnitNameChangedMethod;
   1.177  			AddUnitToTree(unit);
   1.178  		}
   1.179 -		
   1.180 +
   1.181  		private void AddUnitToTree(IBBoard.WarFoundry.API.Objects.Unit unit)
   1.182  		{
   1.183  			TreeStore model = (TreeStore)treeUnits.Model;
   1.184  			TreeIter iter;
   1.185  			model.GetIterFirst(out iter);
   1.186 -			
   1.187 +
   1.188  			do
   1.189  			{
   1.190  				object obj = model.GetValue(iter, 0);
   1.191 -				
   1.192 +
   1.193  				if (obj is ArmyCategory)
   1.194  				{
   1.195  					ArmyCategory cat = (ArmyCategory)obj;
   1.196 -					
   1.197 +
   1.198  					if (cat.Equals(unit.Category))
   1.199  					{
   1.200  						model.AppendValues(iter, unit);
   1.201 @@ -264,40 +265,40 @@
   1.202  			}
   1.203  			while (model.IterNext(ref iter));
   1.204  		}
   1.205 -		
   1.206 +
   1.207  		private void OnUnitRemoved(WarFoundryObject obj)
   1.208  		{
   1.209  			IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj;
   1.210  			unit.NameChanged-= UnitNameChangedMethod;
   1.211  			RemoveUnitFromTree(unit);
   1.212 -			
   1.213 +
   1.214  			//See if unit has a tab open and close it if it does
   1.215  		}
   1.216 -		
   1.217 +
   1.218  		private void RemoveUnitFromTree(IBBoard.WarFoundry.API.Objects.Unit unit)
   1.219  		{
   1.220  			TreeStore model = (TreeStore)treeUnits.Model;
   1.221  			TreeIter iter;
   1.222  			model.GetIterFirst(out iter);
   1.223  			bool removed = false;
   1.224 -			
   1.225 +
   1.226  			do
   1.227  			{
   1.228  				object obj = model.GetValue(iter, 0);
   1.229 -				
   1.230 +
   1.231  				if (obj is ArmyCategory)
   1.232  				{
   1.233  					ArmyCategory cat = (ArmyCategory)obj;
   1.234 -					
   1.235 +
   1.236  					if (unit.Category == null || cat.Equals(unit.Category))
   1.237  					{
   1.238  						TreeIter innerIter;
   1.239  						model.IterChildren(out innerIter, iter);
   1.240 -						
   1.241 +
   1.242  						do
   1.243  						{
   1.244  							object innerObj = model.GetValue(innerIter, 0);
   1.245 -							
   1.246 +
   1.247  							if (unit.Equals(innerObj))
   1.248  							{
   1.249  								model.Remove(ref innerIter);
   1.250 @@ -306,7 +307,7 @@
   1.251  							}
   1.252  						}
   1.253  						while (model.IterNext(ref innerIter));
   1.254 -						
   1.255 +
   1.256  						if (removed)
   1.257  						{
   1.258  							break;
   1.259 @@ -316,28 +317,28 @@
   1.260  			}
   1.261  			while (model.IterNext(ref iter));
   1.262  		}
   1.263 -		
   1.264 +
   1.265  		private void OnPointsValueChanged(WarFoundryObject obj, double before, double after)
   1.266  		{
   1.267  			//Set points in panel
   1.268  		}
   1.269 -		
   1.270 +
   1.271  		private void OnFailedUnitRequirement(List<FailedUnitRequirement> failedRequirement)
   1.272  		{
   1.273  			//Show error message in panel
   1.274  		}
   1.275 -		
   1.276 +
   1.277  		public Preferences Preferences
   1.278  		{
   1.279  			get { return preferences; }
   1.280 -			set { preferences = value; }		
   1.281 +			set { preferences = value; }
   1.282  		}
   1.283 -		
   1.284 +
   1.285  		/*public AbstractNativeWarFoundryFactory Factory
   1.286  		{
   1.287  			get { return WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(Constants.ExecutablePath, factoryType); }
   1.288  		}*/
   1.289 -		
   1.290 +
   1.291  		protected void OnDeleteEvent (object sender, DeleteEventArgs a)
   1.292  		{
   1.293  			Application.Quit ();
   1.294 @@ -382,37 +383,37 @@
   1.295  		{
   1.296  			SaveCurrentArmy();
   1.297  		}
   1.298 -		
   1.299 +
   1.300  		protected virtual void OnAddUnitActivated(object sender, System.EventArgs e)
   1.301  		{
   1.302  			if (sender is ToolButton)
   1.303  			{
   1.304  				Category cat = null;
   1.305  				categoryMap.TryGetValue((ToolButton)sender, out cat);
   1.306 -				
   1.307 +
   1.308  				if (cat!=null)
   1.309  				{
   1.310  					logger.DebugFormat("Show FrmNewUnit for {0}", cat.Name);
   1.311  					FrmNewUnit newUnit = new FrmNewUnit(WarFoundryCore.CurrentArmy.Race, cat, WarFoundryCore.CurrentArmy);
   1.312  					ResponseType response = (ResponseType)newUnit.Run();
   1.313  					newUnit.Hide();
   1.314 -					
   1.315 +
   1.316  					if (response==ResponseType.Ok)
   1.317  					{
   1.318  						CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(cat));
   1.319  						commandStack.Execute(cmd);
   1.320  					}
   1.321 -					
   1.322 +
   1.323  					newUnit.Dispose();
   1.324  				}
   1.325  			}
   1.326  		}
   1.327 -		
   1.328 +
   1.329  		public CommandStack CommandStack
   1.330  		{
   1.331  			get { return commandStack; }
   1.332  		}
   1.333 -		
   1.334 +
   1.335  		private void SetAppTitle()
   1.336  		{
   1.337  			if (WarFoundryCore.CurrentArmy!=null)
   1.338 @@ -428,7 +429,7 @@
   1.339  				Title = AppTitle;
   1.340  			}
   1.341  		}
   1.342 -		
   1.343 +
   1.344  		private void OnGameSystemChanged(GameSystem oldSys, GameSystem newSys)
   1.345  		{
   1.346  			system = newSys;
   1.347 @@ -436,34 +437,34 @@
   1.348  			miCreateArmy.Sensitive = system!=null;
   1.349  			newArmyButton.Sensitive = system!=null;
   1.350  			RemoveCategoryButtons();
   1.351 -			
   1.352 +
   1.353  			if (system!=null)
   1.354  			{
   1.355  				AddCategoryButtons(system.Categories);
   1.356  			}
   1.357  		}
   1.358 -		
   1.359 +
   1.360  		private void OnArmyChanged(Army oldArmy, Army newArmy)
   1.361  		{
   1.362  			loadedArmyPath = null;
   1.363  			SetAppTitle();
   1.364  			SetArmyTree(newArmy);
   1.365 -						
   1.366 +
   1.367  			if (oldArmy!=null)
   1.368  			{
   1.369  				oldArmy.UnitAdded-= UnitAddedMethod;
   1.370  				oldArmy.UnitRemoved-= UnitRemovedMethod;
   1.371  				oldArmy.PointsValueChanged-= PointsValueChangedMethod;
   1.372 -				oldArmy.FailedRequirement-=FailedUnitRequirementMethod;				
   1.373 +				oldArmy.FailedRequirement-=FailedUnitRequirementMethod;
   1.374  			}
   1.375 -			
   1.376 +
   1.377  			unitToWidgetMap.Clear();
   1.378 -			
   1.379 +
   1.380  			while (unitsNotebook.NPages > 0)
   1.381  			{
   1.382  				unitsNotebook.RemovePage(0);
   1.383  			}
   1.384 -			
   1.385 +
   1.386  			if (newArmy==null)
   1.387  			{
   1.388  				DisableCategoryButtons();
   1.389 @@ -483,7 +484,7 @@
   1.390  					AddCategoryButtons(newArmy.Race.Categories);
   1.391  				}
   1.392  			}
   1.393 -			
   1.394 +
   1.395  			miCloseArmy.Sensitive = newArmy!=null;
   1.396  			miSaveArmyAs.Sensitive = newArmy!=null;
   1.397  			//New army has no changes, so we can't save it
   1.398 @@ -493,73 +494,73 @@
   1.399  			CommandStack.Reset();
   1.400  			SetPointsPanelText();
   1.401  		}
   1.402 -		
   1.403 +
   1.404  		private void SetArmyTree(Army army)
   1.405  		{
   1.406  			logger.Debug("Resetting tree");
   1.407  			TreeStore store = (TreeStore)treeUnits.Model;
   1.408  			store.Clear();
   1.409  			TreeIter iter;
   1.410 -			
   1.411 +
   1.412  			if (army!=null)
   1.413  			{
   1.414  				logger.Debug("Loading in categories to tree");
   1.415 -								
   1.416 +
   1.417  				foreach (ArmyCategory cat in army.Categories)
   1.418  				{
   1.419  					logger.DebugFormat("Append category {0}", cat.Name);
   1.420  					iter = store.AppendValues(cat);
   1.421 -					
   1.422 +
   1.423  					foreach (IBBoard.WarFoundry.API.Objects.Unit unit in cat.GetUnits())
   1.424  					{
   1.425  						store.AppendValues(iter, unit);
   1.426 -					} 
   1.427 +					}
   1.428  				}
   1.429 -				
   1.430 +
   1.431  				logger.Debug("Finished loading tree categories");
   1.432  			}
   1.433  		}
   1.434 -		
   1.435 +
   1.436  		private void DisableCategoryButtons()
   1.437  		{
   1.438  			SetCategoryButtonsSensitive(false);
   1.439  		}
   1.440 -		
   1.441 +
   1.442  		private void EnableCategoryButtons()
   1.443  		{
   1.444  			SetCategoryButtonsSensitive(true);
   1.445  		}
   1.446 -		
   1.447 +
   1.448  		private void SetCategoryButtonsSensitive(bool state)
   1.449  		{
   1.450  			int toolbarButtonCount = toolbar.Children.Length - 1;
   1.451  			logger.Debug("Last button index: "+toolbarButtonCount);
   1.452 -			
   1.453 +
   1.454  			for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--)
   1.455  			{
   1.456  				logger.DebugFormat("Setting button {0} state to {1}", i, state);
   1.457  				toolbar.Children[i].Sensitive = state;
   1.458  			}
   1.459  		}
   1.460 -		
   1.461 +
   1.462  		private void RemoveCategoryButtons()
   1.463  		{
   1.464  			int toolbarButtonCount = toolbar.Children.Length - 1;
   1.465 -			
   1.466 +
   1.467  			for (int i = toolbarButtonCount; i > CATEGORY_BUTTON_SEPARATOR_INDEX; i--)
   1.468  			{
   1.469  				toolbar.Remove(toolbar.Children[i]);
   1.470  			}
   1.471 -			
   1.472 +
   1.473  			categoryMap.Clear();
   1.474  		}
   1.475 -		
   1.476 +
   1.477  		private void AddCategoryButtons(Category[] cats)
   1.478  		{
   1.479  			if (cats!=null && cats.Length > 0)
   1.480  			{
   1.481  				logger.DebugFormat("Toolbar button count: {0}. Adding {1} categories.", toolbar.Children.Length, cats.Length);
   1.482 -				
   1.483 +
   1.484  				foreach (Category cat in cats)
   1.485  				{
   1.486  					ToolButton button = new ToolButton("gtk-add");
   1.487 @@ -571,17 +572,17 @@
   1.488  					toolbar.Insert(button, -1);
   1.489  				}
   1.490  			}
   1.491 -			
   1.492 +
   1.493  			toolbar.Children[CATEGORY_BUTTON_SEPARATOR_INDEX].Visible = cats!=null && cats.Length>0;
   1.494 -			
   1.495 +
   1.496  			toolbar.ShowAll();
   1.497  		}
   1.498 -		
   1.499 +
   1.500  		private void SetPointsPanelText()
   1.501  		{
   1.502  			//TODO: Set the points value in the status bar
   1.503  		}
   1.504 -		
   1.505 +
   1.506  		private void commandStack_CommandStackUpdated()
   1.507  		{
   1.508  			undoMenuButton.Sensitive = commandStack.CanUndo();
   1.509 @@ -592,7 +593,7 @@
   1.510  			//TODO: Build menus for undo/redo and find way of adding tooltips
   1.511  			/*int maxRedo = Math.Min(10, redoLength);
   1.512  			MenuItem[] menuItems = null;
   1.513 -		
   1.514 +
   1.515  			if (redoLength > 0)
   1.516  			{
   1.517  				menuItems = new MenuItem[maxRedo];
   1.518 @@ -605,7 +606,7 @@
   1.519  
   1.520  					if (com == null)
   1.521  					{
   1.522 -						break; 
   1.523 +						break;
   1.524  					}
   1.525  
   1.526  					mi = new MenuItem(com.Description);
   1.527 @@ -630,7 +631,7 @@
   1.528  			int undoLength = commandStack.UndoLength;
   1.529  			/*int maxUndo = Math.Min(10, undoLength);
   1.530  			MenuItem[] menuItemsUndo = null;
   1.531 -			
   1.532 +
   1.533  			if (undoLength > 0)
   1.534  			{
   1.535  				menuItemsUndo = new MenuItem[maxUndo];
   1.536 @@ -643,7 +644,7 @@
   1.537  
   1.538  					if (com == null)
   1.539  					{
   1.540 -						break; 
   1.541 +						break;
   1.542  					}
   1.543  
   1.544  					mi = new MenuItem(com.UndoDescription);
   1.545 @@ -658,17 +659,17 @@
   1.546  			{
   1.547  				bttnUndo.ToolTipText = menuItemsUndo[0].Text;
   1.548  				undoMenu.MenuItems.AddRange(menuItemsUndo);
   1.549 -			}*/			
   1.550 +			}*/
   1.551  			//TODO: Put above code back when we have a dropdown version of the undo button
   1.552  			if (undoLength > 0)
   1.553  			{
   1.554  				//undoMenuButton.Tooltip = CommandStack.PeekUndoCommand().UndoDescription;
   1.555  			}
   1.556 -			
   1.557 +
   1.558  			saveArmyButton.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave();
   1.559  			miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy!=null && CanSave();
   1.560 -		}	
   1.561 -		
   1.562 +		}
   1.563 +
   1.564  		private bool CanSave()
   1.565  		{
   1.566  			return loadedArmyPath!=null && WarFoundryCore.CurrentArmy!=null && WarFoundrySaver.GetSaver()!=null;
   1.567 @@ -680,12 +681,12 @@
   1.568  			{
   1.569  				return SaveCurrentArmy();
   1.570  			}
   1.571 -			else 
   1.572 +			else
   1.573  			{
   1.574  				return SaveCurrentArmyAs();
   1.575  			}
   1.576  		}
   1.577 -		
   1.578 +
   1.579  		private bool OpenArmy()
   1.580  		{
   1.581  			//TODO: Open dialog for file selection then open army
   1.582 @@ -697,7 +698,7 @@
   1.583  		private bool SaveCurrentArmy()
   1.584  		{
   1.585  			bool success = false;
   1.586 -			
   1.587 +
   1.588  			if (CanSave())
   1.589  			{
   1.590  				try
   1.591 @@ -717,51 +718,30 @@
   1.592  					md.Show();
   1.593  				}
   1.594  			}
   1.595 -			
   1.596 +
   1.597  			return success;
   1.598  		}
   1.599  
   1.600  		private bool SaveCurrentArmyAs()
   1.601  		{
   1.602 -			/*if (saveArmyDialog.Filter == "")
   1.603 +			bool success = false;
   1.604 +
   1.605 +			if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, Constants.UserDataPath+Constants.DirectoryString+"test.army"))
   1.606  			{
   1.607 -				string savePath = UserDataPath+Constants.DirectoryString+"armies"+Constants.DirectoryString;
   1.608 -				
   1.609 -				if (!Directory.Exists(savePath))
   1.610 -				{
   1.611 -					Directory.CreateDirectory(savePath);
   1.612 -				}
   1.613 -
   1.614 -				saveArmyDialog.InitialDirectory = savePath;
   1.615 -				saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
   1.616 -				saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog");
   1.617 -			}
   1.618 -
   1.619 -			DialogResult dr = saveArmyDialog.ShowDialog(this);
   1.620 -
   1.621 -			if (dr == DialogResult.OK)
   1.622 -			{
   1.623 -				if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, saveArmyDialog.FileName))
   1.624 -				{
   1.625 -					miSaveArmy.Enabled = false;
   1.626 -					bttnSaveArmy.Enabled = false;
   1.627 -					CommandStack.setCleanMark();
   1.628 -					loadedArmyPath = saveArmyDialog.FileName;
   1.629 -					return true;
   1.630 -				}
   1.631 -				else
   1.632 -				{
   1.633 -					MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.634 -					return false;
   1.635 -				}
   1.636 +				miSaveArmy.Sensitive = false;
   1.637 +				//bttnSaveArmy.Sensitive = false;
   1.638 +				CommandStack.setCleanMark();
   1.639 +				loadedArmyPath = Constants.UserDataPath+Constants.DirectoryString+"test.army";
   1.640 +				success = true;
   1.641  			}
   1.642  			else
   1.643  			{
   1.644 -				return false;
   1.645 -			}*/
   1.646 -			return false;
   1.647 +				//MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.648 +			}
   1.649 +
   1.650 +			return success;
   1.651  		}
   1.652 -		
   1.653 +
   1.654  		private bool CloseCurrentArmy()
   1.655  		{
   1.656  			if (WarFoundryCore.CurrentArmy!=null)
   1.657 @@ -770,7 +750,7 @@
   1.658  
   1.659  				if (CommandStack.IsDirty())
   1.660  				{
   1.661 -					MessageDialog dia  = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo | ButtonsType.Cancel, "The army \""+WarFoundryCore.CurrentArmy.Name+"\" has been modified.\r\nSave changes before closing army?");   
   1.662 +					MessageDialog dia  = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo | ButtonsType.Cancel, "The army \""+WarFoundryCore.CurrentArmy.Name+"\" has been modified.\r\nSave changes before closing army?");
   1.663  					ResponseType dr = (ResponseType)dia.Run();
   1.664  
   1.665  					if (dr == ResponseType.Yes)
   1.666 @@ -789,7 +769,7 @@
   1.667  						//Assume cancel or close with the X button
   1.668  						canClose = false;
   1.669  					}
   1.670 -					
   1.671 +
   1.672  					dia.Dispose();
   1.673  				}
   1.674  				else
   1.675 @@ -822,7 +802,7 @@
   1.676  			FrmNewArmy newArmy = new FrmNewArmy(WarFoundryCore.CurrentGameSystem);
   1.677  			ResponseType type = (ResponseType)newArmy.Run();
   1.678  			newArmy.Hide();
   1.679 -		
   1.680 +
   1.681  			if (type == ResponseType.Ok)
   1.682  			{
   1.683  				if (CloseCurrentArmy())
   1.684 @@ -834,17 +814,17 @@
   1.685  			{
   1.686  				logger.Debug("Create new army cancelled");
   1.687  			}
   1.688 -			
   1.689 +
   1.690  			newArmy.Destroy();
   1.691  		}
   1.692 -		
   1.693 +
   1.694  		private void ChangeCurrentGameSystem()
   1.695 -		{				
   1.696 +		{
   1.697  			logger.Debug("Changing game system");
   1.698  			FrmChangeGameSystem dialog = new FrmChangeGameSystem(this);
   1.699  			ResponseType type = (ResponseType)dialog.Run();
   1.700  			dialog.Hide();
   1.701 -			
   1.702 +
   1.703  			if (type == ResponseType.Ok)
   1.704  			{
   1.705  				WarFoundryCore.CurrentGameSystem = dialog.SelectedSystem;
   1.706 @@ -853,7 +833,7 @@
   1.707  			{
   1.708  				logger.Debug("Game system change cancelled");
   1.709  			}
   1.710 -			
   1.711 +
   1.712  			dialog.Destroy();
   1.713  		}
   1.714  
   1.715 @@ -888,14 +868,14 @@
   1.716  			TreeIter iter;
   1.717  			model.GetIter(out iter, args.Path);
   1.718  			object obj = model.GetValue(iter, 0);
   1.719 -			
   1.720 +
   1.721  			if (obj is IBBoard.WarFoundry.API.Objects.Unit)
   1.722  			{
   1.723  				IBBoard.WarFoundry.API.Objects.Unit unit = (IBBoard.WarFoundry.API.Objects.Unit)obj;
   1.724 -				
   1.725 +
   1.726  				UnitDisplayWidget widget;
   1.727  				unitToWidgetMap.TryGetValue(unit, out widget);
   1.728 -				
   1.729 +
   1.730  				if (widget!=null)
   1.731  				{
   1.732  					logger.DebugFormat("Selecting existing page for "+unit.Name);