Mercurial > repos > WarFoundryForge
view FrmMain.cs @ 3:2f52da2e7605
Directory and project updates. VS2008 does not like app.config so I had to remove references of that from the solution from other projects.
author | Tsudico |
---|---|
date | Wed, 08 Dec 2010 18:44:10 -0600 |
parents | 91b5550eff31 |
children | 866d0093bb11 |
line wrap: on
line source
// This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.Forge.WinForms project and is copyright 2007, 2008, 2009 IBBoard. // // 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. using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Threading; using log4net; using log4net.Config; using IBBoard; using IBBoard.CustomMath; using IBBoard.Commands; using IBBoard.IO; using IBBoard.Lang; using IBBoard.Windows.Forms; using IBBoard.Windows.Forms.I18N; using IBBoard.Xml; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.API.Exporters; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Savers; using IBBoard.WarFoundry.API.Factories; using IBBoard.WarFoundry.API.Factories.Xml; namespace IBBoard.WarFoundry.Forge.WinForms { /// <summary> /// Summary description for Form1. /// </summary> public class FrmMain : System.Windows.Forms.Form { private static readonly string AppTitle = "WarFoundry Forge"; internal static readonly string VERSION = "0.0.2"; const string DefaultDataDir = "data"; private Preferences preferences; private readonly ILog log = LogManager.GetLogger(typeof(FrmMain)); private CommandStack commandStack; private string loadedFilePath; // Form contents private System.ComponentModel.IContainer components; private System.Windows.Forms.MainMenu mainMenu; private MenuStrip menuStrip; // File Menu and Contents private IBBToolStripMenuItem menuFile; private IBBToolStripMenuItem menuNew; private IBBToolStripMenuItem miNewSystem; private ToolStripSeparator toolStripSeparator2; private IBBToolStripMenuItem miExit; // About Menu and Contents private IBBToolStripMenuItem menuHelp; private IBBToolStripMenuItem miAbout; /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { try { XmlConfigurator.Configure(new System.IO.FileInfo("WarFoundryForge.log4net")); LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry Forge WinForms"); Application.EnableVisualStyles(); Application.Run(new FrmMain(args)); LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry Forge WinForms"); } catch (Exception ex) { LogManager.GetLogger(typeof(FrmMain)).Fatal(ex); 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); } } public FrmMain(string[] args) { this.Closing += new CancelEventHandler(FrmMain_Closing); InitializeComponent(); Preferences = new Preferences("WarFoundryForge"); try { Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString()); } catch (TranslationLoadException ex) { log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex); MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } Translation.TranslationChanged += new MethodInvoker(TranslationChanged); TranslateControls(); // hack to load default files WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); } private void TranslateControls() { ControlTranslator.TranslateControls(Controls); ControlTranslator.TranslateComponents(components.Components); } void TranslationChanged() { TranslateControls(); } public static string DataPath { get { return Constants.ExecutablePath + Constants.DirectoryChar + "data"; } } public Preferences Preferences { get { return preferences; } set { preferences = value; } } public CommandStack CommandStack { get { if (commandStack == null) { commandStack = new CommandStack(); } return commandStack; } } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain)); this.mainMenu = new System.Windows.Forms.MainMenu(this.components); this.menuStrip = new System.Windows.Forms.MenuStrip(); // File Menu and Contents this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.menuNew = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.miNewSystem = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); // About Menu and Contents this.menuHelp = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.miAbout = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); // // menuStrip // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuFile, this.menuHelp}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(790, 24); this.menuStrip.TabIndex = 6; this.menuStrip.Text = "menuStrip1"; // // menuFile // this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuNew, this.toolStripSeparator2, this.miExit}); this.menuFile.Name = "menuFile"; this.menuFile.Size = new System.Drawing.Size(33, 20); this.menuFile.Text = "&file"; // // menuNew // this.menuNew.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.miNewSystem}); this.menuNew.Name = "menuNew"; this.menuNew.Size = new System.Drawing.Size(164, 22); this.menuNew.Text = "&new"; // // miNewSystem // this.miNewSystem.Name = "miNewSystem"; this.miNewSystem.Size = new System.Drawing.Size(164, 22); this.miNewSystem.Text = "s&ystem"; this.miNewSystem.Click += new System.EventHandler(this.miNewSystem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Size = new System.Drawing.Size(161, 6); // // miExit // this.miExit.Name = "miExit"; this.miExit.Size = new System.Drawing.Size(164, 22); this.miExit.Text = "e&xit"; this.miExit.Click += new System.EventHandler(this.miExit_Click); // // menuHelp // this.menuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.miAbout}); this.menuHelp.Name = "menuHelp"; this.menuHelp.Size = new System.Drawing.Size(39, 20); this.menuHelp.Text = "&help"; // // miAbout // this.miAbout.Name = "miAbout"; this.miAbout.Size = new System.Drawing.Size(109, 22); this.miAbout.Text = "&about"; this.miAbout.Click += new System.EventHandler(this.miAbout_Click); // // FrmMain // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(790, 608); this.Controls.Add(this.menuStrip); this.IsMdiContainer = true; this.MainMenuStrip = this.menuStrip; this.Menu = this.mainMenu; this.Name = "FrmMain"; this.Text = AppTitle; this.menuStrip.ResumeLayout(false); this.menuStrip.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private void FileLoadingFinished(List<FileLoadFailure> failures) { foreach (FileLoadFailure failure in failures) { log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message); } } private void miNewSystem_Click(object sender, System.EventArgs e) { FrmSystem system = new FrmSystem(); system.ShowDialog(this); } private void miExit_Click(object sender, System.EventArgs e) { Application.Exit(); } private void miAbout_Click(object sender, EventArgs e) { FrmAbout about = new FrmAbout(); about.ShowDialog(this); } private void FrmMain_Closing(object sender, CancelEventArgs e) { } } }