Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
changeset 128:d5a631a8d288
Re #361: XML Export in GTK#
* Inherit from FileChooserDialog so that we get the resize behaviour
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 01 Oct 2011 17:04:22 +0100 |
parents | 786a3afb9240 |
children | ac4231d6c3f0 |
files | FrmExportXml.cs IBBoard.WarFoundry.GUI.GTK.csproj gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs gtk-gui/gui.stetic |
diffstat | 4 files changed, 64 insertions(+), 210 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmExportXml.cs Sat Oct 01 16:49:35 2011 +0100 +++ b/FrmExportXml.cs Sat Oct 01 17:04:22 2011 +0100 @@ -13,19 +13,23 @@ namespace IBBoard.WarFoundry.GUI.GTK { - public partial class FrmExportXml : Gtk.Dialog + public partial class FrmExportXml : FileChooserDialog { private Army army; private TransformXmlWidget transformWidget; + private Button buttonOk; - public FrmExportXml(Army army) + public FrmExportXml(Army army) : base("", null, FileChooserAction.Save) { this.army = army; - this.Build(); + AddButton(Gtk.Stock.Cancel, ResponseType.Cancel); + buttonOk = (Button)AddButton(Gtk.Stock.Save, ResponseType.Ok); + buttonOk.Clicked+=OnButtonOkClicked; transformWidget = new TransformXmlWidget(); transformWidget.TransformChanged += HandleTransformWidgetTransformChanged; - saveAsPath.ExtraWidget = transformWidget; - saveAsPath.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); + ExtraWidget = transformWidget; + SetFilename(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "export.xml")); + SelectionChanged += OnSaveAsPathSelectionChanged; } private void HandleTransformWidgetTransformChanged (object sender, EventArgs e) @@ -33,9 +37,16 @@ SetOkayButtonSensitive(); } + private bool IsValid () + { + return Filename != null && Filename != "" && transformWidget.IsValid; + } + private void SetOkayButtonSensitive() { - buttonOk.Sensitive = saveAsPath.Filename != null && saveAsPath.Filename != "" && transformWidget.IsValid; + //TODO: It would be nice to disable save when appropriate options aren't set, + //but we don't seem to get change notifications early enough + //buttonOk.Sensitive = IsValid(); } protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e) @@ -45,67 +56,59 @@ protected void OnButtonOkClicked (object sender, System.EventArgs e) { - string errorMessage = ""; - // Catch potential errors with the file export or XSL compiliation - try - { - string fileName = saveAsPath.Filename; + if (IsValid()) + { + DoExport(); + } + } - if (transformWidget.TransformEnabled) - { - WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath()); - } - else - { - WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName); - } - } - catch (XsltCompileException ex) - { - errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + - ":\n" + ex.Message; - } - catch (XsltException ex) - { + void DoExport() + { + string errorMessage = ""; + // Catch potential errors with the file export or XSL compiliation + try + { + string fileName = Filename; + + if (transformWidget.TransformEnabled) + { + WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath()); + } + else + { + WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName); + } + } + catch (XsltCompileException ex) + { + errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + ":\n" + ex.Message; + } + catch (XsltException ex) + { + + errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + ":\n" + ex.Message; + } + catch (FileNotFoundException ex) + { + errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + ":\n" + ex.Message; + } + catch (IOException ex) + { + errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + ":\n" + ex.Message; + } + catch (Exception ex) + { + errorMessage = Translation.GetTranslation("mbErrorFailed", "") + ":\n" + ex.Message; + } - errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + - ":\n" + ex.Message; - } - catch (FileNotFoundException ex) - { - errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + - ":\n" + ex.Message; - } - catch (IOException ex) - { - errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + - ":\n" + ex.Message; - } - catch (Exception ex) - { - errorMessage = Translation.GetTranslation("mbErrorFailed", "") + - ":\n" + ex.Message; - } - - if (errorMessage != "") - { + if (errorMessage != "") + { MessageDialog dialog = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, errorMessage); dialog.Run(); - } - + } + Respond(ResponseType.Ok); } - - protected void OnButtonCancelClicked (object sender, System.EventArgs e) - { - Respond(ResponseType.Cancel); - } - - protected void OnSizeAllocated (object o, Gtk.SizeAllocatedArgs args) - { - Console.WriteLine(args.Allocation.Height + "," + args.Allocation.Width); - //this. - } } }
--- a/IBBoard.WarFoundry.GUI.GTK.csproj Sat Oct 01 16:49:35 2011 +0100 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj Sat Oct 01 17:04:22 2011 +0100 @@ -73,7 +73,6 @@ <Compile Include="FrmPreferences.cs" /> <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmPreferences.cs" /> <Compile Include="FrmExportXml.cs" /> - <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs" /> <Compile Include="Widgets\TransformXmlWidget.cs" /> <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget.cs" /> </ItemGroup>
--- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs Sat Oct 01 16:49:35 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ - -// This file has been generated by the GUI designer. Do not modify. -namespace IBBoard.WarFoundry.GUI.GTK -{ - public partial class FrmExportXml - { - private global::Gtk.FileChooserWidget saveAsPath; - private global::Gtk.Button buttonCancel; - private global::Gtk.Button buttonOk; - - protected virtual void Build () - { - global::Stetic.Gui.Initialize (this); - // Widget IBBoard.WarFoundry.GUI.GTK.FrmExportXml - this.Name = "IBBoard.WarFoundry.GUI.GTK.FrmExportXml"; - this.TypeHint = ((global::Gdk.WindowTypeHint)(1)); - this.WindowPosition = ((global::Gtk.WindowPosition)(4)); - this.SkipPagerHint = true; - this.SkipTaskbarHint = true; - // Internal child IBBoard.WarFoundry.GUI.GTK.FrmExportXml.VBox - global::Gtk.VBox w1 = this.VBox; - w1.Name = "dialog1_VBox"; - w1.BorderWidth = ((uint)(2)); - // Container child dialog1_VBox.Gtk.Box+BoxChild - this.saveAsPath = new global::Gtk.FileChooserWidget (((global::Gtk.FileChooserAction)(1))); - this.saveAsPath.Name = "saveAsPath"; - this.saveAsPath.LocalOnly = false; - this.saveAsPath.DoOverwriteConfirmation = true; - w1.Add (this.saveAsPath); - global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(w1 [this.saveAsPath])); - w2.Position = 0; - // Internal child IBBoard.WarFoundry.GUI.GTK.FrmExportXml.ActionArea - global::Gtk.HButtonBox w3 = this.ActionArea; - w3.Name = "dialog1_ActionArea"; - w3.Spacing = 10; - w3.BorderWidth = ((uint)(5)); - w3.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4)); - // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild - this.buttonCancel = new global::Gtk.Button (); - this.buttonCancel.CanDefault = true; - this.buttonCancel.CanFocus = true; - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.UseStock = true; - this.buttonCancel.UseUnderline = true; - this.buttonCancel.Label = "gtk-cancel"; - this.AddActionWidget (this.buttonCancel, -6); - global::Gtk.ButtonBox.ButtonBoxChild w4 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w3 [this.buttonCancel])); - w4.Expand = false; - w4.Fill = false; - // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild - this.buttonOk = new global::Gtk.Button (); - this.buttonOk.CanDefault = true; - this.buttonOk.CanFocus = true; - this.buttonOk.Name = "buttonOk"; - this.buttonOk.UseStock = true; - this.buttonOk.UseUnderline = true; - this.buttonOk.Label = "gtk-ok"; - this.AddActionWidget (this.buttonOk, -5); - global::Gtk.ButtonBox.ButtonBoxChild w5 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w3 [this.buttonOk])); - w5.Position = 1; - w5.Expand = false; - w5.Fill = false; - if ((this.Child != null)) { - this.Child.ShowAll (); - } - this.DefaultWidth = 634; - this.DefaultHeight = 468; - this.Show (); - this.SizeAllocated += new global::Gtk.SizeAllocatedHandler (this.OnSizeAllocated); - this.saveAsPath.SelectionChanged += new global::System.EventHandler (this.OnSaveAsPathSelectionChanged); - this.buttonCancel.Clicked += new global::System.EventHandler (this.OnButtonCancelClicked); - this.buttonOk.Clicked += new global::System.EventHandler (this.OnButtonOkClicked); - } - } -}
--- a/gtk-gui/gui.stetic Sat Oct 01 16:49:35 2011 +0100 +++ b/gtk-gui/gui.stetic Sat Oct 01 17:04:22 2011 +0100 @@ -2532,79 +2532,6 @@ </widget> </child> </widget> - <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmExportXml" design-size="634 468"> - <property name="MemberName" /> - <property name="TypeHint">Dialog</property> - <property name="WindowPosition">CenterOnParent</property> - <property name="SkipPagerHint">True</property> - <property name="SkipTaskbarHint">True</property> - <property name="Buttons">2</property> - <property name="HelpButton">False</property> - <signal name="SizeAllocated" handler="OnSizeAllocated" after="yes" /> - <child internal-child="VBox"> - <widget class="Gtk.VBox" id="dialog1_VBox"> - <property name="MemberName" /> - <property name="BorderWidth">2</property> - <child> - <widget class="Gtk.FileChooserWidget" id="saveAsPath"> - <property name="MemberName" /> - <property name="Action">Save</property> - <property name="LocalOnly">False</property> - <property name="DoOverwriteConfirmation">True</property> - <signal name="SelectionChanged" handler="OnSaveAsPathSelectionChanged" /> - </widget> - <packing> - <property name="Position">0</property> - <property name="AutoSize">False</property> - </packing> - </child> - </widget> - </child> - <child internal-child="ActionArea"> - <widget class="Gtk.HButtonBox" id="dialog1_ActionArea"> - <property name="MemberName" /> - <property name="Spacing">10</property> - <property name="BorderWidth">5</property> - <property name="Size">2</property> - <property name="LayoutStyle">End</property> - <child> - <widget class="Gtk.Button" id="buttonCancel"> - <property name="MemberName" /> - <property name="CanDefault">True</property> - <property name="CanFocus">True</property> - <property name="UseStock">True</property> - <property name="Type">StockItem</property> - <property name="StockId">gtk-cancel</property> - <property name="ResponseId">-6</property> - <signal name="Clicked" handler="OnButtonCancelClicked" /> - <property name="label">gtk-cancel</property> - </widget> - <packing> - <property name="Expand">False</property> - <property name="Fill">False</property> - </packing> - </child> - <child> - <widget class="Gtk.Button" id="buttonOk"> - <property name="MemberName" /> - <property name="CanDefault">True</property> - <property name="CanFocus">True</property> - <property name="UseStock">True</property> - <property name="Type">StockItem</property> - <property name="StockId">gtk-ok</property> - <property name="ResponseId">-5</property> - <signal name="Clicked" handler="OnButtonOkClicked" /> - <property name="label">gtk-ok</property> - </widget> - <packing> - <property name="Position">1</property> - <property name="Expand">False</property> - <property name="Fill">False</property> - </packing> - </child> - </widget> - </child> - </widget> <widget class="Gtk.Bin" id="IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget" design-size="300 55"> <property name="MemberName" /> <property name="Visible">False</property>