Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison FrmExportXml.cs @ 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 | d4e6bfeb1c61 |
children | 0d8004d6a4e5 |
comparison
equal
deleted
inserted
replaced
127:786a3afb9240 | 128:d5a631a8d288 |
---|---|
11 using IBBoard.Lang; | 11 using IBBoard.Lang; |
12 using IBBoard.WarFoundry.API.Exporters; | 12 using IBBoard.WarFoundry.API.Exporters; |
13 | 13 |
14 namespace IBBoard.WarFoundry.GUI.GTK | 14 namespace IBBoard.WarFoundry.GUI.GTK |
15 { | 15 { |
16 public partial class FrmExportXml : Gtk.Dialog | 16 public partial class FrmExportXml : FileChooserDialog |
17 { | 17 { |
18 private Army army; | 18 private Army army; |
19 private TransformXmlWidget transformWidget; | 19 private TransformXmlWidget transformWidget; |
20 private Button buttonOk; | |
20 | 21 |
21 public FrmExportXml(Army army) | 22 public FrmExportXml(Army army) : base("", null, FileChooserAction.Save) |
22 { | 23 { |
23 this.army = army; | 24 this.army = army; |
24 this.Build(); | 25 AddButton(Gtk.Stock.Cancel, ResponseType.Cancel); |
26 buttonOk = (Button)AddButton(Gtk.Stock.Save, ResponseType.Ok); | |
27 buttonOk.Clicked+=OnButtonOkClicked; | |
25 transformWidget = new TransformXmlWidget(); | 28 transformWidget = new TransformXmlWidget(); |
26 transformWidget.TransformChanged += HandleTransformWidgetTransformChanged; | 29 transformWidget.TransformChanged += HandleTransformWidgetTransformChanged; |
27 saveAsPath.ExtraWidget = transformWidget; | 30 ExtraWidget = transformWidget; |
28 saveAsPath.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); | 31 SetFilename(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "export.xml")); |
32 SelectionChanged += OnSaveAsPathSelectionChanged; | |
29 } | 33 } |
30 | 34 |
31 private void HandleTransformWidgetTransformChanged (object sender, EventArgs e) | 35 private void HandleTransformWidgetTransformChanged (object sender, EventArgs e) |
32 { | 36 { |
33 SetOkayButtonSensitive(); | 37 SetOkayButtonSensitive(); |
34 } | 38 } |
35 | 39 |
40 private bool IsValid () | |
41 { | |
42 return Filename != null && Filename != "" && transformWidget.IsValid; | |
43 } | |
44 | |
36 private void SetOkayButtonSensitive() | 45 private void SetOkayButtonSensitive() |
37 { | 46 { |
38 buttonOk.Sensitive = saveAsPath.Filename != null && saveAsPath.Filename != "" && transformWidget.IsValid; | 47 //TODO: It would be nice to disable save when appropriate options aren't set, |
48 //but we don't seem to get change notifications early enough | |
49 //buttonOk.Sensitive = IsValid(); | |
39 } | 50 } |
40 | 51 |
41 protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e) | 52 protected void OnSaveAsPathSelectionChanged(object sender, System.EventArgs e) |
42 { | 53 { |
43 SetOkayButtonSensitive(); | 54 SetOkayButtonSensitive(); |
44 } | 55 } |
45 | 56 |
46 protected void OnButtonOkClicked (object sender, System.EventArgs e) | 57 protected void OnButtonOkClicked (object sender, System.EventArgs e) |
47 { | 58 { |
59 if (IsValid()) | |
60 { | |
61 DoExport(); | |
62 } | |
63 } | |
64 | |
65 void DoExport() | |
66 { | |
48 string errorMessage = ""; | 67 string errorMessage = ""; |
49 // Catch potential errors with the file export or XSL compiliation | 68 // Catch potential errors with the file export or XSL compiliation |
50 try | 69 try |
51 { | 70 { |
52 string fileName = saveAsPath.Filename; | 71 string fileName = Filename; |
72 | |
73 if (transformWidget.TransformEnabled) | |
74 { | |
75 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath()); | |
76 } | |
77 else | |
78 { | |
79 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName); | |
80 } | |
81 } | |
82 catch (XsltCompileException ex) | |
83 { | |
84 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + ":\n" + ex.Message; | |
85 } | |
86 catch (XsltException ex) | |
87 { | |
88 | |
89 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + ":\n" + ex.Message; | |
90 } | |
91 catch (FileNotFoundException ex) | |
92 { | |
93 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + ":\n" + ex.Message; | |
94 } | |
95 catch (IOException ex) | |
96 { | |
97 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + ":\n" + ex.Message; | |
98 } | |
99 catch (Exception ex) | |
100 { | |
101 errorMessage = Translation.GetTranslation("mbErrorFailed", "") + ":\n" + ex.Message; | |
102 } | |
53 | 103 |
54 if (transformWidget.TransformEnabled) | 104 if (errorMessage != "") |
55 { | 105 { |
56 WarFoundryXmlWithXslExporter.GetDefault().ExportArmyWithTransform(army, fileName, transformWidget.GetXsltPath()); | |
57 } | |
58 else | |
59 { | |
60 WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(army, fileName); | |
61 } | |
62 } | |
63 catch (XsltCompileException ex) | |
64 { | |
65 errorMessage = Translation.GetTranslation("mbErrorCompileFailed", "") + | |
66 ":\n" + ex.Message; | |
67 } | |
68 catch (XsltException ex) | |
69 { | |
70 | |
71 errorMessage = Translation.GetTranslation("mbErrorXSLTFailed", "") + | |
72 ":\n" + ex.Message; | |
73 } | |
74 catch (FileNotFoundException ex) | |
75 { | |
76 errorMessage = Translation.GetTranslation("mbErrorFileNotFoundFailed", "") + | |
77 ":\n" + ex.Message; | |
78 } | |
79 catch (IOException ex) | |
80 { | |
81 errorMessage = Translation.GetTranslation("mbErrorIOFailed", "") + | |
82 ":\n" + ex.Message; | |
83 } | |
84 catch (Exception ex) | |
85 { | |
86 errorMessage = Translation.GetTranslation("mbErrorFailed", "") + | |
87 ":\n" + ex.Message; | |
88 } | |
89 | |
90 if (errorMessage != "") | |
91 { | |
92 MessageDialog dialog = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, errorMessage); | 106 MessageDialog dialog = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, errorMessage); |
93 dialog.Run(); | 107 dialog.Run(); |
94 } | 108 } |
95 | 109 |
96 Respond(ResponseType.Ok); | 110 Respond(ResponseType.Ok); |
97 } | |
98 | |
99 protected void OnButtonCancelClicked (object sender, System.EventArgs e) | |
100 { | |
101 Respond(ResponseType.Cancel); | |
102 } | |
103 | |
104 protected void OnSizeAllocated (object o, Gtk.SizeAllocatedArgs args) | |
105 { | |
106 Console.WriteLine(args.Allocation.Height + "," + args.Allocation.Width); | |
107 //this. | |
108 } | 111 } |
109 } | 112 } |
110 } | 113 } |
111 | 114 |