0
|
1 // This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.Forge.WinForms project and is copyright 2007, 2008, 2009 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
|
|
5 using System;
|
|
6 using System.Collections.Generic;
|
|
7 using System.Drawing;
|
|
8 using System.Drawing.Drawing2D;
|
|
9 using System.ComponentModel;
|
|
10 using System.Windows.Forms;
|
|
11 using System.Data;
|
|
12 using System.IO;
|
|
13 using System.Threading;
|
|
14 using log4net;
|
|
15 using log4net.Config;
|
|
16 using IBBoard;
|
|
17 using IBBoard.CustomMath;
|
|
18 using IBBoard.Commands;
|
|
19 using IBBoard.IO;
|
|
20 using IBBoard.Lang;
|
|
21 using IBBoard.Windows.Forms;
|
|
22 using IBBoard.Windows.Forms.I18N;
|
|
23 using IBBoard.Xml;
|
|
24 using IBBoard.WarFoundry.API;
|
|
25 using IBBoard.WarFoundry.API.Commands;
|
|
26 using IBBoard.WarFoundry.API.Exporters;
|
|
27 using IBBoard.WarFoundry.API.Objects;
|
|
28 using IBBoard.WarFoundry.API.Savers;
|
|
29 using IBBoard.WarFoundry.API.Factories;
|
|
30 using IBBoard.WarFoundry.API.Factories.Xml;
|
|
31
|
|
32 namespace IBBoard.WarFoundry.Forge.WinForms
|
|
33 {
|
|
34 /// <summary>
|
|
35 /// Summary description for Form1.
|
|
36 /// </summary>
|
|
37 public class FrmMain : System.Windows.Forms.Form
|
|
38 {
|
|
39 private static readonly string AppTitle = "WarFoundry Forge";
|
|
40 internal static readonly string VERSION = "0.0.2";
|
|
41 const string DefaultDataDir = "data";
|
|
42
|
|
43 private Preferences preferences;
|
|
44 private readonly ILog log = LogManager.GetLogger(typeof(FrmMain));
|
|
45
|
|
46 private CommandStack commandStack;
|
|
47
|
|
48 private string loadedFilePath;
|
|
49
|
|
50 // Form contents
|
|
51 private System.ComponentModel.IContainer components;
|
|
52 private System.Windows.Forms.MainMenu mainMenu;
|
|
53 private MenuStrip menuStrip;
|
|
54 // File Menu and Contents
|
|
55 private IBBToolStripMenuItem menuFile;
|
|
56 private IBBToolStripMenuItem menuNew;
|
|
57 private IBBToolStripMenuItem miNewSystem;
|
|
58 private ToolStripSeparator toolStripSeparator2;
|
|
59 private IBBToolStripMenuItem miExit;
|
|
60 // About Menu and Contents
|
|
61 private IBBToolStripMenuItem menuHelp;
|
|
62 private IBBToolStripMenuItem miAbout;
|
|
63
|
|
64 /// <summary>
|
|
65 /// The main entry point for the application.
|
|
66 /// </summary>
|
|
67 [STAThread]
|
|
68 static void Main(string[] args)
|
|
69 {
|
|
70 try
|
|
71 {
|
|
72 XmlConfigurator.Configure(new System.IO.FileInfo("WarFoundryForge.log4net"));
|
|
73 LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry Forge WinForms");
|
|
74 Application.EnableVisualStyles();
|
|
75 Application.Run(new FrmMain(args));
|
|
76 LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry Forge WinForms");
|
|
77 }
|
|
78 catch (Exception ex)
|
|
79 {
|
|
80 LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
|
|
81 MessageBox.Show(null, "A major, unexpected and fatal error ocurred while starting the application: \r\n\r\n" + ex.Message + "\r\n\r\n" + ex.StackTrace, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
82 }
|
|
83 }
|
|
84
|
|
85 public FrmMain(string[] args)
|
|
86 {
|
|
87 this.Closing += new CancelEventHandler(FrmMain_Closing);
|
|
88
|
|
89 InitializeComponent();
|
|
90
|
|
91 Preferences = new Preferences("WarFoundryForge");
|
|
92 try
|
|
93 {
|
|
94 Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
|
|
95 }
|
|
96 catch (TranslationLoadException ex)
|
|
97 {
|
|
98 log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex);
|
|
99 MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
100 }
|
|
101
|
|
102 Translation.TranslationChanged += new MethodInvoker(TranslationChanged);
|
|
103
|
|
104 TranslateControls();
|
|
105
|
|
106 // hack to load default files
|
|
107 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
|
|
108 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
|
|
109 WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
|
|
110 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
|
|
111 }
|
|
112
|
|
113 private void TranslateControls()
|
|
114 {
|
|
115 ControlTranslator.TranslateControls(Controls);
|
|
116 ControlTranslator.TranslateComponents(components.Components);
|
|
117 }
|
|
118
|
|
119 void TranslationChanged()
|
|
120 {
|
|
121 TranslateControls();
|
|
122 }
|
|
123
|
|
124 public static string DataPath
|
|
125 {
|
|
126 get { return Constants.ExecutablePath + Constants.DirectoryChar + "data"; }
|
|
127 }
|
|
128
|
|
129 public Preferences Preferences
|
|
130 {
|
|
131 get { return preferences; }
|
|
132 set { preferences = value; }
|
|
133 }
|
|
134
|
|
135 public CommandStack CommandStack
|
|
136 {
|
|
137 get
|
|
138 {
|
|
139 if (commandStack == null)
|
|
140 {
|
|
141 commandStack = new CommandStack();
|
|
142 }
|
|
143
|
|
144 return commandStack;
|
|
145 }
|
|
146 }
|
|
147
|
|
148 /// <summary>
|
|
149 /// Clean up any resources being used.
|
|
150 /// </summary>
|
|
151 protected override void Dispose(bool disposing)
|
|
152 {
|
|
153 if (disposing)
|
|
154 {
|
|
155 if (components != null)
|
|
156 {
|
|
157 components.Dispose();
|
|
158 }
|
|
159 }
|
|
160 base.Dispose(disposing);
|
|
161 }
|
|
162
|
|
163 #region Windows Form Designer generated code
|
|
164 /// <summary>
|
|
165 /// Required method for Designer support - do not modify
|
|
166 /// the contents of this method with the code editor.
|
|
167 /// </summary>
|
|
168 private void InitializeComponent()
|
|
169 {
|
|
170 this.components = new System.ComponentModel.Container();
|
|
171 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
|
|
172 this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
|
|
173 this.menuStrip = new System.Windows.Forms.MenuStrip();
|
|
174 // File Menu and Contents
|
|
175 this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
|
|
176 this.menuNew = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
|
|
177 this.miNewSystem = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
|
|
178 this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
|
|
179 this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
|
|
180 // About Menu and Contents
|
|
181 this.menuHelp = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
|
|
182 this.miAbout = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
|
|
183
|
|
184 //
|
|
185 // menuStrip
|
|
186 //
|
|
187 this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
|
188 this.menuFile,
|
|
189 this.menuHelp});
|
|
190 this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
|
191 this.menuStrip.Name = "menuStrip";
|
|
192 this.menuStrip.Size = new System.Drawing.Size(790, 24);
|
|
193 this.menuStrip.TabIndex = 6;
|
|
194 this.menuStrip.Text = "menuStrip1";
|
|
195 //
|
|
196 // menuFile
|
|
197 //
|
|
198 this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
|
199 this.menuNew,
|
|
200 this.toolStripSeparator2,
|
|
201 this.miExit});
|
|
202 this.menuFile.Name = "menuFile";
|
|
203 this.menuFile.Size = new System.Drawing.Size(33, 20);
|
|
204 this.menuFile.Text = "&file";
|
|
205 //
|
|
206 // menuNew
|
|
207 //
|
|
208 this.menuNew.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
|
209 this.miNewSystem});
|
|
210 this.menuNew.Name = "menuNew";
|
|
211 this.menuNew.Size = new System.Drawing.Size(164, 22);
|
|
212 this.menuNew.Text = "&new";
|
|
213 //
|
|
214 // miNewSystem
|
|
215 //
|
|
216 this.miNewSystem.Name = "miNewSystem";
|
|
217 this.miNewSystem.Size = new System.Drawing.Size(164, 22);
|
|
218 this.miNewSystem.Text = "s&ystem";
|
|
219 this.miNewSystem.Click += new System.EventHandler(this.miNewSystem_Click);
|
|
220 //
|
|
221 // toolStripSeparator2
|
|
222 //
|
|
223 this.toolStripSeparator2.Name = "toolStripSeparator2";
|
|
224 this.toolStripSeparator2.Size = new System.Drawing.Size(161, 6);
|
|
225 //
|
|
226 // miExit
|
|
227 //
|
|
228 this.miExit.Name = "miExit";
|
|
229 this.miExit.Size = new System.Drawing.Size(164, 22);
|
|
230 this.miExit.Text = "e&xit";
|
|
231 this.miExit.Click += new System.EventHandler(this.miExit_Click);
|
|
232 //
|
|
233 // menuHelp
|
|
234 //
|
|
235 this.menuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
|
236 this.miAbout});
|
|
237 this.menuHelp.Name = "menuHelp";
|
|
238 this.menuHelp.Size = new System.Drawing.Size(39, 20);
|
|
239 this.menuHelp.Text = "&help";
|
|
240 //
|
|
241 // miAbout
|
|
242 //
|
|
243 this.miAbout.Name = "miAbout";
|
|
244 this.miAbout.Size = new System.Drawing.Size(109, 22);
|
|
245 this.miAbout.Text = "&about";
|
|
246 this.miAbout.Click += new System.EventHandler(this.miAbout_Click);
|
|
247 //
|
|
248 // FrmMain
|
|
249 //
|
|
250 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
|
251 this.ClientSize = new System.Drawing.Size(790, 608);
|
|
252 this.Controls.Add(this.menuStrip);
|
|
253 this.IsMdiContainer = true;
|
|
254 this.MainMenuStrip = this.menuStrip;
|
|
255 this.Menu = this.mainMenu;
|
|
256 this.Name = "FrmMain";
|
|
257 this.Text = AppTitle;
|
|
258 this.menuStrip.ResumeLayout(false);
|
|
259 this.menuStrip.PerformLayout();
|
|
260 this.ResumeLayout(false);
|
|
261 this.PerformLayout();
|
|
262 }
|
|
263 #endregion
|
|
264
|
|
265 private void FileLoadingFinished(List<FileLoadFailure> failures)
|
|
266 {
|
|
267 foreach (FileLoadFailure failure in failures)
|
|
268 {
|
|
269 log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
|
|
270 }
|
|
271 }
|
|
272
|
|
273 private void miNewSystem_Click(object sender, System.EventArgs e)
|
|
274 {
|
|
275 FrmSystem system = new FrmSystem();
|
|
276 system.ShowDialog(this);
|
|
277 }
|
|
278
|
|
279 private void miExit_Click(object sender, System.EventArgs e)
|
|
280 {
|
|
281 Application.Exit();
|
|
282 }
|
|
283
|
|
284 private void miAbout_Click(object sender, EventArgs e)
|
|
285 {
|
|
286 FrmAbout about = new FrmAbout();
|
|
287 about.ShowDialog(this);
|
|
288 }
|
|
289
|
|
290 private void FrmMain_Closing(object sender, CancelEventArgs e)
|
|
291 {
|
|
292 }
|
|
293 }
|
|
294 }
|