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 diff
     1.1 --- a/FrmMainWindow.cs	Sat Aug 22 19:10:45 2009 +0000
     1.2 +++ b/FrmMainWindow.cs	Sat Aug 22 19:48:03 2009 +0000
     1.3 @@ -689,9 +689,52 @@
     1.4  
     1.5  		private bool OpenArmy()
     1.6  		{
     1.7 -			//TODO: Open dialog for file selection then open army
     1.8 +			FileChooserDialog fileDialog = new FileChooserDialog("Open army", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
     1.9 +			FileFilter filter = new FileFilter();
    1.10 +			filter.AddPattern("*.army");
    1.11 +			filter.Name = "WarFoundry Army files (*.army)";
    1.12 +			fileDialog.AddFilter(filter);
    1.13 +			int response = fileDialog.Run();
    1.14 +			string filePath = null;
    1.15 +			
    1.16 +			if (response == (int)ResponseType.Accept)
    1.17 +			{
    1.18 +				filePath = fileDialog.Filename;
    1.19 +			}
    1.20 +			
    1.21 +			fileDialog.Hide();			
    1.22 +			fileDialog.Dispose();
    1.23 +			
    1.24  			bool success = false;
    1.25 -			loadedArmyPath = null;//TODO: Set loaded file path
    1.26 +
    1.27 +			if (filePath != null)
    1.28 +			{
    1.29 +				FileInfo file = new FileInfo(filePath);
    1.30 +				Army army = WarFoundryLoader.GetDefault().LoadArmy(file);
    1.31 +
    1.32 +				if (army != null)
    1.33 +				{
    1.34 +					logger.Debug("Loaded army " + army.ID);
    1.35 +					success = true;
    1.36 +					loadedArmyPath = filePath;
    1.37 +					WarFoundryCore.CurrentArmy = army;
    1.38 +					logger.Debug("Army loading complete");
    1.39 +				}
    1.40 +				else
    1.41 +				{
    1.42 +					logger.ErrorFormat("Failed to load {0} as an army file", filePath);
    1.43 +					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.");
    1.44 +					dialog.Title = "Failed to open army";
    1.45 +					dialog.Run();
    1.46 +					dialog.Hide();
    1.47 +					dialog.Dispose();
    1.48 +				}
    1.49 +			}
    1.50 +			else
    1.51 +			{
    1.52 +				logger.Debug("Army open requested but cancelled");
    1.53 +			}	
    1.54 +			
    1.55  			return success;
    1.56  		}
    1.57  
    1.58 @@ -709,7 +752,6 @@
    1.59  
    1.60  		private bool SaveCurrentArmyAs()
    1.61  		{
    1.62 -			
    1.63  			FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
    1.64  			FileFilter filter = new FileFilter();
    1.65  			filter.AddPattern("*.army");
    1.66 @@ -746,7 +788,9 @@
    1.67  				else
    1.68  				{
    1.69  					MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to "+filePath);
    1.70 -					dialog.Show();
    1.71 +					dialog.Title = "Army save failed";
    1.72 +					dialog.Run();
    1.73 +					dialog.Hide();
    1.74  					dialog.Dispose();
    1.75  				}	
    1.76  			}
     2.1 --- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Sat Aug 22 19:10:45 2009 +0000
     2.2 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Sat Aug 22 19:48:03 2009 +0000
     2.3 @@ -86,7 +86,6 @@
     2.4              this.miCreateArmy.ShortLabel = Mono.Unix.Catalog.GetString("Create army");
     2.5              w1.Add(this.miCreateArmy, null);
     2.6              this.miOpenArmy = new Gtk.Action("miOpenArmy", Mono.Unix.Catalog.GetString("Open army"), null, "gtk-open");
     2.7 -            this.miOpenArmy.Sensitive = false;
     2.8              this.miOpenArmy.ShortLabel = Mono.Unix.Catalog.GetString("Open army");
     2.9              w1.Add(this.miOpenArmy, null);
    2.10              this.miSaveArmy = new Gtk.Action("miSaveArmy", Mono.Unix.Catalog.GetString("Save army"), null, "gtk-save");
    2.11 @@ -135,7 +134,6 @@
    2.12              this.newArmyButton.Sensitive = false;
    2.13              w1.Add(this.newArmyButton, null);
    2.14              this.openArmyButton = new Gtk.Action("openArmyButton", null, null, "gtk-open");
    2.15 -            this.openArmyButton.Sensitive = false;
    2.16              w1.Add(this.openArmyButton, null);
    2.17              this.saveArmyButton = new Gtk.Action("saveArmyButton", null, null, "gtk-save");
    2.18              this.saveArmyButton.Sensitive = false;