# HG changeset patch # User IBBoard # Date 1317485062 -3600 # Node ID d5a631a8d28872061ad8adc1cf354c9f12f5cb03 # Parent 786a3afb92404ac8e91f53c0f0ef0821e8b36fbf Re #361: XML Export in GTK# * Inherit from FileChooserDialog so that we get the resize behaviour diff -r 786a3afb9240 -r d5a631a8d288 FrmExportXml.cs --- 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. - } } } diff -r 786a3afb9240 -r d5a631a8d288 IBBoard.WarFoundry.GUI.GTK.csproj --- 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 @@ - diff -r 786a3afb9240 -r d5a631a8d288 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs --- 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); - } - } -} diff -r 786a3afb9240 -r d5a631a8d288 gtk-gui/gui.stetic --- 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 @@ - - - Dialog - CenterOnParent - True - True - 2 - False - - - - - 2 - - - - Save - False - True - - - - 0 - False - - - - - - - - 10 - 5 - 2 - End - - - - True - True - True - StockItem - gtk-cancel - -6 - - gtk-cancel - - - False - False - - - - - - True - True - True - StockItem - gtk-ok - -5 - - gtk-ok - - - 1 - False - False - - - - - False