Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
changeset 125:42d2aa87dfa7
Re #361: Add XML export UI to GTK#
* Add basic UI that works (needs improvement)
* Open the dialog using Run() so that we can close it properly
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 01 Oct 2011 14:52:39 +0100 |
parents | a647afc19fe9 |
children | d4e6bfeb1c61 |
files | FrmExportXml.cs FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs gtk-gui/gui.stetic |
diffstat | 5 files changed, 216 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmExportXml.cs Wed Sep 28 21:01:54 2011 +0100 +++ b/FrmExportXml.cs Sat Oct 01 14:52:39 2011 +0100 @@ -5,13 +5,21 @@ using System.IO; using IBBoard.GtkSharp; using System.Collections.Generic; +using Gtk; +using IBBoard.WarFoundry.API.Objects; +using System.Xml.Xsl; +using IBBoard.Lang; +using IBBoard.WarFoundry.API.Exporters; namespace IBBoard.WarFoundry.GUI.GTK { public partial class FrmExportXml : Gtk.Dialog { - public FrmExportXml() + private Army army; + + public FrmExportXml(Army army) { + this.army = army; this.Build(); FillXsltList(); saveAsPath.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); @@ -34,7 +42,7 @@ private void SetOkayButtonSensitive() { - buttonOk.Sensitive = saveAsPath.Filename != null && (!doTransformWidget.Active || ComboBoxUtils.GetSelectedItem<FileInfo>(transformList) != null); + buttonOk.Sensitive = saveAsName.Text != "" && saveAsPath.Filename != null && saveAsPath.Filename != "" && (!doTransformWidget.Active || ComboBoxUtils.GetSelectedItem<FileInfo>(transformList) != null); } protected void OnTransformListChanged(object sender, System.EventArgs e) @@ -46,6 +54,69 @@ { SetOkayButtonSensitive(); } + + protected void OnButtonOkClicked (object sender, System.EventArgs e) + { + string errorMessage = ""; + // Catch potential errors with the file export or XSL compiliation + try + { + string fileName = System.IO.Path.Combine(saveAsPath.Filename, saveAsName.Text); + + if (doTransformWidget.Active) + { + WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, ComboBoxUtils.GetSelectedItem<FileInfo>(transformList).FullName); + } + 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; + } + + 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 OnSaveAsNameChanged (object sender, System.EventArgs e) + { + SetOkayButtonSensitive(); + } } }
--- a/FrmMainWindow.cs Wed Sep 28 21:01:54 2011 +0100 +++ b/FrmMainWindow.cs Sat Oct 01 14:52:39 2011 +0100 @@ -1177,8 +1177,10 @@ protected void OnTransformedXmlActionActivated (object sender, System.EventArgs e) { - FrmExportXml form = new FrmExportXml(); - form.ShowNow(); + FrmExportXml form = new FrmExportXml(WarFoundryCore.CurrentArmy); + form.Run(); + form.Hide(); + form.Dispose(); } } }
--- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs Wed Sep 28 21:01:54 2011 +0100 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs Sat Oct 01 14:52:39 2011 +0100 @@ -7,7 +7,9 @@ private global::Gtk.Table table; private global::Gtk.CheckButton doTransformWidget; private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblOutputFile; + private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblSaveIn; private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblTransform; + private global::Gtk.Entry saveAsName; private global::Gtk.FileChooserButton saveAsPath; private global::Gtk.ComboBox transformList; private global::Gtk.Button buttonCancel; @@ -18,13 +20,14 @@ 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)); // 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.table = new global::Gtk.Table (((uint)(3)), ((uint)(2)), false); + this.table = new global::Gtk.Table (((uint)(4)), ((uint)(2)), false); this.table.Name = "table"; this.table.RowSpacing = ((uint)(6)); this.table.ColumnSpacing = ((uint)(6)); @@ -37,8 +40,8 @@ this.doTransformWidget.UseUnderline = true; this.table.Add (this.doTransformWidget); global::Gtk.Table.TableChild w2 = ((global::Gtk.Table.TableChild)(this.table [this.doTransformWidget])); - w2.TopAttach = ((uint)(1)); - w2.BottomAttach = ((uint)(2)); + w2.TopAttach = ((uint)(2)); + w2.BottomAttach = ((uint)(3)); w2.LeftAttach = ((uint)(1)); w2.RightAttach = ((uint)(2)); w2.XOptions = ((global::Gtk.AttachOptions)(4)); @@ -47,53 +50,80 @@ this.lblOutputFile = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel (); this.lblOutputFile.Name = "lblOutputFile"; this.lblOutputFile.Xalign = 1F; - this.lblOutputFile.LabelProp = global::Mono.Unix.Catalog.GetString ("Save as:"); + this.lblOutputFile.LabelProp = global::Mono.Unix.Catalog.GetString ("save as:"); this.table.Add (this.lblOutputFile); global::Gtk.Table.TableChild w3 = ((global::Gtk.Table.TableChild)(this.table [this.lblOutputFile])); w3.XOptions = ((global::Gtk.AttachOptions)(4)); w3.YOptions = ((global::Gtk.AttachOptions)(4)); // Container child table.Gtk.Table+TableChild + this.lblSaveIn = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel (); + this.lblSaveIn.Name = "lblSaveIn"; + this.lblSaveIn.Xalign = 1F; + this.lblSaveIn.LabelProp = global::Mono.Unix.Catalog.GetString ("in folder"); + this.table.Add (this.lblSaveIn); + global::Gtk.Table.TableChild w4 = ((global::Gtk.Table.TableChild)(this.table [this.lblSaveIn])); + w4.TopAttach = ((uint)(1)); + w4.BottomAttach = ((uint)(2)); + w4.XOptions = ((global::Gtk.AttachOptions)(4)); + w4.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table.Gtk.Table+TableChild this.lblTransform = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel (); this.lblTransform.Sensitive = false; this.lblTransform.Name = "lblTransform"; - this.lblTransform.LabelProp = global::Mono.Unix.Catalog.GetString ("Transform:"); + this.lblTransform.LabelProp = global::Mono.Unix.Catalog.GetString ("transform:"); this.table.Add (this.lblTransform); - global::Gtk.Table.TableChild w4 = ((global::Gtk.Table.TableChild)(this.table [this.lblTransform])); - w4.TopAttach = ((uint)(2)); - w4.BottomAttach = ((uint)(3)); - w4.XOptions = ((global::Gtk.AttachOptions)(4)); - w4.YOptions = ((global::Gtk.AttachOptions)(4)); - // Container child table.Gtk.Table+TableChild - this.saveAsPath = new global::Gtk.FileChooserButton (global::Mono.Unix.Catalog.GetString ("Select A File"), ((global::Gtk.FileChooserAction)(0))); - this.saveAsPath.Name = "saveAsPath"; - this.table.Add (this.saveAsPath); - global::Gtk.Table.TableChild w5 = ((global::Gtk.Table.TableChild)(this.table [this.saveAsPath])); - w5.LeftAttach = ((uint)(1)); - w5.RightAttach = ((uint)(2)); + global::Gtk.Table.TableChild w5 = ((global::Gtk.Table.TableChild)(this.table [this.lblTransform])); + w5.TopAttach = ((uint)(3)); + w5.BottomAttach = ((uint)(4)); w5.XOptions = ((global::Gtk.AttachOptions)(4)); w5.YOptions = ((global::Gtk.AttachOptions)(4)); // Container child table.Gtk.Table+TableChild + this.saveAsName = new global::Gtk.Entry (); + this.saveAsName.CanFocus = true; + this.saveAsName.Name = "saveAsName"; + this.saveAsName.IsEditable = true; + this.saveAsName.InvisibleChar = '●'; + this.table.Add (this.saveAsName); + global::Gtk.Table.TableChild w6 = ((global::Gtk.Table.TableChild)(this.table [this.saveAsName])); + w6.LeftAttach = ((uint)(1)); + w6.RightAttach = ((uint)(2)); + w6.XOptions = ((global::Gtk.AttachOptions)(4)); + w6.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table.Gtk.Table+TableChild + this.saveAsPath = new global::Gtk.FileChooserButton (global::Mono.Unix.Catalog.GetString ("Select A File"), ((global::Gtk.FileChooserAction)(2))); + this.saveAsPath.Name = "saveAsPath"; + this.saveAsPath.WidthChars = 20; + this.saveAsPath.DoOverwriteConfirmation = true; + this.table.Add (this.saveAsPath); + global::Gtk.Table.TableChild w7 = ((global::Gtk.Table.TableChild)(this.table [this.saveAsPath])); + w7.TopAttach = ((uint)(1)); + w7.BottomAttach = ((uint)(2)); + w7.LeftAttach = ((uint)(1)); + w7.RightAttach = ((uint)(2)); + w7.XOptions = ((global::Gtk.AttachOptions)(4)); + w7.YOptions = ((global::Gtk.AttachOptions)(4)); + // Container child table.Gtk.Table+TableChild this.transformList = global::Gtk.ComboBox.NewText (); this.transformList.Sensitive = false; this.transformList.Name = "transformList"; this.table.Add (this.transformList); - global::Gtk.Table.TableChild w6 = ((global::Gtk.Table.TableChild)(this.table [this.transformList])); - w6.TopAttach = ((uint)(2)); - w6.BottomAttach = ((uint)(3)); - w6.LeftAttach = ((uint)(1)); - w6.RightAttach = ((uint)(2)); - w6.YOptions = ((global::Gtk.AttachOptions)(4)); + global::Gtk.Table.TableChild w8 = ((global::Gtk.Table.TableChild)(this.table [this.transformList])); + w8.TopAttach = ((uint)(3)); + w8.BottomAttach = ((uint)(4)); + w8.LeftAttach = ((uint)(1)); + w8.RightAttach = ((uint)(2)); + w8.YOptions = ((global::Gtk.AttachOptions)(4)); w1.Add (this.table); - global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(w1 [this.table])); - w7.Position = 0; - w7.Expand = false; - w7.Fill = false; + global::Gtk.Box.BoxChild w9 = ((global::Gtk.Box.BoxChild)(w1 [this.table])); + w9.Position = 0; + w9.Expand = false; + w9.Fill = false; // Internal child IBBoard.WarFoundry.GUI.GTK.FrmExportXml.ActionArea - global::Gtk.HButtonBox w8 = this.ActionArea; - w8.Name = "dialog1_ActionArea"; - w8.Spacing = 10; - w8.BorderWidth = ((uint)(5)); - w8.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4)); + global::Gtk.HButtonBox w10 = this.ActionArea; + w10.Name = "dialog1_ActionArea"; + w10.Spacing = 10; + w10.BorderWidth = ((uint)(5)); + w10.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4)); // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild this.buttonCancel = new global::Gtk.Button (); this.buttonCancel.CanDefault = true; @@ -103,9 +133,9 @@ this.buttonCancel.UseUnderline = true; this.buttonCancel.Label = "gtk-cancel"; this.AddActionWidget (this.buttonCancel, -6); - global::Gtk.ButtonBox.ButtonBoxChild w9 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w8 [this.buttonCancel])); - w9.Expand = false; - w9.Fill = false; + global::Gtk.ButtonBox.ButtonBoxChild w11 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w10 [this.buttonCancel])); + w11.Expand = false; + w11.Fill = false; // Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild this.buttonOk = new global::Gtk.Button (); this.buttonOk.CanDefault = true; @@ -115,19 +145,22 @@ this.buttonOk.UseUnderline = true; this.buttonOk.Label = "gtk-ok"; this.AddActionWidget (this.buttonOk, -5); - global::Gtk.ButtonBox.ButtonBoxChild w10 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w8 [this.buttonOk])); - w10.Position = 1; - w10.Expand = false; - w10.Fill = false; + global::Gtk.ButtonBox.ButtonBoxChild w12 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w10 [this.buttonOk])); + w12.Position = 1; + w12.Expand = false; + w12.Fill = false; if ((this.Child != null)) { this.Child.ShowAll (); } - this.DefaultWidth = 336; - this.DefaultHeight = 171; + this.DefaultWidth = 397; + this.DefaultHeight = 300; this.Show (); this.transformList.Changed += new global::System.EventHandler (this.OnTransformListChanged); this.saveAsPath.SelectionChanged += new global::System.EventHandler (this.OnSaveAsPathSelectionChanged); + this.saveAsName.Changed += new global::System.EventHandler (this.OnSaveAsNameChanged); this.doTransformWidget.Toggled += new global::System.EventHandler (this.OnDoTransformWidgetToggled); + this.buttonCancel.Clicked += new global::System.EventHandler (this.OnButtonCancelClicked); + this.buttonOk.Clicked += new global::System.EventHandler (this.OnButtonOkClicked); } } }
--- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs Wed Sep 28 21:01:54 2011 +0100 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs Sat Oct 01 14:52:39 2011 +0100 @@ -29,6 +29,7 @@ private global::Gtk.Action miExportArmyAs; private global::Gtk.Action miExportArmyAsBasicHTML; private global::Gtk.Action miPreferences; + private global::Gtk.Action transformedXmlAction; private global::Gtk.VBox vbox1; private global::Gtk.MenuBar menubar1; private global::Gtk.Toolbar toolbar; @@ -118,6 +119,9 @@ this.miPreferences = new global::Gtk.Action("miPreferences", global::Mono.Unix.Catalog.GetString("preferences"), null, "gtk-preferences"); this.miPreferences.ShortLabel = global::Mono.Unix.Catalog.GetString("preferences"); w1.Add(this.miPreferences, null); + this.transformedXmlAction = new global::Gtk.Action ("transformedXmlAction", global::Mono.Unix.Catalog.GetString ("transformed xml"), null, null); + this.transformedXmlAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("transformed xml"); + w1.Add (this.transformedXmlAction, null); this.UIManager.InsertActionGroup(w1, 0); this.AddAccelGroup(this.UIManager.AccelGroup); this.Name = "IBBoard.WarFoundry.GUI.GTK.FrmMainWindow"; @@ -211,6 +215,7 @@ this.bttnRedo.Activated += new global::System.EventHandler(this.redoTBButtonActivated); this.miExportArmyAsBasicHTML.Activated += new global::System.EventHandler(this.OnMiExportAsBasicHtmlActivated); this.miPreferences.Activated += new global::System.EventHandler(this.miPreferencesClicked); + this.transformedXmlAction.Activated += new global::System.EventHandler (this.OnTransformedXmlActionActivated); this.treeUnits.RowActivated += new global::Gtk.RowActivatedHandler(this.ArmyRowActivated); this.treeUnits.PopupMenu += new global::Gtk.PopupMenuHandler(this.OnTreeUnitsPopupMenu); this.treeUnits.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler(this.UnitTreeButtonPressed);
--- a/gtk-gui/gui.stetic Wed Sep 28 21:01:54 2011 +0100 +++ b/gtk-gui/gui.stetic Sat Oct 01 14:52:39 2011 +0100 @@ -2532,8 +2532,9 @@ </widget> </child> </widget> - <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmExportXml" design-size="336 171"> + <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmExportXml" design-size="397 300"> <property name="MemberName" /> + <property name="TypeHint">Dialog</property> <property name="WindowPosition">CenterOnParent</property> <property name="Buttons">2</property> <property name="HelpButton">False</property> @@ -2544,7 +2545,7 @@ <child> <widget class="Gtk.Table" id="table"> <property name="MemberName" /> - <property name="NRows">3</property> + <property name="NRows">4</property> <property name="NColumns">2</property> <property name="RowSpacing">6</property> <property name="ColumnSpacing">6</property> @@ -2562,8 +2563,8 @@ <signal name="Toggled" handler="OnDoTransformWidgetToggled" /> </widget> <packing> - <property name="TopAttach">1</property> - <property name="BottomAttach">2</property> + <property name="TopAttach">2</property> + <property name="BottomAttach">3</property> <property name="LeftAttach">1</property> <property name="RightAttach">2</property> <property name="AutoSize">True</property> @@ -2581,7 +2582,7 @@ <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblOutputFile"> <property name="MemberName" /> <property name="Xalign">1</property> - <property name="LabelProp" translatable="yes">Save as:</property> + <property name="LabelProp" translatable="yes">save as:</property> </widget> <packing> <property name="AutoSize">True</property> @@ -2596,14 +2597,56 @@ </packing> </child> <child> + <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblSaveIn"> + <property name="MemberName" /> + <property name="Xalign">1</property> + <property name="LabelProp" translatable="yes">in folder</property> + </widget> + <packing> + <property name="TopAttach">1</property> + <property name="BottomAttach">2</property> + <property name="AutoSize">True</property> + <property name="XOptions">Fill</property> + <property name="YOptions">Fill</property> + <property name="XExpand">False</property> + <property name="XFill">True</property> + <property name="XShrink">False</property> + <property name="YExpand">False</property> + <property name="YFill">True</property> + <property name="YShrink">False</property> + </packing> + </child> + <child> <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblTransform"> <property name="MemberName" /> <property name="Sensitive">False</property> - <property name="LabelProp" translatable="yes">Transform:</property> + <property name="LabelProp" translatable="yes">transform:</property> </widget> <packing> - <property name="TopAttach">2</property> - <property name="BottomAttach">3</property> + <property name="TopAttach">3</property> + <property name="BottomAttach">4</property> + <property name="AutoSize">True</property> + <property name="XOptions">Fill</property> + <property name="YOptions">Fill</property> + <property name="XExpand">False</property> + <property name="XFill">True</property> + <property name="XShrink">False</property> + <property name="YExpand">False</property> + <property name="YFill">True</property> + <property name="YShrink">False</property> + </packing> + </child> + <child> + <widget class="Gtk.Entry" id="saveAsName"> + <property name="MemberName" /> + <property name="CanFocus">True</property> + <property name="IsEditable">True</property> + <property name="InvisibleChar">●</property> + <signal name="Changed" handler="OnSaveAsNameChanged" /> + </widget> + <packing> + <property name="LeftAttach">1</property> + <property name="RightAttach">2</property> <property name="AutoSize">True</property> <property name="XOptions">Fill</property> <property name="YOptions">Fill</property> @@ -2618,9 +2661,14 @@ <child> <widget class="Gtk.FileChooserButton" id="saveAsPath"> <property name="MemberName" /> + <property name="Action">SelectFolder</property> + <property name="WidthChars">20</property> + <property name="DoOverwriteConfirmation">True</property> <signal name="SelectionChanged" handler="OnSaveAsPathSelectionChanged" /> </widget> <packing> + <property name="TopAttach">1</property> + <property name="BottomAttach">2</property> <property name="LeftAttach">1</property> <property name="RightAttach">2</property> <property name="AutoSize">True</property> @@ -2643,8 +2691,8 @@ <signal name="Changed" handler="OnTransformListChanged" /> </widget> <packing> - <property name="TopAttach">2</property> - <property name="BottomAttach">3</property> + <property name="TopAttach">3</property> + <property name="BottomAttach">4</property> <property name="LeftAttach">1</property> <property name="RightAttach">2</property> <property name="AutoSize">False</property> @@ -2683,6 +2731,7 @@ <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> @@ -2699,6 +2748,7 @@ <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>