changeset 25:01ddadfa9653

Re #86: Complete initial GTK# UI * Enable "open" buttons * Fill out "open" method * Fix showing of "save failed" dialog
author IBBoard <dev@ibboard.co.uk>
date Sat, 22 Aug 2009 19:48:03 +0000
parents 105c68bb759c
children 3a396783bfed
files FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs
diffstat 2 files changed, 48 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMainWindow.cs	Sat Aug 22 19:10:45 2009 +0000
+++ b/FrmMainWindow.cs	Sat Aug 22 19:48:03 2009 +0000
@@ -689,9 +689,52 @@
 
 		private bool OpenArmy()
 		{
-			//TODO: Open dialog for file selection then open army
+			FileChooserDialog fileDialog = new FileChooserDialog("Open army", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
+			FileFilter filter = new FileFilter();
+			filter.AddPattern("*.army");
+			filter.Name = "WarFoundry Army files (*.army)";
+			fileDialog.AddFilter(filter);
+			int response = fileDialog.Run();
+			string filePath = null;
+			
+			if (response == (int)ResponseType.Accept)
+			{
+				filePath = fileDialog.Filename;
+			}
+			
+			fileDialog.Hide();			
+			fileDialog.Dispose();
+			
 			bool success = false;
-			loadedArmyPath = null;//TODO: Set loaded file path
+
+			if (filePath != null)
+			{
+				FileInfo file = new FileInfo(filePath);
+				Army army = WarFoundryLoader.GetDefault().LoadArmy(file);
+
+				if (army != null)
+				{
+					logger.Debug("Loaded army " + army.ID);
+					success = true;
+					loadedArmyPath = filePath;
+					WarFoundryCore.CurrentArmy = army;
+					logger.Debug("Army loading complete");
+				}
+				else
+				{
+					logger.ErrorFormat("Failed to load {0} as an army file", filePath);
+					MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, file.Name + " could not be loaded.\n\nIf the file is an army file then please check your file loaders.");
+					dialog.Title = "Failed to open army";
+					dialog.Run();
+					dialog.Hide();
+					dialog.Dispose();
+				}
+			}
+			else
+			{
+				logger.Debug("Army open requested but cancelled");
+			}	
+			
 			return success;
 		}
 
@@ -709,7 +752,6 @@
 
 		private bool SaveCurrentArmyAs()
 		{
-			
 			FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
 			FileFilter filter = new FileFilter();
 			filter.AddPattern("*.army");
@@ -746,7 +788,9 @@
 				else
 				{
 					MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to "+filePath);
-					dialog.Show();
+					dialog.Title = "Army save failed";
+					dialog.Run();
+					dialog.Hide();
 					dialog.Dispose();
 				}	
 			}
--- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Sat Aug 22 19:10:45 2009 +0000
+++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Sat Aug 22 19:48:03 2009 +0000
@@ -86,7 +86,6 @@
             this.miCreateArmy.ShortLabel = Mono.Unix.Catalog.GetString("Create army");
             w1.Add(this.miCreateArmy, null);
             this.miOpenArmy = new Gtk.Action("miOpenArmy", Mono.Unix.Catalog.GetString("Open army"), null, "gtk-open");
-            this.miOpenArmy.Sensitive = false;
             this.miOpenArmy.ShortLabel = Mono.Unix.Catalog.GetString("Open army");
             w1.Add(this.miOpenArmy, null);
             this.miSaveArmy = new Gtk.Action("miSaveArmy", Mono.Unix.Catalog.GetString("Save army"), null, "gtk-save");
@@ -135,7 +134,6 @@
             this.newArmyButton.Sensitive = false;
             w1.Add(this.newArmyButton, null);
             this.openArmyButton = new Gtk.Action("openArmyButton", null, null, "gtk-open");
-            this.openArmyButton.Sensitive = false;
             w1.Add(this.openArmyButton, null);
             this.saveArmyButton = new Gtk.Action("saveArmyButton", null, null, "gtk-save");
             this.saveArmyButton.Sensitive = false;