Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate FrmExportXml.cs @ 138:33962c2ef550
Re #326: Make army names and sizes modifiable after creation
* Add army editing form
* Hook up to events to update main window
* Add edit army option to Edit menu
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 11 Oct 2011 21:05:10 +0100 |
parents | 0d8004d6a4e5 |
children | 9808adf2d566 |
rev | line source |
---|---|
122 | 1 // This file (FrmExportXml.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2011 IBBoard |
2 // | |
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; | |
5 using System.IO; | |
6 using IBBoard.GtkSharp; | |
7 using System.Collections.Generic; | |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
8 using Gtk; |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
9 using IBBoard.WarFoundry.API.Objects; |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
10 using System.Xml.Xsl; |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
11 using IBBoard.Lang; |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
12 using IBBoard.WarFoundry.API.Exporters; |
122 | 13 |
14 namespace IBBoard.WarFoundry.GUI.GTK | |
15 { | |
128 | 16 public partial class FrmExportXml : FileChooserDialog |
122 | 17 { |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
18 private Army army; |
126
d4e6bfeb1c61
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
19 private TransformXmlWidget transformWidget; |
128 | 20 private Button buttonOk; |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
21 |
128 | 22 public FrmExportXml(Army army) : base("", null, FileChooserAction.Save) |
122 | 23 { |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
24 this.army = army; |
128 | 25 AddButton(Gtk.Stock.Cancel, ResponseType.Cancel); |
26 buttonOk = (Button)AddButton(Gtk.Stock.Save, ResponseType.Ok); | |
131 | 27 buttonOk.Clicked+= OnButtonOkClicked; |
126
d4e6bfeb1c61
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
28 transformWidget = new TransformXmlWidget(); |
d4e6bfeb1c61
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
29 transformWidget.TransformChanged += HandleTransformWidgetTransformChanged; |
128 | 30 ExtraWidget = transformWidget; |
31 SetFilename(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "export.xml")); | |
32 SelectionChanged += OnSaveAsPathSelectionChanged; | |
122 | 33 } |
34 | |
126
d4e6bfeb1c61
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
125
diff
changeset
|
35 private void HandleTransformWidgetTransformChanged (object sender, EventArgs e) |
122 | 36 { |
124
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
37 SetOkayButtonSensitive(); |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
38 } |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
39 |
131 | 40 private bool IsValid |
41 { | |
42 get | |
43 { | |
44 return CheckFileCanExist() && transformWidget.IsValid; | |
45 } | |
46 } | |
47 | |
48 private bool CheckFileCanExist() | |
128 | 49 { |
131 | 50 bool canExist = false; |
51 | |
52 if (!String.IsNullOrEmpty(Filename)) | |
53 { | |
54 FileInfo file = new FileInfo(Filename); | |
55 canExist = file.Directory.Exists; | |
56 } | |
57 | |
58 return canExist; | |
128 | 59 } |
60 | |
124
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
61 private void SetOkayButtonSensitive() |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
62 { |
128 | 63 //TODO: It would be nice to disable save when appropriate options aren't set, |
64 //but we don't seem to get change notifications early enough | |
65 //buttonOk.Sensitive = IsValid(); | |
124
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
66 } |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
67 |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
68 protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e) |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
69 { |
a647afc19fe9
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
122
diff
changeset
|
70 SetOkayButtonSensitive(); |
122 | 71 } |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
72 |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
73 protected void OnButtonOkClicked (object sender, System.EventArgs e) |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
74 { |
131 | 75 if (IsValid) |
128 | 76 { |
77 DoExport(); | |
78 } | |
79 } | |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
80 |
128 | 81 void DoExport() |
82 { | |
83 string errorMessage = ""; | |
84 // Catch potential errors with the file export or XSL compiliation | |
85 try | |
86 { | |
87 string fileName = Filename; | |
88 | |
89 if (transformWidget.TransformEnabled) | |
90 { | |
91 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath()); | |
92 } | |
93 else | |
94 { | |
95 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName); | |
96 } | |
97 } | |
98 catch (XsltCompileException ex) | |
99 { | |
100 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + ":\n" + ex.Message; | |
101 } | |
102 catch (XsltException ex) | |
103 { | |
104 | |
105 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + ":\n" + ex.Message; | |
106 } | |
107 catch (FileNotFoundException ex) | |
108 { | |
109 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + ":\n" + ex.Message; | |
110 } | |
111 catch (IOException ex) | |
112 { | |
113 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + ":\n" + ex.Message; | |
114 } | |
115 catch (Exception ex) | |
116 { | |
117 errorMessage = Translation.GetTranslation("mbErrorFailed", "") + ":\n" + ex.Message; | |
118 } | |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
119 |
128 | 120 if (errorMessage != "") |
121 { | |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
122 MessageDialog dialog = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, errorMessage); |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
123 dialog.Run(); |
128 | 124 } |
125 | |
125
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
126 Respond(ResponseType.Ok); |
42d2aa87dfa7
Re #361: Add XML export UI to GTK#
IBBoard <dev@ibboard.co.uk>
parents:
124
diff
changeset
|
127 } |
122 | 128 } |
129 } | |
130 |