Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
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, 64 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmMainWindow.cs Mon Aug 17 19:17:35 2009 +0000 +++ b/FrmMainWindow.cs Mon Aug 17 19:49:05 2009 +0000 @@ -701,22 +701,7 @@ if (CanSave()) { - try - { - if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, loadedArmyPath)) - { - saveArmyButton.Sensitive = false; - miSaveArmy.Sensitive = false; - CommandStack.setCleanMark(); - success = true; - } - } - catch (IOException ex) - { - logger.Error("Saving army failed", ex); - 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"); - md.Show(); - } + success = SaveArmyToPath(WarFoundryCore.CurrentArmy, loadedArmyPath); } return success; @@ -724,21 +709,49 @@ private bool SaveCurrentArmyAs() { - bool success = false; - - if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, Constants.UserDataPath+Constants.DirectoryString+"test.army")) + + FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", 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) { - miSaveArmy.Sensitive = false; - //bttnSaveArmy.Sensitive = false; - CommandStack.setCleanMark(); - loadedArmyPath = Constants.UserDataPath+Constants.DirectoryString+"test.army"; - success = true; + filePath = fileDialog.Filename; } - else + + fileDialog.Hide(); + fileDialog.Dispose(); + + return SaveArmyToPath(WarFoundryCore.CurrentArmy, filePath); + } + + private bool SaveArmyToPath(Army army, string filePath) + { + bool success = false; + + if (filePath!=null) { - //MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); + if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, filePath)) + { + miSaveArmy.Sensitive = false; + saveArmyButton.Sensitive = false; + CommandStack.setCleanMark(); + loadedArmyPath = filePath; + success = true; + } + else + { + MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to "+filePath); + dialog.Show(); + dialog.Dispose(); + } } - + //else user cancelled + return success; }
--- a/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs Mon Aug 17 19:17:35 2009 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GTK.FrmMainWindow.cs Mon Aug 17 19:49:05 2009 +0000 @@ -81,51 +81,51 @@ this.menuFile = new Gtk.Action("menuFile", Mono.Unix.Catalog.GetString("File"), null, null); this.menuFile.ShortLabel = Mono.Unix.Catalog.GetString("File"); w1.Add(this.menuFile, null); - this.miCreateArmy = new Gtk.Action("miCreateArmy", Mono.Unix.Catalog.GetString("Create army"), null, null); + this.miCreateArmy = new Gtk.Action("miCreateArmy", Mono.Unix.Catalog.GetString("Create army"), null, "gtk-new"); this.miCreateArmy.Sensitive = false; 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, 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, null); + this.miSaveArmy = new Gtk.Action("miSaveArmy", Mono.Unix.Catalog.GetString("Save army"), null, "gtk-save"); this.miSaveArmy.Sensitive = false; this.miSaveArmy.ShortLabel = Mono.Unix.Catalog.GetString("Save army"); w1.Add(this.miSaveArmy, null); - this.miSaveArmyAs = new Gtk.Action("miSaveArmyAs", Mono.Unix.Catalog.GetString("Save army as"), null, null); + this.miSaveArmyAs = new Gtk.Action("miSaveArmyAs", Mono.Unix.Catalog.GetString("Save army as"), null, "gtk-save-as"); this.miSaveArmyAs.Sensitive = false; this.miSaveArmyAs.ShortLabel = Mono.Unix.Catalog.GetString("Save army as"); w1.Add(this.miSaveArmyAs, null); - this.miCloseArmy = new Gtk.Action("miCloseArmy", Mono.Unix.Catalog.GetString("Close army"), null, null); + this.miCloseArmy = new Gtk.Action("miCloseArmy", Mono.Unix.Catalog.GetString("Close army"), null, "gtk-close"); this.miCloseArmy.Sensitive = false; this.miCloseArmy.ShortLabel = Mono.Unix.Catalog.GetString("Close army"); w1.Add(this.miCloseArmy, null); this.miChangeGameSystem = new Gtk.Action("miChangeGameSystem", Mono.Unix.Catalog.GetString("Change game system"), null, null); this.miChangeGameSystem.ShortLabel = Mono.Unix.Catalog.GetString("Change game system"); w1.Add(this.miChangeGameSystem, null); - this.miReloadFiles = new Gtk.Action("miReloadFiles", Mono.Unix.Catalog.GetString("Reload files"), null, null); + this.miReloadFiles = new Gtk.Action("miReloadFiles", Mono.Unix.Catalog.GetString("Reload files"), null, "gtk-refresh"); this.miReloadFiles.Sensitive = false; this.miReloadFiles.ShortLabel = Mono.Unix.Catalog.GetString("Reload files"); w1.Add(this.miReloadFiles, null); - this.miExit = new Gtk.Action("miExit", Mono.Unix.Catalog.GetString("Exit"), null, null); + this.miExit = new Gtk.Action("miExit", Mono.Unix.Catalog.GetString("Exit"), null, "gtk-quit"); this.miExit.ShortLabel = Mono.Unix.Catalog.GetString("Exit"); w1.Add(this.miExit, null); this.menuEdit = new Gtk.Action("menuEdit", Mono.Unix.Catalog.GetString("Edit"), null, null); this.menuEdit.ShortLabel = Mono.Unix.Catalog.GetString("Edit"); w1.Add(this.menuEdit, null); - this.miUndo = new Gtk.Action("miUndo", Mono.Unix.Catalog.GetString("Undo"), null, null); + this.miUndo = new Gtk.Action("miUndo", Mono.Unix.Catalog.GetString("Undo"), null, "gtk-undo"); this.miUndo.Sensitive = false; this.miUndo.ShortLabel = Mono.Unix.Catalog.GetString("Undo"); w1.Add(this.miUndo, null); - this.miRedo = new Gtk.Action("miRedo", Mono.Unix.Catalog.GetString("Redo"), null, null); + this.miRedo = new Gtk.Action("miRedo", Mono.Unix.Catalog.GetString("Redo"), null, "gtk-redo"); this.miRedo.Sensitive = false; this.miRedo.ShortLabel = Mono.Unix.Catalog.GetString("Redo"); w1.Add(this.miRedo, null); this.menuHelp = new Gtk.Action("menuHelp", Mono.Unix.Catalog.GetString("Help"), null, null); this.menuHelp.ShortLabel = Mono.Unix.Catalog.GetString("Help"); w1.Add(this.menuHelp, null); - this.miAbout = new Gtk.Action("miAbout", Mono.Unix.Catalog.GetString("About"), null, null); + this.miAbout = new Gtk.Action("miAbout", Mono.Unix.Catalog.GetString("About"), null, "gtk-about"); this.miAbout.ShortLabel = Mono.Unix.Catalog.GetString("About"); w1.Add(this.miAbout, null); this.miDebugInformation = new Gtk.Action("miDebugInformation", Mono.Unix.Catalog.GetString("Debug Information"), null, null); @@ -133,22 +133,29 @@ w1.Add(this.miDebugInformation, null); this.newArmyButton = new Gtk.Action("newArmyButton", null, null, "gtk-new"); this.newArmyButton.Sensitive = false; + this.newArmyButton.ShortLabel = ""; w1.Add(this.newArmyButton, null); this.openArmyButton = new Gtk.Action("openArmyButton", null, null, "gtk-open"); this.openArmyButton.Sensitive = false; + this.openArmyButton.ShortLabel = ""; w1.Add(this.openArmyButton, null); this.saveArmyButton = new Gtk.Action("saveArmyButton", null, null, "gtk-save"); this.saveArmyButton.Sensitive = false; + this.saveArmyButton.ShortLabel = ""; w1.Add(this.saveArmyButton, null); this.undoActionButton = new Gtk.Action("undoActionButton", null, null, "gtk-undo"); this.undoActionButton.Sensitive = false; + this.undoActionButton.ShortLabel = ""; w1.Add(this.undoActionButton, null); this.redoActionButton = new Gtk.Action("redoActionButton", null, null, "gtk-redo"); this.redoActionButton.Sensitive = false; + this.redoActionButton.ShortLabel = ""; w1.Add(this.redoActionButton, null); this.goDown = new Gtk.Action("goDown", null, null, null); + this.goDown.ShortLabel = ""; w1.Add(this.goDown, null); this.add = new Gtk.Action("add", null, null, "gtk-add"); + this.add.ShortLabel = ""; w1.Add(this.add, null); this.UIManager.InsertActionGroup(w1, 0); this.AddAccelGroup(this.UIManager.AccelGroup);
--- a/gtk-gui/gui.stetic Mon Aug 17 19:17:35 2009 +0000 +++ b/gtk-gui/gui.stetic Mon Aug 17 19:49:05 2009 +0000 @@ -115,6 +115,7 @@ <property name="Type">Action</property> <property name="Label" translatable="yes" /> <property name="Sensitive">False</property> + <property name="ShortLabel" translatable="yes" /> <property name="StockId">gtk-new</property> <signal name="Activated" handler="newTBButtonActivated" /> </action> @@ -122,6 +123,7 @@ <property name="Type">Action</property> <property name="Label" translatable="yes" /> <property name="Sensitive">False</property> + <property name="ShortLabel" translatable="yes" /> <property name="StockId">gtk-open</property> <signal name="Activated" handler="openTBButtonActivated" /> </action> @@ -129,6 +131,7 @@ <property name="Type">Action</property> <property name="Label" translatable="yes" /> <property name="Sensitive">False</property> + <property name="ShortLabel" translatable="yes" /> <property name="StockId">gtk-save</property> <signal name="Activated" handler="saveTBButtonActivated" /> </action> @@ -136,6 +139,7 @@ <property name="Type">Action</property> <property name="Label" translatable="yes" /> <property name="Sensitive">False</property> + <property name="ShortLabel" translatable="yes" /> <property name="StockId">gtk-undo</property> <signal name="Activated" handler="undoTBButtonActivated" /> </action> @@ -143,16 +147,19 @@ <property name="Type">Action</property> <property name="Label" translatable="yes" /> <property name="Sensitive">False</property> + <property name="ShortLabel" translatable="yes" /> <property name="StockId">gtk-redo</property> <signal name="Activated" handler="redoTBButtonActivated" /> </action> <action id="goDown"> <property name="Type">Action</property> <property name="Label" translatable="yes" /> + <property name="ShortLabel" translatable="yes" /> </action> <action id="add"> <property name="Type">Action</property> <property name="Label" translatable="yes" /> + <property name="ShortLabel" translatable="yes" /> <property name="StockId">gtk-add</property> </action> </action-group>