Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison FrmExportXml.cs @ 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 |
comparison
equal
deleted
inserted
replaced
124:a647afc19fe9 | 125:42d2aa87dfa7 |
---|---|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
4 using System; | 4 using System; |
5 using System.IO; | 5 using System.IO; |
6 using IBBoard.GtkSharp; | 6 using IBBoard.GtkSharp; |
7 using System.Collections.Generic; | 7 using System.Collections.Generic; |
8 using Gtk; | |
9 using IBBoard.WarFoundry.API.Objects; | |
10 using System.Xml.Xsl; | |
11 using IBBoard.Lang; | |
12 using IBBoard.WarFoundry.API.Exporters; | |
8 | 13 |
9 namespace IBBoard.WarFoundry.GUI.GTK | 14 namespace IBBoard.WarFoundry.GUI.GTK |
10 { | 15 { |
11 public partial class FrmExportXml : Gtk.Dialog | 16 public partial class FrmExportXml : Gtk.Dialog |
12 { | 17 { |
13 public FrmExportXml() | 18 private Army army; |
19 | |
20 public FrmExportXml(Army army) | |
14 { | 21 { |
22 this.army = army; | |
15 this.Build(); | 23 this.Build(); |
16 FillXsltList(); | 24 FillXsltList(); |
17 saveAsPath.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); | 25 saveAsPath.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); |
18 } | 26 } |
19 | 27 |
32 SetOkayButtonSensitive(); | 40 SetOkayButtonSensitive(); |
33 } | 41 } |
34 | 42 |
35 private void SetOkayButtonSensitive() | 43 private void SetOkayButtonSensitive() |
36 { | 44 { |
37 buttonOk.Sensitive = saveAsPath.Filename != null && (!doTransformWidget.Active || ComboBoxUtils.GetSelectedItem<FileInfo>(transformList) != null); | 45 buttonOk.Sensitive = saveAsName.Text != "" && saveAsPath.Filename != null && saveAsPath.Filename != "" && (!doTransformWidget.Active || ComboBoxUtils.GetSelectedItem<FileInfo>(transformList) != null); |
38 } | 46 } |
39 | 47 |
40 protected void OnTransformListChanged(object sender, System.EventArgs e) | 48 protected void OnTransformListChanged(object sender, System.EventArgs e) |
41 { | 49 { |
42 SetOkayButtonSensitive(); | 50 SetOkayButtonSensitive(); |
44 | 52 |
45 protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e) | 53 protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e) |
46 { | 54 { |
47 SetOkayButtonSensitive(); | 55 SetOkayButtonSensitive(); |
48 } | 56 } |
57 | |
58 protected void OnButtonOkClicked (object sender, System.EventArgs e) | |
59 { | |
60 string errorMessage = ""; | |
61 // Catch potential errors with the file export or XSL compiliation | |
62 try | |
63 { | |
64 string fileName = System.IO.Path.Combine(saveAsPath.Filename, saveAsName.Text); | |
65 | |
66 if (doTransformWidget.Active) | |
67 { | |
68 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, ComboBoxUtils.GetSelectedItem<FileInfo>(transformList).FullName); | |
69 } | |
70 else | |
71 { | |
72 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName); | |
73 } | |
74 } | |
75 catch (XsltCompileException ex) | |
76 { | |
77 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + | |
78 ":\n" + ex.Message; | |
79 } | |
80 catch (XsltException ex) | |
81 { | |
82 | |
83 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + | |
84 ":\n" + ex.Message; | |
85 } | |
86 catch (FileNotFoundException ex) | |
87 { | |
88 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + | |
89 ":\n" + ex.Message; | |
90 } | |
91 catch (IOException ex) | |
92 { | |
93 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + | |
94 ":\n" + ex.Message; | |
95 } | |
96 catch (Exception ex) | |
97 { | |
98 errorMessage = Translation.GetTranslation("mbErrorFailed", "") + | |
99 ":\n" + ex.Message; | |
100 } | |
101 | |
102 if (errorMessage != "") | |
103 { | |
104 MessageDialog dialog = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, errorMessage); | |
105 dialog.Run(); | |
106 } | |
107 | |
108 Respond(ResponseType.Ok); | |
109 } | |
110 | |
111 protected void OnButtonCancelClicked (object sender, System.EventArgs e) | |
112 { | |
113 Respond(ResponseType.Cancel); | |
114 } | |
115 | |
116 protected void OnSaveAsNameChanged (object sender, System.EventArgs e) | |
117 { | |
118 SetOkayButtonSensitive(); | |
119 } | |
49 } | 120 } |
50 } | 121 } |
51 | 122 |