changeset 23:d661cb257511

Re #86: Initial GTK# GUI (because of Re #53) * Refactor file saving in to a common method * Replace fixed location with dialog
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Aug 2009 19:49:05 +0000
parents 40485c6e5cb0
children 105c68bb759c
files FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs gtk-gui/gui.stetic
diffstat 3 files changed, 65 insertions(+), 38 deletions(-) [+]
line diff
     1.1 --- a/FrmMainWindow.cs	Mon Aug 17 19:17:35 2009 +0000
     1.2 +++ b/FrmMainWindow.cs	Mon Aug 17 19:49:05 2009 +0000
     1.3 @@ -701,22 +701,7 @@
     1.4  
     1.5  			if (CanSave())
     1.6  			{
     1.7 -				try
     1.8 -				{
     1.9 -					if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, loadedArmyPath))
    1.10 -					{
    1.11 -						saveArmyButton.Sensitive = false;
    1.12 -						miSaveArmy.Sensitive = false;
    1.13 -						CommandStack.setCleanMark();
    1.14 -						success = true;
    1.15 -					}
    1.16 -				}
    1.17 -				catch (IOException ex)
    1.18 -				{
    1.19 -					logger.Error("Saving army failed", ex);
    1.20 -					MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "An error occured while saving the army. Please check the logs for details on what failed");
    1.21 -					md.Show();
    1.22 -				}
    1.23 +				success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath);
    1.24  			}
    1.25  
    1.26  			return success;
    1.27 @@ -724,21 +709,49 @@
    1.28  
    1.29  		private bool SaveCurrentArmyAs()
    1.30  		{
    1.31 +			
    1.32 +			FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
    1.33 +			FileFilter filter = new FileFilter();
    1.34 +			filter.AddPattern("*.army");
    1.35 +			filter.Name = "WarFoundry Army files (*.army)";
    1.36 +			fileDialog.AddFilter(filter);
    1.37 +			int response = fileDialog.Run();
    1.38 +			string filePath = null;
    1.39 +			
    1.40 +			if (response == (int)ResponseType.Accept)
    1.41 +			{
    1.42 +				filePath = fileDialog.Filename;
    1.43 +			}
    1.44 +			
    1.45 +			fileDialog.Hide();			
    1.46 +			fileDialog.Dispose();
    1.47 +			
    1.48 +			return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath);
    1.49 +		}
    1.50 +		
    1.51 +		private bool SaveArmyToPath(Army army, string filePath)
    1.52 +		{
    1.53  			bool success = false;
    1.54 -
    1.55 -			if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, Constants.UserDataPath+Constants.DirectoryString+"test.army"))
    1.56 +			
    1.57 +			if (filePath!=null)
    1.58  			{
    1.59 -				miSaveArmy.Sensitive = false;
    1.60 -				//bttnSaveArmy.Sensitive = false;
    1.61 -				CommandStack.setCleanMark();
    1.62 -				loadedArmyPath = Constants.UserDataPath+Constants.DirectoryString+"test.army";
    1.63 -				success = true;
    1.64 +				if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, filePath))
    1.65 +				{
    1.66 +					miSaveArmy.Sensitive = false;
    1.67 +					saveArmyButton.Sensitive = false;
    1.68 +					CommandStack.setCleanMark();
    1.69 +					loadedArmyPath = filePath;
    1.70 +					success = true;
    1.71 +				}
    1.72 +				else
    1.73 +				{
    1.74 +					MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to "+filePath);
    1.75 +					dialog.Show();
    1.76 +					dialog.Dispose();
    1.77 +				}	
    1.78  			}
    1.79 -			else
    1.80 -			{
    1.81 -				//MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error);
    1.82 -			}
    1.83 -
    1.84 +			//else user cancelled
    1.85 +			
    1.86  			return success;
    1.87  		}
    1.88  
     2.1 --- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Mon Aug 17 19:17:35 2009 +0000
     2.2 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs	Mon Aug 17 19:49:05 2009 +0000
     2.3 @@ -81,51 +81,51 @@
     2.4              this.menuFile = new Gtk.Action("menuFile", Mono.Unix.Catalog.GetString("File"), null, null);
     2.5              this.menuFile.ShortLabel = Mono.Unix.Catalog.GetString("File");
     2.6              w1.Add(this.menuFile, null);
     2.7 -            this.miCreateArmy = new Gtk.Action("miCreateArmy", Mono.Unix.Catalog.GetString("Create army"), null, null);
     2.8 +            this.miCreateArmy = new Gtk.Action("miCreateArmy", Mono.Unix.Catalog.GetString("Create army"), null, "gtk-new");
     2.9              this.miCreateArmy.Sensitive = false;
    2.10              this.miCreateArmy.ShortLabel = Mono.Unix.Catalog.GetString("Create army");
    2.11              w1.Add(this.miCreateArmy, null);
    2.12 -            this.miOpenArmy = new Gtk.Action("miOpenArmy", Mono.Unix.Catalog.GetString("Open army"), null, null);
    2.13 +            this.miOpenArmy = new Gtk.Action("miOpenArmy", Mono.Unix.Catalog.GetString("Open army"), null, "gtk-open");
    2.14              this.miOpenArmy.Sensitive = false;
    2.15              this.miOpenArmy.ShortLabel = Mono.Unix.Catalog.GetString("Open army");
    2.16              w1.Add(this.miOpenArmy, null);
    2.17 -            this.miSaveArmy = new Gtk.Action("miSaveArmy", Mono.Unix.Catalog.GetString("Save army"), null, null);
    2.18 +            this.miSaveArmy = new Gtk.Action("miSaveArmy", Mono.Unix.Catalog.GetString("Save army"), null, "gtk-save");
    2.19              this.miSaveArmy.Sensitive = false;
    2.20              this.miSaveArmy.ShortLabel = Mono.Unix.Catalog.GetString("Save army");
    2.21              w1.Add(this.miSaveArmy, null);
    2.22 -            this.miSaveArmyAs = new Gtk.Action("miSaveArmyAs", Mono.Unix.Catalog.GetString("Save army as"), null, null);
    2.23 +            this.miSaveArmyAs = new Gtk.Action("miSaveArmyAs", Mono.Unix.Catalog.GetString("Save army as"), null, "gtk-save-as");
    2.24              this.miSaveArmyAs.Sensitive = false;
    2.25              this.miSaveArmyAs.ShortLabel = Mono.Unix.Catalog.GetString("Save army as");
    2.26              w1.Add(this.miSaveArmyAs, null);
    2.27 -            this.miCloseArmy = new Gtk.Action("miCloseArmy", Mono.Unix.Catalog.GetString("Close army"), null, null);
    2.28 +            this.miCloseArmy = new Gtk.Action("miCloseArmy", Mono.Unix.Catalog.GetString("Close army"), null, "gtk-close");
    2.29              this.miCloseArmy.Sensitive = false;
    2.30              this.miCloseArmy.ShortLabel = Mono.Unix.Catalog.GetString("Close army");
    2.31              w1.Add(this.miCloseArmy, null);
    2.32              this.miChangeGameSystem = new Gtk.Action("miChangeGameSystem", Mono.Unix.Catalog.GetString("Change game system"), null, null);
    2.33              this.miChangeGameSystem.ShortLabel = Mono.Unix.Catalog.GetString("Change game system");
    2.34              w1.Add(this.miChangeGameSystem, null);
    2.35 -            this.miReloadFiles = new Gtk.Action("miReloadFiles", Mono.Unix.Catalog.GetString("Reload files"), null, null);
    2.36 +            this.miReloadFiles = new Gtk.Action("miReloadFiles", Mono.Unix.Catalog.GetString("Reload files"), null, "gtk-refresh");
    2.37              this.miReloadFiles.Sensitive = false;
    2.38              this.miReloadFiles.ShortLabel = Mono.Unix.Catalog.GetString("Reload files");
    2.39              w1.Add(this.miReloadFiles, null);
    2.40 -            this.miExit = new Gtk.Action("miExit", Mono.Unix.Catalog.GetString("Exit"), null, null);
    2.41 +            this.miExit = new Gtk.Action("miExit", Mono.Unix.Catalog.GetString("Exit"), null, "gtk-quit");
    2.42              this.miExit.ShortLabel = Mono.Unix.Catalog.GetString("Exit");
    2.43              w1.Add(this.miExit, null);
    2.44              this.menuEdit = new Gtk.Action("menuEdit", Mono.Unix.Catalog.GetString("Edit"), null, null);
    2.45              this.menuEdit.ShortLabel = Mono.Unix.Catalog.GetString("Edit");
    2.46              w1.Add(this.menuEdit, null);
    2.47 -            this.miUndo = new Gtk.Action("miUndo", Mono.Unix.Catalog.GetString("Undo"), null, null);
    2.48 +            this.miUndo = new Gtk.Action("miUndo", Mono.Unix.Catalog.GetString("Undo"), null, "gtk-undo");
    2.49              this.miUndo.Sensitive = false;
    2.50              this.miUndo.ShortLabel = Mono.Unix.Catalog.GetString("Undo");
    2.51              w1.Add(this.miUndo, null);
    2.52 -            this.miRedo = new Gtk.Action("miRedo", Mono.Unix.Catalog.GetString("Redo"), null, null);
    2.53 +            this.miRedo = new Gtk.Action("miRedo", Mono.Unix.Catalog.GetString("Redo"), null, "gtk-redo");
    2.54              this.miRedo.Sensitive = false;
    2.55              this.miRedo.ShortLabel = Mono.Unix.Catalog.GetString("Redo");
    2.56              w1.Add(this.miRedo, null);
    2.57              this.menuHelp = new Gtk.Action("menuHelp", Mono.Unix.Catalog.GetString("Help"), null, null);
    2.58              this.menuHelp.ShortLabel = Mono.Unix.Catalog.GetString("Help");
    2.59              w1.Add(this.menuHelp, null);
    2.60 -            this.miAbout = new Gtk.Action("miAbout", Mono.Unix.Catalog.GetString("About"), null, null);
    2.61 +            this.miAbout = new Gtk.Action("miAbout", Mono.Unix.Catalog.GetString("About"), null, "gtk-about");
    2.62              this.miAbout.ShortLabel = Mono.Unix.Catalog.GetString("About");
    2.63              w1.Add(this.miAbout, null);
    2.64              this.miDebugInformation = new Gtk.Action("miDebugInformation", Mono.Unix.Catalog.GetString("Debug Information"), null, null);
    2.65 @@ -133,22 +133,29 @@
    2.66              w1.Add(this.miDebugInformation, null);
    2.67              this.newArmyButton = new Gtk.Action("newArmyButton", null, null, "gtk-new");
    2.68              this.newArmyButton.Sensitive = false;
    2.69 +            this.newArmyButton.ShortLabel = "";
    2.70              w1.Add(this.newArmyButton, null);
    2.71              this.openArmyButton = new Gtk.Action("openArmyButton", null, null, "gtk-open");
    2.72              this.openArmyButton.Sensitive = false;
    2.73 +            this.openArmyButton.ShortLabel = "";
    2.74              w1.Add(this.openArmyButton, null);
    2.75              this.saveArmyButton = new Gtk.Action("saveArmyButton", null, null, "gtk-save");
    2.76              this.saveArmyButton.Sensitive = false;
    2.77 +            this.saveArmyButton.ShortLabel = "";
    2.78              w1.Add(this.saveArmyButton, null);
    2.79              this.undoActionButton = new Gtk.Action("undoActionButton", null, null, "gtk-undo");
    2.80              this.undoActionButton.Sensitive = false;
    2.81 +            this.undoActionButton.ShortLabel = "";
    2.82              w1.Add(this.undoActionButton, null);
    2.83              this.redoActionButton = new Gtk.Action("redoActionButton", null, null, "gtk-redo");
    2.84              this.redoActionButton.Sensitive = false;
    2.85 +            this.redoActionButton.ShortLabel = "";
    2.86              w1.Add(this.redoActionButton, null);
    2.87              this.goDown = new Gtk.Action("goDown", null, null, null);
    2.88 +            this.goDown.ShortLabel = "";
    2.89              w1.Add(this.goDown, null);
    2.90              this.add = new Gtk.Action("add", null, null, "gtk-add");
    2.91 +            this.add.ShortLabel = "";
    2.92              w1.Add(this.add, null);
    2.93              this.UIManager.InsertActionGroup(w1, 0);
    2.94              this.AddAccelGroup(this.UIManager.AccelGroup);
     3.1 --- a/gtk-gui/gui.stetic	Mon Aug 17 19:17:35 2009 +0000
     3.2 +++ b/gtk-gui/gui.stetic	Mon Aug 17 19:49:05 2009 +0000
     3.3 @@ -115,6 +115,7 @@
     3.4          <property name="Type">Action</property>
     3.5          <property name="Label" translatable="yes" />
     3.6          <property name="Sensitive">False</property>
     3.7 +        <property name="ShortLabel" translatable="yes" />
     3.8          <property name="StockId">gtk-new</property>
     3.9          <signal name="Activated" handler="newTBButtonActivated" />
    3.10        </action>
    3.11 @@ -122,6 +123,7 @@
    3.12          <property name="Type">Action</property>
    3.13          <property name="Label" translatable="yes" />
    3.14          <property name="Sensitive">False</property>
    3.15 +        <property name="ShortLabel" translatable="yes" />
    3.16          <property name="StockId">gtk-open</property>
    3.17          <signal name="Activated" handler="openTBButtonActivated" />
    3.18        </action>
    3.19 @@ -129,6 +131,7 @@
    3.20          <property name="Type">Action</property>
    3.21          <property name="Label" translatable="yes" />
    3.22          <property name="Sensitive">False</property>
    3.23 +        <property name="ShortLabel" translatable="yes" />
    3.24          <property name="StockId">gtk-save</property>
    3.25          <signal name="Activated" handler="saveTBButtonActivated" />
    3.26        </action>
    3.27 @@ -136,6 +139,7 @@
    3.28          <property name="Type">Action</property>
    3.29          <property name="Label" translatable="yes" />
    3.30          <property name="Sensitive">False</property>
    3.31 +        <property name="ShortLabel" translatable="yes" />
    3.32          <property name="StockId">gtk-undo</property>
    3.33          <signal name="Activated" handler="undoTBButtonActivated" />
    3.34        </action>
    3.35 @@ -143,16 +147,19 @@
    3.36          <property name="Type">Action</property>
    3.37          <property name="Label" translatable="yes" />
    3.38          <property name="Sensitive">False</property>
    3.39 +        <property name="ShortLabel" translatable="yes" />
    3.40          <property name="StockId">gtk-redo</property>
    3.41          <signal name="Activated" handler="redoTBButtonActivated" />
    3.42        </action>
    3.43        <action id="goDown">
    3.44          <property name="Type">Action</property>
    3.45          <property name="Label" translatable="yes" />
    3.46 +        <property name="ShortLabel" translatable="yes" />
    3.47        </action>
    3.48        <action id="add">
    3.49          <property name="Type">Action</property>
    3.50          <property name="Label" translatable="yes" />
    3.51 +        <property name="ShortLabel" translatable="yes" />
    3.52          <property name="StockId">gtk-add</property>
    3.53        </action>
    3.54      </action-group>