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 diff
     1.1 --- a/FrmExportXml.cs	Sat Oct 01 16:49:35 2011 +0100
     1.2 +++ b/FrmExportXml.cs	Sat Oct 01 17:04:22 2011 +0100
     1.3 @@ -13,19 +13,23 @@
     1.4  
     1.5  namespace IBBoard.WarFoundry.GUI.GTK
     1.6  {
     1.7 -	public partial class FrmExportXml : Gtk.Dialog
     1.8 +	public partial class FrmExportXml : FileChooserDialog
     1.9  	{
    1.10  		private Army army;
    1.11  		private TransformXmlWidget transformWidget;
    1.12 +		private Button buttonOk;
    1.13  
    1.14 -		public FrmExportXml(Army army)
    1.15 +		public FrmExportXml(Army army) : base("", null, FileChooserAction.Save)
    1.16  		{
    1.17  			this.army = army;
    1.18 -			this.Build();
    1.19 +			AddButton(Gtk.Stock.Cancel, ResponseType.Cancel);
    1.20 +			buttonOk = (Button)AddButton(Gtk.Stock.Save, ResponseType.Ok);
    1.21 +			buttonOk.Clicked+=OnButtonOkClicked;
    1.22  			transformWidget = new TransformXmlWidget();
    1.23  			transformWidget.TransformChanged += HandleTransformWidgetTransformChanged;
    1.24 -			saveAsPath.ExtraWidget = transformWidget;
    1.25 -			saveAsPath.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
    1.26 +			ExtraWidget = transformWidget;
    1.27 +			SetFilename(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "export.xml"));
    1.28 +			SelectionChanged += OnSaveAsPathSelectionChanged;
    1.29  		}
    1.30  
    1.31  		private void HandleTransformWidgetTransformChanged (object sender, EventArgs e)
    1.32 @@ -33,9 +37,16 @@
    1.33  			SetOkayButtonSensitive();
    1.34  		}
    1.35  
    1.36 +		private bool IsValid ()
    1.37 +		{
    1.38 +			return Filename != null && Filename != "" && transformWidget.IsValid;
    1.39 +		}
    1.40 +
    1.41  		private void SetOkayButtonSensitive()
    1.42  		{
    1.43 -			buttonOk.Sensitive = saveAsPath.Filename != null && saveAsPath.Filename != "" && transformWidget.IsValid;
    1.44 +			//TODO: It would be nice to disable save when appropriate options aren't set,
    1.45 +			//but we don't seem to get change notifications early enough
    1.46 +			//buttonOk.Sensitive = IsValid();
    1.47  		}
    1.48  
    1.49  		protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e)
    1.50 @@ -45,67 +56,59 @@
    1.51  
    1.52  		protected void OnButtonOkClicked (object sender, System.EventArgs e)
    1.53  		{
    1.54 +			if (IsValid())
    1.55 +			{
    1.56 +				DoExport();
    1.57 +			}
    1.58 +		}
    1.59 +
    1.60 +		void DoExport()
    1.61 +		{
    1.62  			string errorMessage = "";
    1.63 -            // Catch potential errors with the file export or XSL compiliation
    1.64 -            try
    1.65 -            {
    1.66 -                string fileName = saveAsPath.Filename;
    1.67 +			// Catch potential errors with the file export or XSL compiliation
    1.68 +			try
    1.69 +			{
    1.70 +				string fileName = Filename;
    1.71 +	
    1.72 +				if (transformWidget.TransformEnabled)
    1.73 +				{
    1.74 +					WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath());
    1.75 +				}
    1.76 +				else
    1.77 +				{
    1.78 +					WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName);
    1.79 +				}
    1.80 +			}
    1.81 +			catch (XsltCompileException ex)
    1.82 +			{
    1.83 +				errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + ":\n" + ex.Message;
    1.84 +			}
    1.85 +			catch (XsltException ex)
    1.86 +			{
    1.87 +	
    1.88 +				errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + ":\n" + ex.Message;
    1.89 +			}
    1.90 +			catch (FileNotFoundException ex)
    1.91 +			{
    1.92 +				errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + ":\n" + ex.Message;
    1.93 +			}
    1.94 +			catch (IOException ex)
    1.95 +			{
    1.96 +				errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + ":\n" + ex.Message;
    1.97 +			}
    1.98 +			catch (Exception ex)
    1.99 +			{
   1.100 +				errorMessage = Translation.GetTranslation("mbErrorFailed", "") + ":\n" + ex.Message;
   1.101 +			}
   1.102  
   1.103 -                if (transformWidget.TransformEnabled)
   1.104 -                {
   1.105 -                    WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath());
   1.106 -                }
   1.107 -                else
   1.108 -                {
   1.109 -                    WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName);
   1.110 -                }
   1.111 -            }
   1.112 -            catch (XsltCompileException ex)
   1.113 -            {
   1.114 -                errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") +
   1.115 -                    ":\n" + ex.Message;
   1.116 -            }
   1.117 -            catch (XsltException ex)
   1.118 -            {
   1.119 -
   1.120 -                errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") +
   1.121 -                    ":\n" + ex.Message;
   1.122 -            }
   1.123 -            catch (FileNotFoundException ex)
   1.124 -            {
   1.125 -                errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") +
   1.126 -                    ":\n" + ex.Message;
   1.127 -            }
   1.128 -            catch (IOException ex)
   1.129 -            {
   1.130 -                errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") +
   1.131 -                    ":\n" + ex.Message;
   1.132 -            }
   1.133 -            catch (Exception ex)
   1.134 -            {
   1.135 -                errorMessage = Translation.GetTranslation("mbErrorFailed", "") +
   1.136 -                    ":\n" + ex.Message;
   1.137 -            }
   1.138 -
   1.139 -            if (errorMessage != "")
   1.140 -            {
   1.141 +			if (errorMessage != "")
   1.142 +			{
   1.143  				MessageDialog dialog = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, errorMessage);
   1.144  				dialog.Run();
   1.145 -            }
   1.146 -
   1.147 +			}
   1.148 +			
   1.149  			Respond(ResponseType.Ok);
   1.150  		}
   1.151 -
   1.152 -		protected void OnButtonCancelClicked (object sender, System.EventArgs e)
   1.153 -		{
   1.154 -			Respond(ResponseType.Cancel);
   1.155 -		}
   1.156 -
   1.157 -		protected void OnSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
   1.158 -		{
   1.159 -			Console.WriteLine(args.Allocation.Height + "," + args.Allocation.Width);
   1.160 -			//this.
   1.161 -		}
   1.162  	}
   1.163  }
   1.164  
     2.1 --- a/IBBoard.WarFoundry.GUI.GTK.csproj	Sat Oct 01 16:49:35 2011 +0100
     2.2 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj	Sat Oct 01 17:04:22 2011 +0100
     2.3 @@ -73,7 +73,6 @@
     2.4      <Compile Include="FrmPreferences.cs" />
     2.5      <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmPreferences.cs" />
     2.6      <Compile Include="FrmExportXml.cs" />
     2.7 -    <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs" />
     2.8      <Compile Include="Widgets\TransformXmlWidget.cs" />
     2.9      <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget.cs" />
    2.10    </ItemGroup>
     3.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmExportXml.cs	Sat Oct 01 16:49:35 2011 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,75 +0,0 @@
     3.4 -
     3.5 -// This file has been generated by the GUI designer. Do not modify.
     3.6 -namespace IBBoard.WarFoundry.GUI.GTK
     3.7 -{
     3.8 -	public partial class FrmExportXml
     3.9 -	{
    3.10 -		private global::Gtk.FileChooserWidget saveAsPath;
    3.11 -		private global::Gtk.Button buttonCancel;
    3.12 -		private global::Gtk.Button buttonOk;
    3.13 -		
    3.14 -		protected virtual void Build ()
    3.15 -		{
    3.16 -			global::Stetic.Gui.Initialize (this);
    3.17 -			// Widget IBBoard.WarFoundry.GUI.GTK.FrmExportXml
    3.18 -			this.Name = "IBBoard.WarFoundry.GUI.GTK.FrmExportXml";
    3.19 -			this.TypeHint = ((global::Gdk.WindowTypeHint)(1));
    3.20 -			this.WindowPosition = ((global::Gtk.WindowPosition)(4));
    3.21 -			this.SkipPagerHint = true;
    3.22 -			this.SkipTaskbarHint = true;
    3.23 -			// Internal child IBBoard.WarFoundry.GUI.GTK.FrmExportXml.VBox
    3.24 -			global::Gtk.VBox w1 = this.VBox;
    3.25 -			w1.Name = "dialog1_VBox";
    3.26 -			w1.BorderWidth = ((uint)(2));
    3.27 -			// Container child dialog1_VBox.Gtk.Box+BoxChild
    3.28 -			this.saveAsPath = new global::Gtk.FileChooserWidget (((global::Gtk.FileChooserAction)(1)));
    3.29 -			this.saveAsPath.Name = "saveAsPath";
    3.30 -			this.saveAsPath.LocalOnly = false;
    3.31 -			this.saveAsPath.DoOverwriteConfirmation = true;
    3.32 -			w1.Add (this.saveAsPath);
    3.33 -			global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(w1 [this.saveAsPath]));
    3.34 -			w2.Position = 0;
    3.35 -			// Internal child IBBoard.WarFoundry.GUI.GTK.FrmExportXml.ActionArea
    3.36 -			global::Gtk.HButtonBox w3 = this.ActionArea;
    3.37 -			w3.Name = "dialog1_ActionArea";
    3.38 -			w3.Spacing = 10;
    3.39 -			w3.BorderWidth = ((uint)(5));
    3.40 -			w3.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4));
    3.41 -			// Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
    3.42 -			this.buttonCancel = new global::Gtk.Button ();
    3.43 -			this.buttonCancel.CanDefault = true;
    3.44 -			this.buttonCancel.CanFocus = true;
    3.45 -			this.buttonCancel.Name = "buttonCancel";
    3.46 -			this.buttonCancel.UseStock = true;
    3.47 -			this.buttonCancel.UseUnderline = true;
    3.48 -			this.buttonCancel.Label = "gtk-cancel";
    3.49 -			this.AddActionWidget (this.buttonCancel, -6);
    3.50 -			global::Gtk.ButtonBox.ButtonBoxChild w4 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w3 [this.buttonCancel]));
    3.51 -			w4.Expand = false;
    3.52 -			w4.Fill = false;
    3.53 -			// Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
    3.54 -			this.buttonOk = new global::Gtk.Button ();
    3.55 -			this.buttonOk.CanDefault = true;
    3.56 -			this.buttonOk.CanFocus = true;
    3.57 -			this.buttonOk.Name = "buttonOk";
    3.58 -			this.buttonOk.UseStock = true;
    3.59 -			this.buttonOk.UseUnderline = true;
    3.60 -			this.buttonOk.Label = "gtk-ok";
    3.61 -			this.AddActionWidget (this.buttonOk, -5);
    3.62 -			global::Gtk.ButtonBox.ButtonBoxChild w5 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w3 [this.buttonOk]));
    3.63 -			w5.Position = 1;
    3.64 -			w5.Expand = false;
    3.65 -			w5.Fill = false;
    3.66 -			if ((this.Child != null)) {
    3.67 -				this.Child.ShowAll ();
    3.68 -			}
    3.69 -			this.DefaultWidth = 634;
    3.70 -			this.DefaultHeight = 468;
    3.71 -			this.Show ();
    3.72 -			this.SizeAllocated += new global::Gtk.SizeAllocatedHandler (this.OnSizeAllocated);
    3.73 -			this.saveAsPath.SelectionChanged += new global::System.EventHandler (this.OnSaveAsPathSelectionChanged);
    3.74 -			this.buttonCancel.Clicked += new global::System.EventHandler (this.OnButtonCancelClicked);
    3.75 -			this.buttonOk.Clicked += new global::System.EventHandler (this.OnButtonOkClicked);
    3.76 -		}
    3.77 -	}
    3.78 -}
     4.1 --- a/gtk-gui/gui.stetic	Sat Oct 01 16:49:35 2011 +0100
     4.2 +++ b/gtk-gui/gui.stetic	Sat Oct 01 17:04:22 2011 +0100
     4.3 @@ -2532,79 +2532,6 @@
     4.4        </widget>
     4.5      </child>
     4.6    </widget>
     4.7 -  <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmExportXml" design-size="634 468">
     4.8 -    <property name="MemberName" />
     4.9 -    <property name="TypeHint">Dialog</property>
    4.10 -    <property name="WindowPosition">CenterOnParent</property>
    4.11 -    <property name="SkipPagerHint">True</property>
    4.12 -    <property name="SkipTaskbarHint">True</property>
    4.13 -    <property name="Buttons">2</property>
    4.14 -    <property name="HelpButton">False</property>
    4.15 -    <signal name="SizeAllocated" handler="OnSizeAllocated" after="yes" />
    4.16 -    <child internal-child="VBox">
    4.17 -      <widget class="Gtk.VBox" id="dialog1_VBox">
    4.18 -        <property name="MemberName" />
    4.19 -        <property name="BorderWidth">2</property>
    4.20 -        <child>
    4.21 -          <widget class="Gtk.FileChooserWidget" id="saveAsPath">
    4.22 -            <property name="MemberName" />
    4.23 -            <property name="Action">Save</property>
    4.24 -            <property name="LocalOnly">False</property>
    4.25 -            <property name="DoOverwriteConfirmation">True</property>
    4.26 -            <signal name="SelectionChanged" handler="OnSaveAsPathSelectionChanged" />
    4.27 -          </widget>
    4.28 -          <packing>
    4.29 -            <property name="Position">0</property>
    4.30 -            <property name="AutoSize">False</property>
    4.31 -          </packing>
    4.32 -        </child>
    4.33 -      </widget>
    4.34 -    </child>
    4.35 -    <child internal-child="ActionArea">
    4.36 -      <widget class="Gtk.HButtonBox" id="dialog1_ActionArea">
    4.37 -        <property name="MemberName" />
    4.38 -        <property name="Spacing">10</property>
    4.39 -        <property name="BorderWidth">5</property>
    4.40 -        <property name="Size">2</property>
    4.41 -        <property name="LayoutStyle">End</property>
    4.42 -        <child>
    4.43 -          <widget class="Gtk.Button" id="buttonCancel">
    4.44 -            <property name="MemberName" />
    4.45 -            <property name="CanDefault">True</property>
    4.46 -            <property name="CanFocus">True</property>
    4.47 -            <property name="UseStock">True</property>
    4.48 -            <property name="Type">StockItem</property>
    4.49 -            <property name="StockId">gtk-cancel</property>
    4.50 -            <property name="ResponseId">-6</property>
    4.51 -            <signal name="Clicked" handler="OnButtonCancelClicked" />
    4.52 -            <property name="label">gtk-cancel</property>
    4.53 -          </widget>
    4.54 -          <packing>
    4.55 -            <property name="Expand">False</property>
    4.56 -            <property name="Fill">False</property>
    4.57 -          </packing>
    4.58 -        </child>
    4.59 -        <child>
    4.60 -          <widget class="Gtk.Button" id="buttonOk">
    4.61 -            <property name="MemberName" />
    4.62 -            <property name="CanDefault">True</property>
    4.63 -            <property name="CanFocus">True</property>
    4.64 -            <property name="UseStock">True</property>
    4.65 -            <property name="Type">StockItem</property>
    4.66 -            <property name="StockId">gtk-ok</property>
    4.67 -            <property name="ResponseId">-5</property>
    4.68 -            <signal name="Clicked" handler="OnButtonOkClicked" />
    4.69 -            <property name="label">gtk-ok</property>
    4.70 -          </widget>
    4.71 -          <packing>
    4.72 -            <property name="Position">1</property>
    4.73 -            <property name="Expand">False</property>
    4.74 -            <property name="Fill">False</property>
    4.75 -          </packing>
    4.76 -        </child>
    4.77 -      </widget>
    4.78 -    </child>
    4.79 -  </widget>
    4.80    <widget class="Gtk.Bin" id="IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget" design-size="300 55">
    4.81      <property name="MemberName" />
    4.82      <property name="Visible">False</property>