changeset 134:e381ec627d14

Re #88: Complete initial WinForms UI * Do toolstrip positioning properly - use the right-hand side to work from instead of the width
author IBBoard <dev@ibboard.co.uk>
date Fri, 02 Apr 2010 19:39:27 +0000
parents acb4456598ce
children c095c57a56f9
files FrmMain.cs
diffstat 1 files changed, 1352 insertions(+), 1352 deletions(-) [+]
line diff
     1.1 --- a/FrmMain.cs	Wed Mar 31 20:03:45 2010 +0000
     1.2 +++ b/FrmMain.cs	Fri Apr 02 19:39:27 2010 +0000
     1.3 @@ -1,1352 +1,1352 @@
     1.4 -// This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard.
     1.5 -//
     1.6 -// 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.
     1.7 -
     1.8 -using System;
     1.9 -using System.Collections.Generic;
    1.10 -using System.Drawing;
    1.11 -using System.Drawing.Drawing2D;
    1.12 -using System.ComponentModel;
    1.13 -using System.Windows.Forms;
    1.14 -using System.Data;
    1.15 -using System.IO;
    1.16 -using System.Threading;
    1.17 -using log4net;
    1.18 -using IBBoard;
    1.19 -using IBBoard.CustomMath;
    1.20 -using IBBoard.Commands;
    1.21 -using IBBoard.IO;
    1.22 -using IBBoard.Lang;
    1.23 -using IBBoard.Windows.Forms;
    1.24 -using IBBoard.Windows.Forms.I18N;
    1.25 -using IBBoard.Xml;
    1.26 -using IBBoard.WarFoundry.API;
    1.27 -using IBBoard.WarFoundry.API.Commands;
    1.28 -using IBBoard.WarFoundry.API.Exporters;
    1.29 -using IBBoard.WarFoundry.API.Objects;
    1.30 -using IBBoard.WarFoundry.API.Savers;
    1.31 -using IBBoard.WarFoundry.API.Factories;
    1.32 -using IBBoard.WarFoundry.API.Factories.Xml;
    1.33 -
    1.34 -namespace IBBoard.WarFoundry.GUI.WinForms
    1.35 -{
    1.36 -	/// <summary>
    1.37 -	/// Summary description for Form1.
    1.38 -	/// </summary>
    1.39 -	public class FrmMain : System.Windows.Forms.Form
    1.40 -	{
    1.41 -		private static readonly string AppTitle = "WarFoundry";
    1.42 -		internal static readonly string VERSION = "0.1b7";
    1.43 -        const string DefaultDataDir = "data";
    1.44 -
    1.45 -		private Preferences preferences;
    1.46 -		private readonly ILog log = LogManager.GetLogger(typeof(FrmMain));
    1.47 -
    1.48 -		private CommandStack commandStack;
    1.49 -
    1.50 -		public ObjectAddDelegate UnitAddedMethod;
    1.51 -		public ObjectRemoveDelegate UnitRemovedMethod;
    1.52 -		public DoubleValChangedDelegate PointsValueChangedMethod;
    1.53 -		//public FailedUnitRequirementDelegate FailedUnitRequirementMethod;
    1.54 -
    1.55 -		private FrmArmyTree armyTree;
    1.56 -		private string loadedFilePath;
    1.57 -		private Dictionary<string, FrmUnit> unitWindows;
    1.58 -
    1.59 -		private System.ComponentModel.IContainer components;
    1.60 -		private System.Windows.Forms.OpenFileDialog openArmyDialog;
    1.61 -		private System.Windows.Forms.SaveFileDialog saveArmyDialog;
    1.62 -		private System.Windows.Forms.MainMenu mainMenu;
    1.63 -		private IBBoard.Windows.Forms.ColorableStatusBarPanel sbMainPanel;
    1.64 -		private IBBoard.Windows.Forms.ColorableStatusBarPanel sbErrorPanel;
    1.65 -		private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel;
    1.66 -		private System.Windows.Forms.ContextMenu undoMenu;
    1.67 -		private System.Windows.Forms.ContextMenu redoMenu;
    1.68 -		private IBBoard.Windows.Forms.ColorableStatusBar statusBar;
    1.69 -		private System.Windows.Forms.Timer statusBarTimer;
    1.70 -		private MenuStrip menuStrip;
    1.71 -		private IBBToolStripMenuItem menuFile;
    1.72 -		private IBBToolStripMenuItem miNewArmy;
    1.73 -		private IBBToolStripMenuItem miOpenArmy;
    1.74 -		private IBBToolStripMenuItem miSaveArmy;
    1.75 -		private IBBToolStripMenuItem miSaveArmyAs;
    1.76 -		private IBBToolStripMenuItem miExportArmyAs;
    1.77 -		private IBBToolStripMenuItem miExportArmyAsBasicHTML;
    1.78 -		private IBBToolStripMenuItem miCloseArmy;
    1.79 -		private ToolStripSeparator toolStripSeparator1;
    1.80 -		private IBBToolStripMenuItem miReloadFiles;
    1.81 -		private ToolStripSeparator toolStripSeparator2;
    1.82 -		private IBBToolStripMenuItem miExit;
    1.83 -		private IBBToolStripMenuItem menuEdit;
    1.84 -		private IBBToolStripMenuItem miUndo;
    1.85 -		private IBBToolStripMenuItem miRedo;
    1.86 -		private IBBToolStripMenuItem menuHelp;
    1.87 -		private ToolStrip mainToolStrip;
    1.88 -		private IBBToolStripButton bttnNewArmy;
    1.89 -		private IBBToolStripButton bttnOpenArmy;
    1.90 -		private IBBToolStripButton bttnSaveArmy;
    1.91 -		private ToolStripSeparator toolStripSeparator3;
    1.92 -		private IBBToolStripSplitButton bttnUndo;
    1.93 -		private IBBToolStripSplitButton bttnRedo;
    1.94 -		private ToolStrip catToolStrip;
    1.95 -		private ToolStripPanel toolStripPanel;
    1.96 -		private IBBToolStripMenuItem miAbout;
    1.97 -
    1.98 -		/// <summary>
    1.99 -		/// The main entry point for the application.
   1.100 -		/// </summary>
   1.101 -		[STAThread]
   1.102 -		static void Main(string[] args)
   1.103 -		{
   1.104 -			try
   1.105 -			{
   1.106 -				LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms");
   1.107 -				Application.EnableVisualStyles();
   1.108 -				Application.Run(new FrmMain(args));
   1.109 -				LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms");
   1.110 -			}
   1.111 -			catch (Exception ex)
   1.112 -			{
   1.113 -				LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
   1.114 -				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);
   1.115 -			}
   1.116 -		}
   1.117 -
   1.118 -		public FrmMain(string[] args)
   1.119 -		{
   1.120 -			this.Closing+=new CancelEventHandler(FrmMain_Closing);
   1.121 -			CommandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated);
   1.122 -
   1.123 -			InitializeComponent();
   1.124 -			toolStripPanel.Join(mainToolStrip, 0, 0);
   1.125 -			toolStripPanel.Join(catToolStrip, mainToolStrip.Width+5, 0);
   1.126 -
   1.127 -			Preferences = new Preferences("WarFoundry");
   1.128 -			try
   1.129 -			{
   1.130 -				Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
   1.131 -			}
   1.132 -			catch (TranslationLoadException ex)
   1.133 -			{
   1.134 -				log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex);
   1.135 -				MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.136 -			}
   1.137 -
   1.138 -			ControlTranslator.TranslateControls(Controls);
   1.139 -			ControlTranslator.TranslateComponents(components.Components);
   1.140 -			ControlTranslator.TranslateComponent(openArmyDialog);
   1.141 -			ControlTranslator.TranslateComponent(saveArmyDialog);
   1.142 -			unitWindows = new Dictionary<string, FrmUnit>();
   1.143 -
   1.144 -			WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged);
   1.145 -			WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged);
   1.146 -			UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod);
   1.147 -			UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod);
   1.148 -			PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod);
   1.149 -			//FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(FrmMain_FailedUnitRequirement);
   1.150 -
   1.151 -			sbErrorPanel.Color = Color.Red;
   1.152 -			sbPointsPanel.ToolTipText = Translation.GetTranslation("statusPanelPointsToolTip", "total points value");
   1.153 -
   1.154 -			armyTree = new FrmArmyTree(CommandStack);
   1.155 -			armyTree.MdiParent = this;
   1.156 -			armyTree.StartPosition = FormStartPosition.Manual;
   1.157 -			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
   1.158 -            ControlTranslator.TranslateControl(armyTree);
   1.159 -
   1.160 -            // hack to load default files
   1.161 -            WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
   1.162 -            WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
   1.163 -			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
   1.164 -			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
   1.165 -		}
   1.166 -
   1.167 -		public static string DataPath
   1.168 -		{
   1.169 -			get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; }
   1.170 -		}
   1.171 -
   1.172 -		public static String ArmiesPath
   1.173 -		{
   1.174 -			get { return Environment.GetFolderPath(Environment.SpecialFolder.Personal); }
   1.175 -		}
   1.176 -
   1.177 -		public Preferences Preferences
   1.178 -		{
   1.179 -			get { return preferences; }
   1.180 -			set { preferences = value; }
   1.181 -		}
   1.182 -
   1.183 -		public CommandStack CommandStack
   1.184 -		{
   1.185 -			get 
   1.186 -			{
   1.187 -				if (commandStack == null)
   1.188 -				{					
   1.189 -					commandStack = new CommandStack();
   1.190 -				}
   1.191 -
   1.192 -				return commandStack; 
   1.193 -			}
   1.194 -		}
   1.195 -
   1.196 -		/// <summary>
   1.197 -		/// Clean up any resources being used.
   1.198 -		/// </summary>
   1.199 -		protected override void Dispose( bool disposing )
   1.200 -		{
   1.201 -			if( disposing )
   1.202 -			{
   1.203 -				if (components != null) 
   1.204 -				{
   1.205 -					components.Dispose();
   1.206 -				}
   1.207 -			}
   1.208 -			base.Dispose( disposing );
   1.209 -		}
   1.210 -
   1.211 -		#region Windows Form Designer generated code
   1.212 -		/// <summary>
   1.213 -		/// Required method for Designer support - do not modify
   1.214 -		/// the contents of this method with the code editor.
   1.215 -		/// </summary>
   1.216 -		private void InitializeComponent()
   1.217 -		{
   1.218 -			this.components = new System.ComponentModel.Container();
   1.219 -			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
   1.220 -			this.undoMenu = new System.Windows.Forms.ContextMenu();
   1.221 -			this.redoMenu = new System.Windows.Forms.ContextMenu();
   1.222 -			this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
   1.223 -			this.openArmyDialog = new System.Windows.Forms.OpenFileDialog();
   1.224 -			this.saveArmyDialog = new System.Windows.Forms.SaveFileDialog();
   1.225 -			this.statusBarTimer = new System.Windows.Forms.Timer(this.components);
   1.226 -			this.menuStrip = new System.Windows.Forms.MenuStrip();
   1.227 -			this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.228 -			this.miNewArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.229 -			this.miOpenArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.230 -			this.miSaveArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.231 -			this.miSaveArmyAs = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.232 -			this.miExportArmyAs = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.233 -			this.miExportArmyAsBasicHTML = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.234 -			this.miCloseArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.235 -			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
   1.236 -			this.miReloadFiles = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.237 -			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
   1.238 -			this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.239 -			this.menuEdit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.240 -			this.miUndo = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.241 -			this.miRedo = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.242 -			this.menuHelp = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.243 -			this.miAbout = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
   1.244 -			this.mainToolStrip = new System.Windows.Forms.ToolStrip();
   1.245 -			this.bttnNewArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
   1.246 -			this.bttnOpenArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
   1.247 -			this.bttnSaveArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
   1.248 -			this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
   1.249 -			this.bttnUndo = new IBBoard.Windows.Forms.IBBToolStripSplitButton();
   1.250 -			this.bttnRedo = new IBBoard.Windows.Forms.IBBToolStripSplitButton();
   1.251 -			this.catToolStrip = new System.Windows.Forms.ToolStrip();
   1.252 -			this.statusBar = new IBBoard.Windows.Forms.ColorableStatusBar();
   1.253 -			this.sbMainPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
   1.254 -			this.sbErrorPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
   1.255 -			this.sbPointsPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
   1.256 -			this.toolStripPanel = new System.Windows.Forms.ToolStripPanel();
   1.257 -			this.menuStrip.SuspendLayout();
   1.258 -			this.mainToolStrip.SuspendLayout();
   1.259 -			((System.ComponentModel.ISupportInitialize) (this.sbMainPanel)).BeginInit();
   1.260 -			((System.ComponentModel.ISupportInitialize) (this.sbErrorPanel)).BeginInit();
   1.261 -			((System.ComponentModel.ISupportInitialize) (this.sbPointsPanel)).BeginInit();
   1.262 -			this.SuspendLayout();
   1.263 -			// 
   1.264 -			// saveArmyDialog
   1.265 -			// 
   1.266 -			this.saveArmyDialog.Title = "Translatable:saveArmyDialog";
   1.267 -			// 
   1.268 -			// statusBarTimer
   1.269 -			// 
   1.270 -			this.statusBarTimer.Interval = 5000;
   1.271 -			this.statusBarTimer.Tick += new System.EventHandler(this.statusBarTimer_Tick);
   1.272 -			// 
   1.273 -			// menuStrip
   1.274 -			// 
   1.275 -			this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
   1.276 -            this.menuFile,
   1.277 -            this.menuEdit,
   1.278 -            this.menuHelp});
   1.279 -			this.menuStrip.Location = new System.Drawing.Point(0, 0);
   1.280 -			this.menuStrip.Name = "menuStrip";
   1.281 -			this.menuStrip.Size = new System.Drawing.Size(790, 24);
   1.282 -			this.menuStrip.TabIndex = 6;
   1.283 -			this.menuStrip.Text = "menuStrip1";
   1.284 -			// 
   1.285 -			// menuFile
   1.286 -			// 
   1.287 -			this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
   1.288 -            this.miNewArmy,
   1.289 -            this.miOpenArmy,
   1.290 -            this.miSaveArmy,
   1.291 -            this.miSaveArmyAs,
   1.292 -            this.miExportArmyAs,
   1.293 -            this.miCloseArmy,
   1.294 -            this.toolStripSeparator1,
   1.295 -            this.miReloadFiles,
   1.296 -            this.toolStripSeparator2,
   1.297 -            this.miExit});
   1.298 -			this.menuFile.Name = "menuFile";
   1.299 -			this.menuFile.Size = new System.Drawing.Size(33, 20);
   1.300 -			this.menuFile.Text = "&file";
   1.301 -			// 
   1.302 -			// miNewArmy
   1.303 -			// 
   1.304 -			this.miNewArmy.Name = "miNewArmy";
   1.305 -			this.miNewArmy.Size = new System.Drawing.Size(164, 22);
   1.306 -			this.miNewArmy.Text = "&new army";
   1.307 -			this.miNewArmy.Click += new System.EventHandler(this.miNewArmy_Click);
   1.308 -			// 
   1.309 -			// miOpenArmy
   1.310 -			// 
   1.311 -			this.miOpenArmy.Name = "miOpenArmy";
   1.312 -			this.miOpenArmy.Size = new System.Drawing.Size(164, 22);
   1.313 -			this.miOpenArmy.Text = "&open army";
   1.314 -			this.miOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click);
   1.315 -			// 
   1.316 -			// miSaveArmy
   1.317 -			// 
   1.318 -			this.miSaveArmy.Enabled = false;
   1.319 -			this.miSaveArmy.Name = "miSaveArmy";
   1.320 -			this.miSaveArmy.Size = new System.Drawing.Size(164, 22);
   1.321 -			this.miSaveArmy.Text = "&save army";
   1.322 -			this.miSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click);
   1.323 -			// 
   1.324 -			// miSaveArmyAs
   1.325 -			// 
   1.326 -			this.miSaveArmyAs.Enabled = false;
   1.327 -			this.miSaveArmyAs.Name = "miSaveArmyAs";
   1.328 -			this.miSaveArmyAs.Size = new System.Drawing.Size(164, 22);
   1.329 -			this.miSaveArmyAs.Text = "save army &as...";
   1.330 -			this.miSaveArmyAs.Click += new System.EventHandler(this.miSaveArmyAs_Click);
   1.331 -			// 
   1.332 -			// miExportArmyAs
   1.333 -			// 
   1.334 -			this.miExportArmyAs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
   1.335 -            this.miExportArmyAsBasicHTML});
   1.336 -			this.miExportArmyAs.Enabled = false;
   1.337 -			this.miExportArmyAs.Name = "miExportArmyAs";
   1.338 -			this.miExportArmyAs.Size = new System.Drawing.Size(164, 22);
   1.339 -			this.miExportArmyAs.Text = "export army as...";
   1.340 -			// 
   1.341 -			// miExportArmyAsBasicHTML
   1.342 -			// 
   1.343 -			this.miExportArmyAsBasicHTML.Name = "miExportArmyAsBasicHTML";
   1.344 -			this.miExportArmyAsBasicHTML.Size = new System.Drawing.Size(130, 22);
   1.345 -			this.miExportArmyAsBasicHTML.Text = "&basic html";
   1.346 -			this.miExportArmyAsBasicHTML.Click += new System.EventHandler(this.miExportArmyAsBasicHTML_Click);
   1.347 -			// 
   1.348 -			// miCloseArmy
   1.349 -			// 
   1.350 -			this.miCloseArmy.Enabled = false;
   1.351 -			this.miCloseArmy.Name = "miCloseArmy";
   1.352 -			this.miCloseArmy.Size = new System.Drawing.Size(164, 22);
   1.353 -			this.miCloseArmy.Text = "&close army";
   1.354 -			this.miCloseArmy.Click += new System.EventHandler(this.miCloseArmy_Click);
   1.355 -			// 
   1.356 -			// toolStripSeparator1
   1.357 -			// 
   1.358 -			this.toolStripSeparator1.Name = "toolStripSeparator1";
   1.359 -			this.toolStripSeparator1.Size = new System.Drawing.Size(161, 6);
   1.360 -			// 
   1.361 -			// miReloadFiles
   1.362 -			// 
   1.363 -			this.miReloadFiles.Name = "miReloadFiles";
   1.364 -			this.miReloadFiles.Size = new System.Drawing.Size(164, 22);
   1.365 -			this.miReloadFiles.Text = "&reload files";
   1.366 -			this.miReloadFiles.Click += new System.EventHandler(this.miReloadFiles_Click);
   1.367 -			// 
   1.368 -			// toolStripSeparator2
   1.369 -			// 
   1.370 -			this.toolStripSeparator2.Name = "toolStripSeparator2";
   1.371 -			this.toolStripSeparator2.Size = new System.Drawing.Size(161, 6);
   1.372 -			// 
   1.373 -			// miExit
   1.374 -			// 
   1.375 -			this.miExit.Name = "miExit";
   1.376 -			this.miExit.Size = new System.Drawing.Size(164, 22);
   1.377 -			this.miExit.Text = "e&xit";
   1.378 -			this.miExit.Click += new System.EventHandler(this.miExit_Click);
   1.379 -			// 
   1.380 -			// menuEdit
   1.381 -			// 
   1.382 -			this.menuEdit.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
   1.383 -            this.miUndo,
   1.384 -            this.miRedo});
   1.385 -			this.menuEdit.Name = "menuEdit";
   1.386 -			this.menuEdit.Size = new System.Drawing.Size(36, 20);
   1.387 -			this.menuEdit.Text = "&edit";
   1.388 -			// 
   1.389 -			// miUndo
   1.390 -			// 
   1.391 -			this.miUndo.Enabled = false;
   1.392 -			this.miUndo.Name = "miUndo";
   1.393 -			this.miUndo.Size = new System.Drawing.Size(106, 22);
   1.394 -			this.miUndo.Text = "&undo";
   1.395 -			this.miUndo.Click += new System.EventHandler(this.miUndo_Click);
   1.396 -			// 
   1.397 -			// miRedo
   1.398 -			// 
   1.399 -			this.miRedo.Enabled = false;
   1.400 -			this.miRedo.Name = "miRedo";
   1.401 -			this.miRedo.Size = new System.Drawing.Size(106, 22);
   1.402 -			this.miRedo.Text = "&redo";
   1.403 -			this.miRedo.Click += new System.EventHandler(this.miRedo_Click);
   1.404 -			// 
   1.405 -			// menuHelp
   1.406 -			// 
   1.407 -			this.menuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
   1.408 -            this.miAbout});
   1.409 -			this.menuHelp.Name = "menuHelp";
   1.410 -			this.menuHelp.Size = new System.Drawing.Size(39, 20);
   1.411 -			this.menuHelp.Text = "&help";
   1.412 -			// 
   1.413 -			// miAbout
   1.414 -			// 
   1.415 -			this.miAbout.Name = "miAbout";
   1.416 -			this.miAbout.Size = new System.Drawing.Size(109, 22);
   1.417 -			this.miAbout.Text = "&about";
   1.418 -			this.miAbout.Click += new System.EventHandler(this.miAbout_Click);
   1.419 -			// 
   1.420 -			// mainToolStrip
   1.421 -			// 
   1.422 -			this.mainToolStrip.Dock = System.Windows.Forms.DockStyle.None;
   1.423 -			this.mainToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
   1.424 -            this.bttnNewArmy,
   1.425 -            this.bttnOpenArmy,
   1.426 -            this.bttnSaveArmy,
   1.427 -            this.toolStripSeparator3,
   1.428 -            this.bttnUndo,
   1.429 -            this.bttnRedo});
   1.430 -			this.mainToolStrip.Location = new System.Drawing.Point(0, 24);
   1.431 -			this.mainToolStrip.Name = "mainToolStrip";
   1.432 -			this.mainToolStrip.Size = new System.Drawing.Size(182, 25);
   1.433 -			this.mainToolStrip.TabIndex = 8;
   1.434 -			// 
   1.435 -			// bttnNewArmy
   1.436 -			// 
   1.437 -			this.bttnNewArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
   1.438 -			this.bttnNewArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_new;
   1.439 -			this.bttnNewArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
   1.440 -			this.bttnNewArmy.Name = "bttnNewArmy";
   1.441 -			this.bttnNewArmy.Size = new System.Drawing.Size(23, 22);
   1.442 -			this.bttnNewArmy.Text = "new army";
   1.443 -			this.bttnNewArmy.Click += new System.EventHandler(this.miNewArmy_Click);
   1.444 -			// 
   1.445 -			// bttnOpenArmy
   1.446 -			// 
   1.447 -			this.bttnOpenArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
   1.448 -			this.bttnOpenArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_open;
   1.449 -			this.bttnOpenArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
   1.450 -			this.bttnOpenArmy.Name = "bttnOpenArmy";
   1.451 -			this.bttnOpenArmy.Size = new System.Drawing.Size(23, 22);
   1.452 -			this.bttnOpenArmy.Text = "open army";
   1.453 -			this.bttnOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click);
   1.454 -			// 
   1.455 -			// bttnSaveArmy
   1.456 -			// 
   1.457 -			this.bttnSaveArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
   1.458 -			this.bttnSaveArmy.Enabled = false;
   1.459 -			this.bttnSaveArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_save;
   1.460 -			this.bttnSaveArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
   1.461 -			this.bttnSaveArmy.Name = "bttnSaveArmy";
   1.462 -			this.bttnSaveArmy.Size = new System.Drawing.Size(23, 22);
   1.463 -			this.bttnSaveArmy.Text = "save army";
   1.464 -			this.bttnSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click);
   1.465 -			// 
   1.466 -			// toolStripSeparator3
   1.467 -			// 
   1.468 -			this.toolStripSeparator3.Name = "toolStripSeparator3";
   1.469 -			this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
   1.470 -			// 
   1.471 -			// bttnUndo
   1.472 -			// 
   1.473 -			this.bttnUndo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
   1.474 -			this.bttnUndo.Enabled = false;
   1.475 -			this.bttnUndo.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_undo;
   1.476 -			this.bttnUndo.ImageTransparentColor = System.Drawing.Color.Magenta;
   1.477 -			this.bttnUndo.Name = "bttnUndo";
   1.478 -			this.bttnUndo.Size = new System.Drawing.Size(32, 22);
   1.479 -			this.bttnUndo.Text = "undo";
   1.480 -			this.bttnUndo.ButtonClick += new System.EventHandler(this.miUndo_Click);
   1.481 -			// 
   1.482 -			// bttnRedo
   1.483 -			// 
   1.484 -			this.bttnRedo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
   1.485 -			this.bttnRedo.Enabled = false;
   1.486 -			this.bttnRedo.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_redo;
   1.487 -			this.bttnRedo.ImageTransparentColor = System.Drawing.Color.Magenta;
   1.488 -			this.bttnRedo.Name = "bttnRedo";
   1.489 -			this.bttnRedo.Size = new System.Drawing.Size(32, 22);
   1.490 -			this.bttnRedo.Text = "redo";
   1.491 -			this.bttnRedo.ButtonClick += new System.EventHandler(this.miRedo_Click);
   1.492 -			// 
   1.493 -			// catToolStrip
   1.494 -			// 
   1.495 -			this.catToolStrip.Dock = System.Windows.Forms.DockStyle.None;
   1.496 -			this.catToolStrip.Location = new System.Drawing.Point(161, 24);
   1.497 -			this.catToolStrip.Name = "catToolStrip";
   1.498 -			this.catToolStrip.Size = new System.Drawing.Size(111, 25);
   1.499 -			this.catToolStrip.TabIndex = 9;
   1.500 -			this.catToolStrip.Visible = false;
   1.501 -			// 
   1.502 -			// statusBar
   1.503 -			// 
   1.504 -			this.statusBar.Location = new System.Drawing.Point(0, 586);
   1.505 -			this.statusBar.Name = "statusBar";
   1.506 -			this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
   1.507 -            this.sbMainPanel,
   1.508 -            this.sbErrorPanel,
   1.509 -            this.sbPointsPanel});
   1.510 -			this.statusBar.ShowPanels = true;
   1.511 -			this.statusBar.Size = new System.Drawing.Size(790, 22);
   1.512 -			this.statusBar.TabIndex = 1;
   1.513 -			this.statusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar_PanelClick);
   1.514 -			this.statusBar.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem);
   1.515 -			// 
   1.516 -			// sbMainPanel
   1.517 -			// 
   1.518 -			this.sbMainPanel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
   1.519 -			this.sbMainPanel.Color = System.Drawing.SystemColors.WindowText;
   1.520 -			this.sbMainPanel.Name = "sbMainPanel";
   1.521 -			this.sbMainPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
   1.522 -			this.sbMainPanel.Width = 473;
   1.523 -			// 
   1.524 -			// sbErrorPanel
   1.525 -			// 
   1.526 -			this.sbErrorPanel.Color = System.Drawing.SystemColors.WindowText;
   1.527 -			this.sbErrorPanel.Name = "sbErrorPanel";
   1.528 -			this.sbErrorPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
   1.529 -			this.sbErrorPanel.Width = 150;
   1.530 -			// 
   1.531 -			// sbPointsPanel
   1.532 -			// 
   1.533 -			this.sbPointsPanel.Color = System.Drawing.SystemColors.WindowText;
   1.534 -			this.sbPointsPanel.Name = "sbPointsPanel";
   1.535 -			this.sbPointsPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
   1.536 -			this.sbPointsPanel.ToolTipText = "current points total";
   1.537 -			this.sbPointsPanel.Width = 150;
   1.538 -			// 
   1.539 -			// toolStripPanel
   1.540 -			// 
   1.541 -			this.toolStripPanel.Dock = System.Windows.Forms.DockStyle.Top;
   1.542 -			this.toolStripPanel.Location = new System.Drawing.Point(0, 24);
   1.543 -			this.toolStripPanel.Name = "toolStripPanel";
   1.544 -			this.toolStripPanel.Orientation = System.Windows.Forms.Orientation.Horizontal;
   1.545 -			this.toolStripPanel.RowMargin = new System.Windows.Forms.Padding(3, 0, 0, 0);
   1.546 -			this.toolStripPanel.Size = new System.Drawing.Size(790, 0);
   1.547 -			// 
   1.548 -			// FrmMain
   1.549 -			// 
   1.550 -			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.551 -			this.ClientSize = new System.Drawing.Size(790, 608);
   1.552 -			this.Controls.Add(this.mainToolStrip);
   1.553 -			this.Controls.Add(this.toolStripPanel);
   1.554 -			this.Controls.Add(this.statusBar);
   1.555 -			this.Controls.Add(this.catToolStrip);
   1.556 -			this.Controls.Add(this.menuStrip);
   1.557 -			this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
   1.558 -			this.IsMdiContainer = true;
   1.559 -			this.MainMenuStrip = this.menuStrip;
   1.560 -			this.Menu = this.mainMenu;
   1.561 -			this.Name = "FrmMain";
   1.562 -			this.Text = "WarFoundry";
   1.563 -			this.Load += new System.EventHandler(this.FrmMain_Load);
   1.564 -			this.menuStrip.ResumeLayout(false);
   1.565 -			this.menuStrip.PerformLayout();
   1.566 -			this.mainToolStrip.ResumeLayout(false);
   1.567 -			this.mainToolStrip.PerformLayout();
   1.568 -			((System.ComponentModel.ISupportInitialize) (this.sbMainPanel)).EndInit();
   1.569 -			((System.ComponentModel.ISupportInitialize) (this.sbErrorPanel)).EndInit();
   1.570 -			((System.ComponentModel.ISupportInitialize) (this.sbPointsPanel)).EndInit();
   1.571 -			this.ResumeLayout(false);
   1.572 -			this.PerformLayout();
   1.573 -
   1.574 -		}
   1.575 -		#endregion
   1.576 -
   1.577 -		private void FileLoadingFinished(List<FileLoadFailure> failures)
   1.578 -		{
   1.579 -			foreach (FileLoadFailure failure in failures)
   1.580 -			{
   1.581 -				log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
   1.582 -			}
   1.583 -		}
   1.584 -
   1.585 -		private void miExit_Click(object sender, System.EventArgs e)
   1.586 -		{
   1.587 -			Application.Exit();
   1.588 -		}
   1.589 -
   1.590 -		private void miNewArmy_Click(object sender, System.EventArgs e)
   1.591 -		{
   1.592 -			CreateNewArmy();
   1.593 -		}
   1.594 -
   1.595 -		private void CreateNewArmy()
   1.596 -		{
   1.597 -			if (CloseCurrentArmy())
   1.598 -			{
   1.599 -				FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem);
   1.600 -				DialogResult dr = newArmy.ShowDialog();
   1.601 -
   1.602 -				if (dr == DialogResult.OK)
   1.603 -				{
   1.604 -					try
   1.605 -					{
   1.606 -						CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize);
   1.607 -					}
   1.608 -					catch (RequiredDataMissingException ex)
   1.609 -					{
   1.610 -						log.Error("Required data missing from race file", ex);
   1.611 -						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.612 -					}
   1.613 -					catch (InvalidFileException ex)
   1.614 -					{
   1.615 -						log.Error("Race file was invalid", ex);
   1.616 -						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.617 -					}
   1.618 -				}
   1.619 -			}
   1.620 -		}
   1.621 -
   1.622 -		private bool OpenArmy()
   1.623 -		{
   1.624 -			if (openArmyDialog.Filter=="")
   1.625 -			{
   1.626 -				string savePath = ArmiesPath;
   1.627 -			
   1.628 -				if (!Directory.Exists(savePath))
   1.629 -				{
   1.630 -					Directory.CreateDirectory(savePath);
   1.631 -				}
   1.632 -
   1.633 -				openArmyDialog.InitialDirectory = savePath;
   1.634 -				openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
   1.635 -				openArmyDialog.Title = Translation.GetTranslation("openArmyDialog");
   1.636 -
   1.637 -			}
   1.638 -
   1.639 -			DialogResult dr = openArmyDialog.ShowDialog(this);
   1.640 -
   1.641 -			if (dr == DialogResult.OK)
   1.642 -			{
   1.643 -				if (CloseCurrentArmy())
   1.644 -				{
   1.645 -					try
   1.646 -					{
   1.647 -						string newFilePath = openArmyDialog.FileName;
   1.648 -						CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath));
   1.649 -						loadedFilePath = newFilePath;
   1.650 -						return true;
   1.651 -					}
   1.652 -					catch (RequiredDataMissingException ex)
   1.653 -					{
   1.654 -						log.Error(ex);
   1.655 -						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.656 -						return false;
   1.657 -					}
   1.658 -					catch (InvalidFileException ex)
   1.659 -					{
   1.660 -						log.Error(ex);
   1.661 -						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.662 -						return false;
   1.663 -					}
   1.664 -				}
   1.665 -				else
   1.666 -				{
   1.667 -					return false;
   1.668 -				}
   1.669 -			}
   1.670 -			else
   1.671 -			{
   1.672 -				return false;
   1.673 -			}
   1.674 -		}
   1.675 -
   1.676 -		private bool CloseCurrentArmy()
   1.677 -		{
   1.678 -			if (CurrentArmy!=null)
   1.679 -			{
   1.680 -				bool canClose = false;
   1.681 -
   1.682 -				if (CommandStack.IsDirty())
   1.683 -				{
   1.684 -					string saveChanges = Translation.GetTranslation("SaveChangesQuestion", "the army \"{0}\" has been modified\r\nsave changes before closing army?", CurrentArmy.Name);
   1.685 -					string saveChangesTitle = Translation.GetTranslation("SaveChangesTitle", "unsaved changes");
   1.686 -					DialogResult dr = MessageBox.Show(this, saveChanges, saveChangesTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3);
   1.687 -
   1.688 -					if (dr == DialogResult.Yes)
   1.689 -					{
   1.690 -						canClose = SaveCurrentArmy();
   1.691 -					}
   1.692 -					else if (dr == DialogResult.No)
   1.693 -					{
   1.694 -						canClose = true;
   1.695 -					}
   1.696 -					//else they said cancel and we default to "canClose = false" so do nothing
   1.697 -				}
   1.698 -				else
   1.699 -				{
   1.700 -					canClose = true;
   1.701 -				}
   1.702 -
   1.703 -				if (canClose)
   1.704 -				{
   1.705 -					//do close
   1.706 -					DisableCategoryButtons();
   1.707 -					CurrentArmy = null;
   1.708 -					return true;
   1.709 -				}
   1.710 -				else
   1.711 -				{
   1.712 -					return false;
   1.713 -				}
   1.714 -			}
   1.715 -			else
   1.716 -			{
   1.717 -				DisableCategoryButtons();
   1.718 -				//pretend we succeeded
   1.719 -				return true;
   1.720 -			}
   1.721 -		}
   1.722 -
   1.723 -		private void UndoLastAction()
   1.724 -		{
   1.725 -			if (commandStack.CanUndo())
   1.726 -			{
   1.727 -				commandStack.Undo();
   1.728 -			}
   1.729 -		}
   1.730 -
   1.731 -		private void RedoAction()
   1.732 -		{
   1.733 -			if (commandStack.CanRedo())
   1.734 -			{
   1.735 -				commandStack.Redo();
   1.736 -			}
   1.737 -		}
   1.738 -
   1.739 -		private bool SaveCurrentArmy()
   1.740 -		{
   1.741 -			bool saved = false;
   1.742 -
   1.743 -			string filePath = loadedFilePath;
   1.744 -
   1.745 -			if (filePath == null)
   1.746 -			{
   1.747 -				filePath = PromptForArmyFilePath();
   1.748 -			}
   1.749 -
   1.750 -			if (filePath != null)
   1.751 -			{
   1.752 -				saved = SaveCurrentArmyToFile(filePath);
   1.753 -			}
   1.754 -
   1.755 -			return saved;
   1.756 -		}
   1.757 -
   1.758 -		private bool SaveCurrentArmyAs()
   1.759 -		{
   1.760 -			bool saved = false;
   1.761 -			string filePath = PromptForArmyFilePath();
   1.762 -
   1.763 -			if (filePath != null)
   1.764 -			{
   1.765 -				saved = SaveCurrentArmyToFile(filePath);
   1.766 -			}
   1.767 -			
   1.768 -			return saved;
   1.769 -		}
   1.770 -
   1.771 -		private bool SaveCurrentArmyToFile(string filePath)
   1.772 -		{
   1.773 -			if (WarFoundrySaver.GetSaver().Save(CurrentArmy, filePath))
   1.774 -			{
   1.775 -				loadedFilePath = filePath;
   1.776 -				miSaveArmy.Enabled = false;
   1.777 -				bttnSaveArmy.Enabled = false;
   1.778 -				CommandStack.setCleanMark();
   1.779 -				return true;
   1.780 -			}
   1.781 -			else
   1.782 -			{
   1.783 -				MessageBox.Show(this, Translation.GetTranslation("SaveFailed", "file save failed - check log for details"), Translation.GetTranslation("SaveFailedTitle", "file save failed"), MessageBoxButtons.OK, MessageBoxIcon.Error);
   1.784 -				return false;
   1.785 -			}
   1.786 -		}
   1.787 -
   1.788 -		private string PromptForArmyFilePath()
   1.789 -		{
   1.790 -			if (saveArmyDialog.Filter == "")
   1.791 -			{
   1.792 -				string savePath = ArmiesPath;
   1.793 -				
   1.794 -				if (!Directory.Exists(savePath))
   1.795 -				{
   1.796 -					Directory.CreateDirectory(savePath);
   1.797 -				}
   1.798 -
   1.799 -				saveArmyDialog.InitialDirectory = savePath;
   1.800 -				saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
   1.801 -				saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog");
   1.802 -			}
   1.803 -
   1.804 -			DialogResult dr = saveArmyDialog.ShowDialog(this);
   1.805 -
   1.806 -			if (dr == DialogResult.OK)
   1.807 -			{
   1.808 -				return saveArmyDialog.FileName;
   1.809 -			}
   1.810 -			else
   1.811 -			{
   1.812 -				return null;
   1.813 -			}
   1.814 -		}
   1.815 -
   1.816 -		public GameSystem CurrentGameSystem
   1.817 -		{
   1.818 -			get { return WarFoundryCore.CurrentGameSystem; }
   1.819 -			set { WarFoundryCore.CurrentGameSystem = value; }
   1.820 -		}
   1.821 -
   1.822 -		public Army CurrentArmy
   1.823 -		{
   1.824 -			get { return WarFoundryCore.CurrentArmy; }
   1.825 -			set { SetArmy(value); }
   1.826 -		}
   1.827 -
   1.828 -		private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem)
   1.829 -		{
   1.830 -			SetAppTitle();
   1.831 -			RemoveCategoryButtons();
   1.832 -		}
   1.833 -
   1.834 -		private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy)
   1.835 -		{
   1.836 -			CommandStack.Reset();
   1.837 -			loadedFilePath = null;
   1.838 -			miSaveArmy.Enabled = false;
   1.839 -			bttnSaveArmy.Enabled = false;
   1.840 -			SetPointsPanelText();
   1.841 -			SetAppTitle();
   1.842 -		}
   1.843 -
   1.844 -		private void SetArmy(Army newArmy)
   1.845 -		{
   1.846 -			IgnoreArmy(CurrentArmy);
   1.847 -			CloseAllUnitWindows();
   1.848 -
   1.849 -			if (newArmy == null)
   1.850 -			{
   1.851 -				SetNullArmyState();
   1.852 -			}
   1.853 -			else
   1.854 -			{
   1.855 -				WarFoundryCore.CurrentGameSystem = newArmy.GameSystem;
   1.856 -				ListenToArmy(newArmy);
   1.857 -				SetNonNullArmyState(newArmy);
   1.858 -			}
   1.859 -			
   1.860 -			WarFoundryCore.CurrentArmy = newArmy;
   1.861 -		}
   1.862 -
   1.863 -		private void IgnoreArmy(Army oldArmy)
   1.864 -		{
   1.865 -			if (oldArmy != null)
   1.866 -			{
   1.867 -				oldArmy.UnitAdded -= UnitAddedMethod;
   1.868 -				oldArmy.UnitRemoved -= UnitRemovedMethod;
   1.869 -				oldArmy.PointsValueChanged -= PointsValueChangedMethod;
   1.870 -			}
   1.871 -		}
   1.872 -
   1.873 -		private void CloseAllUnitWindows()
   1.874 -		{
   1.875 -			FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows);
   1.876 -
   1.877 -			foreach (FrmUnit window in unitForms)
   1.878 -			{
   1.879 -				window.Close();
   1.880 -			}
   1.881 -
   1.882 -			unitWindows.Clear();
   1.883 -		}
   1.884 -
   1.885 -		private void ListenToArmy(Army newArmy)
   1.886 -		{
   1.887 -			if (newArmy != null)
   1.888 -			{
   1.889 -				newArmy.UnitAdded += UnitAddedMethod;
   1.890 -				newArmy.UnitRemoved += UnitRemovedMethod;
   1.891 -				newArmy.PointsValueChanged += PointsValueChangedMethod;
   1.892 -			}
   1.893 -		}
   1.894 -
   1.895 -		private void SetNullArmyState()
   1.896 -		{
   1.897 -			miSaveArmyAs.Enabled = false;
   1.898 -			miCloseArmy.Enabled = false;
   1.899 -			miExportArmyAs.Enabled = false;
   1.900 -			DisableCategoryButtons();
   1.901 -			armyTree.Hide();
   1.902 -		}
   1.903 -
   1.904 -		private void SetNonNullArmyState(Army newArmy)
   1.905 -		{
   1.906 -			SetCategoryButtons(newArmy.Race.Categories);
   1.907 -			EnableCategoryButtons();
   1.908 -			miSaveArmyAs.Enabled = true;
   1.909 -			miCloseArmy.Enabled = true;
   1.910 -			miExportArmyAs.Enabled = true;
   1.911 -			armyTree.Show();
   1.912 -		}
   1.913 -
   1.914 -		private void SetCategoryButtons(Category[] cats)
   1.915 -		{
   1.916 -			if (CategoryButtonsHaveChanged(cats))
   1.917 -			{
   1.918 -				RemoveCategoryButtons();
   1.919 -				AddCategoryButtons(cats);
   1.920 -			}
   1.921 -		}
   1.922 -
   1.923 -		private bool CategoryButtonsHaveChanged(Category[] cats)
   1.924 -		{
   1.925 -			int catCount = cats.Length;
   1.926 -			ToolStripItemCollection items = catToolStrip.Items;
   1.927 -			bool haveChanged = (!catToolStrip.Visible || catCount != items.Count);
   1.928 -
   1.929 -			if (!haveChanged)
   1.930 -			{
   1.931 -				for (int i = 0; i < catCount; i++)
   1.932 -				{
   1.933 -					if (cats[i].Equals(items[i+1].Tag))
   1.934 -					{
   1.935 -						haveChanged = true;
   1.936 -						break;
   1.937 -					}
   1.938 -				}
   1.939 -			}
   1.940 -
   1.941 -			return haveChanged;
   1.942 -		}
   1.943 -
   1.944 -		private void RemoveCategoryButtons()
   1.945 -		{
   1.946 -			this.Invoke(new MethodInvoker(catToolStrip.Items.Clear));
   1.947 -		}
   1.948 -
   1.949 -		private void AddCategoryButtons(Category[] cats)
   1.950 -		{
   1.951 -			int catCount = cats.Length;
   1.952 -			Category cat;
   1.953 -			IBBToolStripButton[] categoryButtons = new IBBToolStripButton[catCount];
   1.954 -
   1.955 -			for (int i = 0; i < catCount; i++)
   1.956 -			{
   1.957 -				cat = cats[i];
   1.958 -				IBBToolStripButton button = new IBBToolStripButton();
   1.959 -				button.Text = cat.Name;
   1.960 -				button.Tag = cat;
   1.961 -				button.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
   1.962 -				button.Enabled = false;
   1.963 -				button.Click += new EventHandler(CreateUnitForCategoryButtonClick);
   1.964 -				categoryButtons[i] = button;
   1.965 -			}
   1.966 -
   1.967 -			this.Invoke(new ArrayMethodInvoker<IBBToolStripButton>(catToolStrip.Items.AddRange), new object[]{ categoryButtons });
   1.968 -		}
   1.969 -
   1.970 -		private void CreateUnitForCategoryButtonClick(object sender, EventArgs e)
   1.971 -		{
   1.972 -			if (sender is IBBToolStripButton)
   1.973 -			{
   1.974 -				IBBToolStripButton button = (IBBToolStripButton)sender;
   1.975 -				object tag = button.Tag;
   1.976 -
   1.977 -				if (tag is Category)
   1.978 -				{
   1.979 -					AddUnitFromCategory((Category)tag);
   1.980 -				}
   1.981 -			}
   1.982 -		}
   1.983 -
   1.984 -		private void EnableCategoryButtons()
   1.985 -		{
   1.986 -			catToolStrip.Visible = true;
   1.987 -			SetCategoryButtonState(true);
   1.988 -		}
   1.989 -
   1.990 -		private void DisableCategoryButtons()
   1.991 -		{
   1.992 -			catToolStrip.Visible = false;
   1.993 -			SetCategoryButtonState(false);
   1.994 -		}
   1.995 -
   1.996 -		private void SetCategoryButtonState(bool state)
   1.997 -		{
   1.998 -			foreach (IBBToolStripButton button in catToolStrip.Items)
   1.999 -			{
  1.1000 -				button.Enabled = state;
  1.1001 -			}
  1.1002 -		}
  1.1003 -
  1.1004 -		private void miSaveArmyAs_Click(object sender, System.EventArgs e)
  1.1005 -		{
  1.1006 -			SaveCurrentArmyAs();
  1.1007 -		}
  1.1008 -
  1.1009 -		private void commandStack_CommandStackUpdated()
  1.1010 -		{
  1.1011 -			bttnUndo.Enabled = commandStack.CanUndo();
  1.1012 -			miUndo.Enabled = bttnUndo.Enabled;
  1.1013 -			bttnRedo.Enabled = commandStack.CanRedo();
  1.1014 -			miRedo.Enabled = bttnRedo.Enabled;
  1.1015 -
  1.1016 -			PopulateRedoMenu();
  1.1017 -			PopulateUndoMenu();
  1.1018 -
  1.1019 -			bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null;
  1.1020 -			miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null;
  1.1021 -		}
  1.1022 -
  1.1023 -		private void PopulateRedoMenu()
  1.1024 -		{
  1.1025 -			int redoLength = commandStack.RedoLength;
  1.1026 -			int maxRedo = Math.Min(10, redoLength);
  1.1027 -			ToolStripItemCollection dropDownItems = bttnRedo.DropDownItems;
  1.1028 -			dropDownItems.Clear();
  1.1029 -
  1.1030 -			for (int i = 1; i <= maxRedo; i++)
  1.1031 -			{
  1.1032 -				Command cmd = commandStack.PeekRedoCommand(i);
  1.1033 -
  1.1034 -				if (cmd == null)
  1.1035 -				{
  1.1036 -					break;
  1.1037 -				}
  1.1038 -
  1.1039 -				dropDownItems.Add(cmd.Description, null, redoMenu_Click);
  1.1040 -			}
  1.1041 -
  1.1042 -			if (redoLength > 0)
  1.1043 -			{
  1.1044 -				bttnRedo.Text = commandStack.PeekRedoCommand(1).Description;
  1.1045 -			}
  1.1046 -			else
  1.1047 -			{
  1.1048 -				bttnRedo.Text = Translation.GetTranslation("bttnRedo");
  1.1049 -			}
  1.1050 -		}
  1.1051 -
  1.1052 -		private void PopulateUndoMenu()
  1.1053 -		{
  1.1054 -			int undoLength = commandStack.UndoLength;
  1.1055 -			int maxUndo = Math.Min(10, undoLength);
  1.1056 -			ToolStripItemCollection dropDownItems = bttnUndo.DropDownItems;
  1.1057 -			dropDownItems.Clear();
  1.1058 -
  1.1059 -			for (int i = 1; i <= maxUndo; i++)
  1.1060 -			{
  1.1061 -				Command cmd = commandStack.PeekUndoCommand(i);
  1.1062 -
  1.1063 -				if (cmd == null)
  1.1064 -				{
  1.1065 -					break;
  1.1066 -				}
  1.1067 -
  1.1068 -				dropDownItems.Add(cmd.UndoDescription, null, undoMenu_Click);
  1.1069 -			}
  1.1070 -
  1.1071 -			if (undoLength > 0)
  1.1072 -			{
  1.1073 -				bttnUndo.Text = commandStack.PeekUndoCommand(1).UndoDescription;
  1.1074 -			}
  1.1075 -			else
  1.1076 -			{
  1.1077 -				bttnUndo.Text = Translation.GetTranslation("bttnUndo");
  1.1078 -			}
  1.1079 -		}
  1.1080 -
  1.1081 -		private void miSaveArmy_Click(object sender, System.EventArgs e)
  1.1082 -		{
  1.1083 -			SaveCurrentArmy();
  1.1084 -		}
  1.1085 -
  1.1086 -		private void SetAppTitle()
  1.1087 -		{
  1.1088 -			string str = AppTitle;
  1.1089 -
  1.1090 -			if (CurrentGameSystem!=null)
  1.1091 -			{
  1.1092 -				str+= " - "+CurrentGameSystem.Name;
  1.1093 -			}
  1.1094 -
  1.1095 -			if (CurrentArmy!=null)
  1.1096 -			{
  1.1097 -				str+= " - "+CurrentArmy.Name;
  1.1098 -			}
  1.1099 -
  1.1100 -			this.Text = str;
  1.1101 -		}
  1.1102 -
  1.1103 -		private void AddUnitFromCategory(Category cat)
  1.1104 -		{
  1.1105 -			FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy);
  1.1106 -			DialogResult dr = newUnit.ShowDialog(this);
  1.1107 -
  1.1108 -			if (dr == DialogResult.OK)
  1.1109 -			{
  1.1110 -				CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat));
  1.1111 -				commandStack.Execute(cmd);
  1.1112 -				OpenUnitDialog(cmd.Unit);
  1.1113 -			}
  1.1114 -		}
  1.1115 -
  1.1116 -		internal void OpenUnitDialog(Unit unit)
  1.1117 -		{
  1.1118 -			string unitID = unit.ID;
  1.1119 -
  1.1120 -			if (unitWindows.ContainsKey(unitID))
  1.1121 -			{
  1.1122 -				unitWindows[unitID].Focus();
  1.1123 -			}
  1.1124 -			else
  1.1125 -			{
  1.1126 -				FrmUnit unitForm = new FrmUnit(unit, commandStack);
  1.1127 -				unitWindows.Add(unitID, unitForm);
  1.1128 -				unitForm.MdiParent = this;
  1.1129 -				unitForm.Closing += new CancelEventHandler(unitForm_Closing);
  1.1130 -				unitForm.Show();
  1.1131 -			}
  1.1132 -		}
  1.1133 -
  1.1134 -		private void unitForm_Closing(object sender, CancelEventArgs e)
  1.1135 -		{
  1.1136 -			if (sender is FrmUnit)
  1.1137 -			{
  1.1138 -				FrmUnit unitForm = (FrmUnit) sender;
  1.1139 -				unitWindows.Remove(unitForm.Unit.ID);
  1.1140 -			}
  1.1141 -		}
  1.1142 -
  1.1143 -		private void FrmMain_UnitAddedMethod(object unitObj)
  1.1144 -		{
  1.1145 -			if (unitObj is Unit)
  1.1146 -			{
  1.1147 -				Unit unit = (Unit)unitObj;
  1.1148 -				sbErrorPanel.Text = "";
  1.1149 -			}
  1.1150 -		}
  1.1151 -
  1.1152 -		private void FrmMain_UnitRemovedMethod(object unitObj)
  1.1153 -		{
  1.1154 -			if (unitObj is Unit)
  1.1155 -			{
  1.1156 -				Unit unit = (Unit)unitObj;
  1.1157 -				sbErrorPanel.Text = "";
  1.1158 -
  1.1159 -				//check if window is open, and close it if it is
  1.1160 -				foreach (Form frm in this.MdiChildren)
  1.1161 -				{
  1.1162 -					if (frm is FrmUnit)
  1.1163 -					{
  1.1164 -						if (((FrmUnit)frm).Unit == unit)
  1.1165 -						{
  1.1166 -							frm.Close();
  1.1167 -							break;
  1.1168 -						}
  1.1169 -					}
  1.1170 -				}
  1.1171 -			}
  1.1172 -		}
  1.1173 -
  1.1174 -		/*private void FrmMain_FailedUnitRequirement(FailedUnitRequirement failedRequirement)
  1.1175 -		{
  1.1176 -			sbErrorPanel.Text = Translation.GetTranslation("UnitRequirementFailed", "Unit Requirement Failed");
  1.1177 -			sbErrorPanel.Tag = failedRequirement.Description;
  1.1178 -		}*/
  1.1179 -
  1.1180 -		/*public void MdiChildMoved()
  1.1181 -		{
  1.1182 -			Point mouseAt = PointToClient(ActiveMdiChild.Location);
  1.1183 -
  1.1184 -			if (Comparisons.ValueWithinAmount(pnlRight.Right, ActiveMdiChild.Right, 10))
  1.1185 -			{
  1.1186 -				pnlRight.Visible = true;
  1.1187 -				//pnlRight.Container.Add(ActiveMdiChild);
  1.1188 -			}
  1.1189 -			else
  1.1190 -			{
  1.1191 -				pnlRight.Visible = false;
  1.1192 -			}
  1.1193 -		}*/
  1.1194 -
  1.1195 -		private void miUndo_Click(object sender, System.EventArgs e)
  1.1196 -		{
  1.1197 -			UndoLastAction();
  1.1198 -		}
  1.1199 -
  1.1200 -		private void miRedo_Click(object sender, System.EventArgs e)
  1.1201 -		{
  1.1202 -			RedoAction();
  1.1203 -		}
  1.1204 -
  1.1205 -		private void miCloseArmy_Click(object sender, EventArgs e)
  1.1206 -		{
  1.1207 -			CloseCurrentArmy();
  1.1208 -		}
  1.1209 -
  1.1210 -		private void miOpenArmy_Click(object sender, EventArgs e)
  1.1211 -		{
  1.1212 -			OpenArmy();
  1.1213 -		}
  1.1214 -
  1.1215 -		private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal)
  1.1216 -		{
  1.1217 -			if (obj is Army)
  1.1218 -			{
  1.1219 -				SetPointsPanelText();
  1.1220 -			}
  1.1221 -		}
  1.1222 -
  1.1223 -		private void SetPointsPanelText()
  1.1224 -		{	
  1.1225 -			if (CurrentArmy==null)
  1.1226 -			{
  1.1227 -				sbPointsPanel.Text = "";
  1.1228 -				sbPointsPanel.ResetColor();
  1.1229 -			}
  1.1230 -			else 
  1.1231 -			{
  1.1232 -				sbPointsPanel.Text = String.Format(Translation.GetTranslation("statusPanelPoints"), CurrentArmy.Points, CurrentArmy.MaxPoints);
  1.1233 -
  1.1234 -				if (CurrentArmy.Points>CurrentArmy.MaxPoints)
  1.1235 -				{
  1.1236 -					sbPointsPanel.Color = Color.Red;
  1.1237 -				}
  1.1238 -				else
  1.1239 -				{
  1.1240 -					sbPointsPanel.ResetColor();
  1.1241 -				}
  1.1242 -			}
  1.1243 -		}
  1.1244 -
  1.1245 -		private void redoMenu_Click(object sender, EventArgs e)
  1.1246 -		{
  1.1247 -			if (sender is ToolStripDropDownItem)
  1.1248 -			{
  1.1249 -				ToolStripDropDownItem item = (ToolStripDropDownItem)sender;
  1.1250 -					//we know it's an redo menu item so find it's index and redo everything					
  1.1251 -				int max = bttnRedo.DropDownItems.IndexOf(item);
  1.1252 -
  1.1253 -				if (max >= 0)
  1.1254 -				{
  1.1255 -					for (int i = 0; i <= max; i++)
  1.1256 -					{
  1.1257 -						commandStack.Redo();
  1.1258 -					}
  1.1259 -				}
  1.1260 -			}
  1.1261 -		}
  1.1262 -
  1.1263 -		private void undoMenu_Click(object sender, EventArgs e)
  1.1264 -		{
  1.1265 -			if (sender is ToolStripDropDownItem)
  1.1266 -			{
  1.1267 -				ToolStripDropDownItem item = (ToolStripDropDownItem)sender;
  1.1268 -				//we know it's an redo menu item so find it's index and redo everything					
  1.1269 -				int max = bttnUndo.DropDownItems.IndexOf(item);
  1.1270 -
  1.1271 -				if (max >= 0)
  1.1272 -				{
  1.1273 -					for (int i = 0; i <= max; i++)
  1.1274 -					{
  1.1275 -						commandStack.Undo();
  1.1276 -					}
  1.1277 -				}
  1.1278 -			}
  1.1279 -		}
  1.1280 -
  1.1281 -		private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
  1.1282 -		{
  1.1283 -			statusBar.ColorableStatusBarDrawItem(sender, sbdevent);
  1.1284 -		}
  1.1285 -
  1.1286 -		private void FrmMain_Closing(object sender, CancelEventArgs e)
  1.1287 -		{
  1.1288 -			if (!CloseCurrentArmy())
  1.1289 -			{
  1.1290 -				e.Cancel = true;
  1.1291 -			}
  1.1292 -		}
  1.1293 -
  1.1294 -		private void miReloadFiles_Click(object sender, System.EventArgs e)
  1.1295 -		{
  1.1296 -			WarFoundryLoader.GetDefault().LoadFiles();
  1.1297 -			sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded");
  1.1298 -			statusBarTimer.Enabled = true;
  1.1299 -		}
  1.1300 -
  1.1301 -		private void statusBarTimer_Tick(object sender, System.EventArgs e)
  1.1302 -		{
  1.1303 -			sbMainPanel.Text = "";
  1.1304 -			statusBarTimer.Enabled = false;
  1.1305 -		}
  1.1306 -
  1.1307 -		private void statusBar_PanelClick(object sender, StatusBarPanelClickEventArgs e)
  1.1308 -		{
  1.1309 -			if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="")
  1.1310 -			{
  1.1311 -				MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1.1312 -			}
  1.1313 -		}
  1.1314 -
  1.1315 -		private void miExportArmyAsBasicHTML_Click(object sender, EventArgs e)
  1.1316 -		{
  1.1317 -			SaveFileDialog dialog = new SaveFileDialog();
  1.1318 -			dialog.Filter = Translation.GetTranslation("armyExportBasicHtmlFilter", "HTML pages") + "|*.html";
  1.1319 -			dialog.Title = Translation.GetTranslation("exportArmyDialog", "Export army");
  1.1320 -
  1.1321 -			DialogResult dr = dialog.ShowDialog(this);
  1.1322 -
  1.1323 -			if (dr == DialogResult.OK)
  1.1324 -			{
  1.1325 -				Army army = CurrentArmy;
  1.1326 -				string filePath = dialog.FileName;
  1.1327 -				log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
  1.1328 -				WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
  1.1329 -			}
  1.1330 -		}
  1.1331 -
  1.1332 -		private void FrmMain_Load(object sender, EventArgs e)
  1.1333 -		{
  1.1334 -			string gameSystemID = Preferences.GetStringProperty("currSystem");
  1.1335 -
  1.1336 -			if (gameSystemID != null && !"".Equals(gameSystemID))
  1.1337 -			{
  1.1338 -				log.Debug("Attempting to load current game system from properties");
  1.1339 -				GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
  1.1340 -
  1.1341 -				if (sys != null)
  1.1342 -				{
  1.1343 -					WarFoundryCore.CurrentGameSystem = sys;
  1.1344 -					log.InfoFormat("Loaded game system {0} from properties", gameSystemID);
  1.1345 -				}
  1.1346 -			}
  1.1347 -		}
  1.1348 -
  1.1349 -		private void miAbout_Click(object sender, EventArgs e)
  1.1350 -		{
  1.1351 -			FrmAbout about = new FrmAbout();
  1.1352 -			about.ShowDialog(this);
  1.1353 -		}
  1.1354 -	}
  1.1355 -}
  1.1356 +// This file (FrmMain.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard.
  1.1357 +//
  1.1358 +// 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.
  1.1359 +
  1.1360 +using System;
  1.1361 +using System.Collections.Generic;
  1.1362 +using System.Drawing;
  1.1363 +using System.Drawing.Drawing2D;
  1.1364 +using System.ComponentModel;
  1.1365 +using System.Windows.Forms;
  1.1366 +using System.Data;
  1.1367 +using System.IO;
  1.1368 +using System.Threading;
  1.1369 +using log4net;
  1.1370 +using IBBoard;
  1.1371 +using IBBoard.CustomMath;
  1.1372 +using IBBoard.Commands;
  1.1373 +using IBBoard.IO;
  1.1374 +using IBBoard.Lang;
  1.1375 +using IBBoard.Windows.Forms;
  1.1376 +using IBBoard.Windows.Forms.I18N;
  1.1377 +using IBBoard.Xml;
  1.1378 +using IBBoard.WarFoundry.API;
  1.1379 +using IBBoard.WarFoundry.API.Commands;
  1.1380 +using IBBoard.WarFoundry.API.Exporters;
  1.1381 +using IBBoard.WarFoundry.API.Objects;
  1.1382 +using IBBoard.WarFoundry.API.Savers;
  1.1383 +using IBBoard.WarFoundry.API.Factories;
  1.1384 +using IBBoard.WarFoundry.API.Factories.Xml;
  1.1385 +
  1.1386 +namespace IBBoard.WarFoundry.GUI.WinForms
  1.1387 +{
  1.1388 +	/// <summary>
  1.1389 +	/// Summary description for Form1.
  1.1390 +	/// </summary>
  1.1391 +	public class FrmMain : System.Windows.Forms.Form
  1.1392 +	{
  1.1393 +		private static readonly string AppTitle = "WarFoundry";
  1.1394 +		internal static readonly string VERSION = "0.1b7";
  1.1395 +        const string DefaultDataDir = "data";
  1.1396 +
  1.1397 +		private Preferences preferences;
  1.1398 +		private readonly ILog log = LogManager.GetLogger(typeof(FrmMain));
  1.1399 +
  1.1400 +		private CommandStack commandStack;
  1.1401 +
  1.1402 +		public ObjectAddDelegate UnitAddedMethod;
  1.1403 +		public ObjectRemoveDelegate UnitRemovedMethod;
  1.1404 +		public DoubleValChangedDelegate PointsValueChangedMethod;
  1.1405 +		//public FailedUnitRequirementDelegate FailedUnitRequirementMethod;
  1.1406 +
  1.1407 +		private FrmArmyTree armyTree;
  1.1408 +		private string loadedFilePath;
  1.1409 +		private Dictionary<string, FrmUnit> unitWindows;
  1.1410 +
  1.1411 +		private System.ComponentModel.IContainer components;
  1.1412 +		private System.Windows.Forms.OpenFileDialog openArmyDialog;
  1.1413 +		private System.Windows.Forms.SaveFileDialog saveArmyDialog;
  1.1414 +		private System.Windows.Forms.MainMenu mainMenu;
  1.1415 +		private IBBoard.Windows.Forms.ColorableStatusBarPanel sbMainPanel;
  1.1416 +		private IBBoard.Windows.Forms.ColorableStatusBarPanel sbErrorPanel;
  1.1417 +		private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel;
  1.1418 +		private System.Windows.Forms.ContextMenu undoMenu;
  1.1419 +		private System.Windows.Forms.ContextMenu redoMenu;
  1.1420 +		private IBBoard.Windows.Forms.ColorableStatusBar statusBar;
  1.1421 +		private System.Windows.Forms.Timer statusBarTimer;
  1.1422 +		private MenuStrip menuStrip;
  1.1423 +		private IBBToolStripMenuItem menuFile;
  1.1424 +		private IBBToolStripMenuItem miNewArmy;
  1.1425 +		private IBBToolStripMenuItem miOpenArmy;
  1.1426 +		private IBBToolStripMenuItem miSaveArmy;
  1.1427 +		private IBBToolStripMenuItem miSaveArmyAs;
  1.1428 +		private IBBToolStripMenuItem miExportArmyAs;
  1.1429 +		private IBBToolStripMenuItem miExportArmyAsBasicHTML;
  1.1430 +		private IBBToolStripMenuItem miCloseArmy;
  1.1431 +		private ToolStripSeparator toolStripSeparator1;
  1.1432 +		private IBBToolStripMenuItem miReloadFiles;
  1.1433 +		private ToolStripSeparator toolStripSeparator2;
  1.1434 +		private IBBToolStripMenuItem miExit;
  1.1435 +		private IBBToolStripMenuItem menuEdit;
  1.1436 +		private IBBToolStripMenuItem miUndo;
  1.1437 +		private IBBToolStripMenuItem miRedo;
  1.1438 +		private IBBToolStripMenuItem menuHelp;
  1.1439 +		private ToolStrip mainToolStrip;
  1.1440 +		private IBBToolStripButton bttnNewArmy;
  1.1441 +		private IBBToolStripButton bttnOpenArmy;
  1.1442 +		private IBBToolStripButton bttnSaveArmy;
  1.1443 +		private ToolStripSeparator toolStripSeparator3;
  1.1444 +		private IBBToolStripSplitButton bttnUndo;
  1.1445 +		private IBBToolStripSplitButton bttnRedo;
  1.1446 +		private ToolStrip catToolStrip;
  1.1447 +		private ToolStripPanel toolStripPanel;
  1.1448 +		private IBBToolStripMenuItem miAbout;
  1.1449 +
  1.1450 +		/// <summary>
  1.1451 +		/// The main entry point for the application.
  1.1452 +		/// </summary>
  1.1453 +		[STAThread]
  1.1454 +		static void Main(string[] args)
  1.1455 +		{
  1.1456 +			try
  1.1457 +			{
  1.1458 +				LogManager.GetLogger(typeof(FrmMain)).Info("Starting WarFoundry WinForms");
  1.1459 +				Application.EnableVisualStyles();
  1.1460 +				Application.Run(new FrmMain(args));
  1.1461 +				LogManager.GetLogger(typeof(FrmMain)).Info("Closing WarFoundry WinForms");
  1.1462 +			}
  1.1463 +			catch (Exception ex)
  1.1464 +			{
  1.1465 +				LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
  1.1466 +				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);
  1.1467 +			}
  1.1468 +		}
  1.1469 +
  1.1470 +		public FrmMain(string[] args)
  1.1471 +		{
  1.1472 +			this.Closing+=new CancelEventHandler(FrmMain_Closing);
  1.1473 +			CommandStack.CommandStackUpdated += new MethodInvoker(commandStack_CommandStackUpdated);
  1.1474 +
  1.1475 +			InitializeComponent();
  1.1476 +			toolStripPanel.Join(mainToolStrip, 0, 0);
  1.1477 +			toolStripPanel.Join(catToolStrip, mainToolStrip.Right, 0);
  1.1478 +
  1.1479 +			Preferences = new Preferences("WarFoundry");
  1.1480 +			try
  1.1481 +			{
  1.1482 +				Translation.InitialiseTranslations(Constants.ExecutablePath, Preferences["language"].ToString());
  1.1483 +			}
  1.1484 +			catch (TranslationLoadException ex)
  1.1485 +			{
  1.1486 +				log.Error("Translation loading failed for language " + Preferences["language"].ToString(), ex);
  1.1487 +				MessageBox.Show(this, "Translation loading failed for language " + Preferences["language"].ToString(), "Translation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1.1488 +			}
  1.1489 +
  1.1490 +			ControlTranslator.TranslateControls(Controls);
  1.1491 +			ControlTranslator.TranslateComponents(components.Components);
  1.1492 +			ControlTranslator.TranslateComponent(openArmyDialog);
  1.1493 +			ControlTranslator.TranslateComponent(saveArmyDialog);
  1.1494 +			unitWindows = new Dictionary<string, FrmUnit>();
  1.1495 +
  1.1496 +			WarFoundryCore.GameSystemChanged+= new GameSystemChangedDelegate(FrmMain_GameSystemChanged);
  1.1497 +			WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(FrmMain_ArmyChanged);
  1.1498 +			UnitAddedMethod = new ObjectAddDelegate(FrmMain_UnitAddedMethod);
  1.1499 +			UnitRemovedMethod = new ObjectRemoveDelegate(FrmMain_UnitRemovedMethod);
  1.1500 +			PointsValueChangedMethod = new DoubleValChangedDelegate(FrmMain_PointsValueChangedMethod);
  1.1501 +			//FailedUnitRequirementMethod = new FailedUnitRequirementDelegate(FrmMain_FailedUnitRequirement);
  1.1502 +
  1.1503 +			sbErrorPanel.Color = Color.Red;
  1.1504 +			sbPointsPanel.ToolTipText = Translation.GetTranslation("statusPanelPointsToolTip", "total points value");
  1.1505 +
  1.1506 +			armyTree = new FrmArmyTree(CommandStack);
  1.1507 +			armyTree.MdiParent = this;
  1.1508 +			armyTree.StartPosition = FormStartPosition.Manual;
  1.1509 +			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
  1.1510 +            ControlTranslator.TranslateControl(armyTree);
  1.1511 +
  1.1512 +            // hack to load default files
  1.1513 +            WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
  1.1514 +            WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
  1.1515 +			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
  1.1516 +			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
  1.1517 +		}
  1.1518 +
  1.1519 +		public static string DataPath
  1.1520 +		{
  1.1521 +			get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; }
  1.1522 +		}
  1.1523 +
  1.1524 +		public static String ArmiesPath
  1.1525 +		{
  1.1526 +			get { return Environment.GetFolderPath(Environment.SpecialFolder.Personal); }
  1.1527 +		}
  1.1528 +
  1.1529 +		public Preferences Preferences
  1.1530 +		{
  1.1531 +			get { return preferences; }
  1.1532 +			set { preferences = value; }
  1.1533 +		}
  1.1534 +
  1.1535 +		public CommandStack CommandStack
  1.1536 +		{
  1.1537 +			get 
  1.1538 +			{
  1.1539 +				if (commandStack == null)
  1.1540 +				{					
  1.1541 +					commandStack = new CommandStack();
  1.1542 +				}
  1.1543 +
  1.1544 +				return commandStack; 
  1.1545 +			}
  1.1546 +		}
  1.1547 +
  1.1548 +		/// <summary>
  1.1549 +		/// Clean up any resources being used.
  1.1550 +		/// </summary>
  1.1551 +		protected override void Dispose( bool disposing )
  1.1552 +		{
  1.1553 +			if( disposing )
  1.1554 +			{
  1.1555 +				if (components != null) 
  1.1556 +				{
  1.1557 +					components.Dispose();
  1.1558 +				}
  1.1559 +			}
  1.1560 +			base.Dispose( disposing );
  1.1561 +		}
  1.1562 +
  1.1563 +		#region Windows Form Designer generated code
  1.1564 +		/// <summary>
  1.1565 +		/// Required method for Designer support - do not modify
  1.1566 +		/// the contents of this method with the code editor.
  1.1567 +		/// </summary>
  1.1568 +		private void InitializeComponent()
  1.1569 +		{
  1.1570 +			this.components = new System.ComponentModel.Container();
  1.1571 +			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
  1.1572 +			this.undoMenu = new System.Windows.Forms.ContextMenu();
  1.1573 +			this.redoMenu = new System.Windows.Forms.ContextMenu();
  1.1574 +			this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
  1.1575 +			this.openArmyDialog = new System.Windows.Forms.OpenFileDialog();
  1.1576 +			this.saveArmyDialog = new System.Windows.Forms.SaveFileDialog();
  1.1577 +			this.statusBarTimer = new System.Windows.Forms.Timer(this.components);
  1.1578 +			this.menuStrip = new System.Windows.Forms.MenuStrip();
  1.1579 +			this.menuFile = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1580 +			this.miNewArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1581 +			this.miOpenArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1582 +			this.miSaveArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1583 +			this.miSaveArmyAs = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1584 +			this.miExportArmyAs = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1585 +			this.miExportArmyAsBasicHTML = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1586 +			this.miCloseArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1587 +			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
  1.1588 +			this.miReloadFiles = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1589 +			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
  1.1590 +			this.miExit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1591 +			this.menuEdit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1592 +			this.miUndo = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1593 +			this.miRedo = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1594 +			this.menuHelp = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1595 +			this.miAbout = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
  1.1596 +			this.mainToolStrip = new System.Windows.Forms.ToolStrip();
  1.1597 +			this.bttnNewArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
  1.1598 +			this.bttnOpenArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
  1.1599 +			this.bttnSaveArmy = new IBBoard.Windows.Forms.IBBToolStripButton();
  1.1600 +			this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
  1.1601 +			this.bttnUndo = new IBBoard.Windows.Forms.IBBToolStripSplitButton();
  1.1602 +			this.bttnRedo = new IBBoard.Windows.Forms.IBBToolStripSplitButton();
  1.1603 +			this.catToolStrip = new System.Windows.Forms.ToolStrip();
  1.1604 +			this.statusBar = new IBBoard.Windows.Forms.ColorableStatusBar();
  1.1605 +			this.sbMainPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
  1.1606 +			this.sbErrorPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
  1.1607 +			this.sbPointsPanel = new IBBoard.Windows.Forms.ColorableStatusBarPanel();
  1.1608 +			this.toolStripPanel = new System.Windows.Forms.ToolStripPanel();
  1.1609 +			this.menuStrip.SuspendLayout();
  1.1610 +			this.mainToolStrip.SuspendLayout();
  1.1611 +			((System.ComponentModel.ISupportInitialize) (this.sbMainPanel)).BeginInit();
  1.1612 +			((System.ComponentModel.ISupportInitialize) (this.sbErrorPanel)).BeginInit();
  1.1613 +			((System.ComponentModel.ISupportInitialize) (this.sbPointsPanel)).BeginInit();
  1.1614 +			this.SuspendLayout();
  1.1615 +			// 
  1.1616 +			// saveArmyDialog
  1.1617 +			// 
  1.1618 +			this.saveArmyDialog.Title = "Translatable:saveArmyDialog";
  1.1619 +			// 
  1.1620 +			// statusBarTimer
  1.1621 +			// 
  1.1622 +			this.statusBarTimer.Interval = 5000;
  1.1623 +			this.statusBarTimer.Tick += new System.EventHandler(this.statusBarTimer_Tick);
  1.1624 +			// 
  1.1625 +			// menuStrip
  1.1626 +			// 
  1.1627 +			this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  1.1628 +            this.menuFile,
  1.1629 +            this.menuEdit,
  1.1630 +            this.menuHelp});
  1.1631 +			this.menuStrip.Location = new System.Drawing.Point(0, 0);
  1.1632 +			this.menuStrip.Name = "menuStrip";
  1.1633 +			this.menuStrip.Size = new System.Drawing.Size(790, 24);
  1.1634 +			this.menuStrip.TabIndex = 6;
  1.1635 +			this.menuStrip.Text = "menuStrip1";
  1.1636 +			// 
  1.1637 +			// menuFile
  1.1638 +			// 
  1.1639 +			this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  1.1640 +            this.miNewArmy,
  1.1641 +            this.miOpenArmy,
  1.1642 +            this.miSaveArmy,
  1.1643 +            this.miSaveArmyAs,
  1.1644 +            this.miExportArmyAs,
  1.1645 +            this.miCloseArmy,
  1.1646 +            this.toolStripSeparator1,
  1.1647 +            this.miReloadFiles,
  1.1648 +            this.toolStripSeparator2,
  1.1649 +            this.miExit});
  1.1650 +			this.menuFile.Name = "menuFile";
  1.1651 +			this.menuFile.Size = new System.Drawing.Size(33, 20);
  1.1652 +			this.menuFile.Text = "&file";
  1.1653 +			// 
  1.1654 +			// miNewArmy
  1.1655 +			// 
  1.1656 +			this.miNewArmy.Name = "miNewArmy";
  1.1657 +			this.miNewArmy.Size = new System.Drawing.Size(164, 22);
  1.1658 +			this.miNewArmy.Text = "&new army";
  1.1659 +			this.miNewArmy.Click += new System.EventHandler(this.miNewArmy_Click);
  1.1660 +			// 
  1.1661 +			// miOpenArmy
  1.1662 +			// 
  1.1663 +			this.miOpenArmy.Name = "miOpenArmy";
  1.1664 +			this.miOpenArmy.Size = new System.Drawing.Size(164, 22);
  1.1665 +			this.miOpenArmy.Text = "&open army";
  1.1666 +			this.miOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click);
  1.1667 +			// 
  1.1668 +			// miSaveArmy
  1.1669 +			// 
  1.1670 +			this.miSaveArmy.Enabled = false;
  1.1671 +			this.miSaveArmy.Name = "miSaveArmy";
  1.1672 +			this.miSaveArmy.Size = new System.Drawing.Size(164, 22);
  1.1673 +			this.miSaveArmy.Text = "&save army";
  1.1674 +			this.miSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click);
  1.1675 +			// 
  1.1676 +			// miSaveArmyAs
  1.1677 +			// 
  1.1678 +			this.miSaveArmyAs.Enabled = false;
  1.1679 +			this.miSaveArmyAs.Name = "miSaveArmyAs";
  1.1680 +			this.miSaveArmyAs.Size = new System.Drawing.Size(164, 22);
  1.1681 +			this.miSaveArmyAs.Text = "save army &as...";
  1.1682 +			this.miSaveArmyAs.Click += new System.EventHandler(this.miSaveArmyAs_Click);
  1.1683 +			// 
  1.1684 +			// miExportArmyAs
  1.1685 +			// 
  1.1686 +			this.miExportArmyAs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  1.1687 +            this.miExportArmyAsBasicHTML});
  1.1688 +			this.miExportArmyAs.Enabled = false;
  1.1689 +			this.miExportArmyAs.Name = "miExportArmyAs";
  1.1690 +			this.miExportArmyAs.Size = new System.Drawing.Size(164, 22);
  1.1691 +			this.miExportArmyAs.Text = "export army as...";
  1.1692 +			// 
  1.1693 +			// miExportArmyAsBasicHTML
  1.1694 +			// 
  1.1695 +			this.miExportArmyAsBasicHTML.Name = "miExportArmyAsBasicHTML";
  1.1696 +			this.miExportArmyAsBasicHTML.Size = new System.Drawing.Size(130, 22);
  1.1697 +			this.miExportArmyAsBasicHTML.Text = "&basic html";
  1.1698 +			this.miExportArmyAsBasicHTML.Click += new System.EventHandler(this.miExportArmyAsBasicHTML_Click);
  1.1699 +			// 
  1.1700 +			// miCloseArmy
  1.1701 +			// 
  1.1702 +			this.miCloseArmy.Enabled = false;
  1.1703 +			this.miCloseArmy.Name = "miCloseArmy";
  1.1704 +			this.miCloseArmy.Size = new System.Drawing.Size(164, 22);
  1.1705 +			this.miCloseArmy.Text = "&close army";
  1.1706 +			this.miCloseArmy.Click += new System.EventHandler(this.miCloseArmy_Click);
  1.1707 +			// 
  1.1708 +			// toolStripSeparator1
  1.1709 +			// 
  1.1710 +			this.toolStripSeparator1.Name = "toolStripSeparator1";
  1.1711 +			this.toolStripSeparator1.Size = new System.Drawing.Size(161, 6);
  1.1712 +			// 
  1.1713 +			// miReloadFiles
  1.1714 +			// 
  1.1715 +			this.miReloadFiles.Name = "miReloadFiles";
  1.1716 +			this.miReloadFiles.Size = new System.Drawing.Size(164, 22);
  1.1717 +			this.miReloadFiles.Text = "&reload files";
  1.1718 +			this.miReloadFiles.Click += new System.EventHandler(this.miReloadFiles_Click);
  1.1719 +			// 
  1.1720 +			// toolStripSeparator2
  1.1721 +			// 
  1.1722 +			this.toolStripSeparator2.Name = "toolStripSeparator2";
  1.1723 +			this.toolStripSeparator2.Size = new System.Drawing.Size(161, 6);
  1.1724 +			// 
  1.1725 +			// miExit
  1.1726 +			// 
  1.1727 +			this.miExit.Name = "miExit";
  1.1728 +			this.miExit.Size = new System.Drawing.Size(164, 22);
  1.1729 +			this.miExit.Text = "e&xit";
  1.1730 +			this.miExit.Click += new System.EventHandler(this.miExit_Click);
  1.1731 +			// 
  1.1732 +			// menuEdit
  1.1733 +			// 
  1.1734 +			this.menuEdit.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  1.1735 +            this.miUndo,
  1.1736 +            this.miRedo});
  1.1737 +			this.menuEdit.Name = "menuEdit";
  1.1738 +			this.menuEdit.Size = new System.Drawing.Size(36, 20);
  1.1739 +			this.menuEdit.Text = "&edit";
  1.1740 +			// 
  1.1741 +			// miUndo
  1.1742 +			// 
  1.1743 +			this.miUndo.Enabled = false;
  1.1744 +			this.miUndo.Name = "miUndo";
  1.1745 +			this.miUndo.Size = new System.Drawing.Size(106, 22);
  1.1746 +			this.miUndo.Text = "&undo";
  1.1747 +			this.miUndo.Click += new System.EventHandler(this.miUndo_Click);
  1.1748 +			// 
  1.1749 +			// miRedo
  1.1750 +			// 
  1.1751 +			this.miRedo.Enabled = false;
  1.1752 +			this.miRedo.Name = "miRedo";
  1.1753 +			this.miRedo.Size = new System.Drawing.Size(106, 22);
  1.1754 +			this.miRedo.Text = "&redo";
  1.1755 +			this.miRedo.Click += new System.EventHandler(this.miRedo_Click);
  1.1756 +			// 
  1.1757 +			// menuHelp
  1.1758 +			// 
  1.1759 +			this.menuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  1.1760 +            this.miAbout});
  1.1761 +			this.menuHelp.Name = "menuHelp";
  1.1762 +			this.menuHelp.Size = new System.Drawing.Size(39, 20);
  1.1763 +			this.menuHelp.Text = "&help";
  1.1764 +			// 
  1.1765 +			// miAbout
  1.1766 +			// 
  1.1767 +			this.miAbout.Name = "miAbout";
  1.1768 +			this.miAbout.Size = new System.Drawing.Size(109, 22);
  1.1769 +			this.miAbout.Text = "&about";
  1.1770 +			this.miAbout.Click += new System.EventHandler(this.miAbout_Click);
  1.1771 +			// 
  1.1772 +			// mainToolStrip
  1.1773 +			// 
  1.1774 +			this.mainToolStrip.Dock = System.Windows.Forms.DockStyle.None;
  1.1775 +			this.mainToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  1.1776 +            this.bttnNewArmy,
  1.1777 +            this.bttnOpenArmy,
  1.1778 +            this.bttnSaveArmy,
  1.1779 +            this.toolStripSeparator3,
  1.1780 +            this.bttnUndo,
  1.1781 +            this.bttnRedo});
  1.1782 +			this.mainToolStrip.Location = new System.Drawing.Point(0, 24);
  1.1783 +			this.mainToolStrip.Name = "mainToolStrip";
  1.1784 +			this.mainToolStrip.Size = new System.Drawing.Size(182, 25);
  1.1785 +			this.mainToolStrip.TabIndex = 8;
  1.1786 +			// 
  1.1787 +			// bttnNewArmy
  1.1788 +			// 
  1.1789 +			this.bttnNewArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  1.1790 +			this.bttnNewArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_new;
  1.1791 +			this.bttnNewArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
  1.1792 +			this.bttnNewArmy.Name = "bttnNewArmy";
  1.1793 +			this.bttnNewArmy.Size = new System.Drawing.Size(23, 22);
  1.1794 +			this.bttnNewArmy.Text = "new army";
  1.1795 +			this.bttnNewArmy.Click += new System.EventHandler(this.miNewArmy_Click);
  1.1796 +			// 
  1.1797 +			// bttnOpenArmy
  1.1798 +			// 
  1.1799 +			this.bttnOpenArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  1.1800 +			this.bttnOpenArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_open;
  1.1801 +			this.bttnOpenArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
  1.1802 +			this.bttnOpenArmy.Name = "bttnOpenArmy";
  1.1803 +			this.bttnOpenArmy.Size = new System.Drawing.Size(23, 22);
  1.1804 +			this.bttnOpenArmy.Text = "open army";
  1.1805 +			this.bttnOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click);
  1.1806 +			// 
  1.1807 +			// bttnSaveArmy
  1.1808 +			// 
  1.1809 +			this.bttnSaveArmy.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  1.1810 +			this.bttnSaveArmy.Enabled = false;
  1.1811 +			this.bttnSaveArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.document_save;
  1.1812 +			this.bttnSaveArmy.ImageTransparentColor = System.Drawing.Color.Magenta;
  1.1813 +			this.bttnSaveArmy.Name = "bttnSaveArmy";
  1.1814 +			this.bttnSaveArmy.Size = new System.Drawing.Size(23, 22);
  1.1815 +			this.bttnSaveArmy.Text = "save army";
  1.1816 +			this.bttnSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click);
  1.1817 +			// 
  1.1818 +			// toolStripSeparator3
  1.1819 +			// 
  1.1820 +			this.toolStripSeparator3.Name = "toolStripSeparator3";
  1.1821 +			this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
  1.1822 +			// 
  1.1823 +			// bttnUndo
  1.1824 +			// 
  1.1825 +			this.bttnUndo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  1.1826 +			this.bttnUndo.Enabled = false;
  1.1827 +			this.bttnUndo.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_undo;
  1.1828 +			this.bttnUndo.ImageTransparentColor = System.Drawing.Color.Magenta;
  1.1829 +			this.bttnUndo.Name = "bttnUndo";
  1.1830 +			this.bttnUndo.Size = new System.Drawing.Size(32, 22);
  1.1831 +			this.bttnUndo.Text = "undo";
  1.1832 +			this.bttnUndo.ButtonClick += new System.EventHandler(this.miUndo_Click);
  1.1833 +			// 
  1.1834 +			// bttnRedo
  1.1835 +			// 
  1.1836 +			this.bttnRedo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  1.1837 +			this.bttnRedo.Enabled = false;
  1.1838 +			this.bttnRedo.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_redo;
  1.1839 +			this.bttnRedo.ImageTransparentColor = System.Drawing.Color.Magenta;
  1.1840 +			this.bttnRedo.Name = "bttnRedo";
  1.1841 +			this.bttnRedo.Size = new System.Drawing.Size(32, 22);
  1.1842 +			this.bttnRedo.Text = "redo";
  1.1843 +			this.bttnRedo.ButtonClick += new System.EventHandler(this.miRedo_Click);
  1.1844 +			// 
  1.1845 +			// catToolStrip
  1.1846 +			// 
  1.1847 +			this.catToolStrip.Dock = System.Windows.Forms.DockStyle.None;
  1.1848 +			this.catToolStrip.Location = new System.Drawing.Point(161, 24);
  1.1849 +			this.catToolStrip.Name = "catToolStrip";
  1.1850 +			this.catToolStrip.Size = new System.Drawing.Size(111, 25);
  1.1851 +			this.catToolStrip.TabIndex = 9;
  1.1852 +			this.catToolStrip.Visible = false;
  1.1853 +			// 
  1.1854 +			// statusBar
  1.1855 +			// 
  1.1856 +			this.statusBar.Location = new System.Drawing.Point(0, 586);
  1.1857 +			this.statusBar.Name = "statusBar";
  1.1858 +			this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
  1.1859 +            this.sbMainPanel,
  1.1860 +            this.sbErrorPanel,
  1.1861 +            this.sbPointsPanel});
  1.1862 +			this.statusBar.ShowPanels = true;
  1.1863 +			this.statusBar.Size = new System.Drawing.Size(790, 22);
  1.1864 +			this.statusBar.TabIndex = 1;
  1.1865 +			this.statusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar_PanelClick);
  1.1866 +			this.statusBar.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem);
  1.1867 +			// 
  1.1868 +			// sbMainPanel
  1.1869 +			// 
  1.1870 +			this.sbMainPanel.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
  1.1871 +			this.sbMainPanel.Color = System.Drawing.SystemColors.WindowText;
  1.1872 +			this.sbMainPanel.Name = "sbMainPanel";
  1.1873 +			this.sbMainPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
  1.1874 +			this.sbMainPanel.Width = 473;
  1.1875 +			// 
  1.1876 +			// sbErrorPanel
  1.1877 +			// 
  1.1878 +			this.sbErrorPanel.Color = System.Drawing.SystemColors.WindowText;
  1.1879 +			this.sbErrorPanel.Name = "sbErrorPanel";
  1.1880 +			this.sbErrorPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
  1.1881 +			this.sbErrorPanel.Width = 150;
  1.1882 +			// 
  1.1883 +			// sbPointsPanel
  1.1884 +			// 
  1.1885 +			this.sbPointsPanel.Color = System.Drawing.SystemColors.WindowText;
  1.1886 +			this.sbPointsPanel.Name = "sbPointsPanel";
  1.1887 +			this.sbPointsPanel.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
  1.1888 +			this.sbPointsPanel.ToolTipText = "current points total";
  1.1889 +			this.sbPointsPanel.Width = 150;
  1.1890 +			// 
  1.1891 +			// toolStripPanel
  1.1892 +			// 
  1.1893 +			this.toolStripPanel.Dock = System.Windows.Forms.DockStyle.Top;
  1.1894 +			this.toolStripPanel.Location = new System.Drawing.Point(0, 24);
  1.1895 +			this.toolStripPanel.Name = "toolStripPanel";
  1.1896 +			this.toolStripPanel.Orientation = System.Windows.Forms.Orientation.Horizontal;
  1.1897 +			this.toolStripPanel.RowMargin = new System.Windows.Forms.Padding(3, 0, 0, 0);
  1.1898 +			this.toolStripPanel.Size = new System.Drawing.Size(790, 0);
  1.1899 +			// 
  1.1900 +			// FrmMain
  1.1901 +			// 
  1.1902 +			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  1.1903 +			this.ClientSize = new System.Drawing.Size(790, 608);
  1.1904 +			this.Controls.Add(this.mainToolStrip);
  1.1905 +			this.Controls.Add(this.toolStripPanel);
  1.1906 +			this.Controls.Add(this.statusBar);
  1.1907 +			this.Controls.Add(this.catToolStrip);
  1.1908 +			this.Controls.Add(this.menuStrip);
  1.1909 +			this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
  1.1910 +			this.IsMdiContainer = true;
  1.1911 +			this.MainMenuStrip = this.menuStrip;
  1.1912 +			this.Menu = this.mainMenu;
  1.1913 +			this.Name = "FrmMain";
  1.1914 +			this.Text = "WarFoundry";
  1.1915 +			this.Load += new System.EventHandler(this.FrmMain_Load);
  1.1916 +			this.menuStrip.ResumeLayout(false);
  1.1917 +			this.menuStrip.PerformLayout();
  1.1918 +			this.mainToolStrip.ResumeLayout(false);
  1.1919 +			this.mainToolStrip.PerformLayout();
  1.1920 +			((System.ComponentModel.ISupportInitialize) (this.sbMainPanel)).EndInit();
  1.1921 +			((System.ComponentModel.ISupportInitialize) (this.sbErrorPanel)).EndInit();
  1.1922 +			((System.ComponentModel.ISupportInitialize) (this.sbPointsPanel)).EndInit();
  1.1923 +			this.ResumeLayout(false);
  1.1924 +			this.PerformLayout();
  1.1925 +
  1.1926 +		}
  1.1927 +		#endregion
  1.1928 +
  1.1929 +		private void FileLoadingFinished(List<FileLoadFailure> failures)
  1.1930 +		{
  1.1931 +			foreach (FileLoadFailure failure in failures)
  1.1932 +			{
  1.1933 +				log.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
  1.1934 +			}
  1.1935 +		}
  1.1936 +
  1.1937 +		private void miExit_Click(object sender, System.EventArgs e)
  1.1938 +		{
  1.1939 +			Application.Exit();
  1.1940 +		}
  1.1941 +
  1.1942 +		private void miNewArmy_Click(object sender, System.EventArgs e)
  1.1943 +		{
  1.1944 +			CreateNewArmy();
  1.1945 +		}
  1.1946 +
  1.1947 +		private void CreateNewArmy()
  1.1948 +		{
  1.1949 +			if (CloseCurrentArmy())
  1.1950 +			{
  1.1951 +				FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem);
  1.1952 +				DialogResult dr = newArmy.ShowDialog();
  1.1953 +
  1.1954 +				if (dr == DialogResult.OK)
  1.1955 +				{
  1.1956 +					try
  1.1957 +					{
  1.1958 +						CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize);
  1.1959 +					}
  1.1960 +					catch (RequiredDataMissingException ex)
  1.1961 +					{
  1.1962 +						log.Error("Required data missing from race file", ex);
  1.1963 +						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  1.1964 +					}
  1.1965 +					catch (InvalidFileException ex)
  1.1966 +					{
  1.1967 +						log.Error("Race file was invalid", ex);
  1.1968 +						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidRaceFileBoxTitle", "invalid race file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  1.1969 +					}
  1.1970 +				}
  1.1971 +			}
  1.1972 +		}
  1.1973 +
  1.1974 +		private bool OpenArmy()
  1.1975 +		{
  1.1976 +			if (openArmyDialog.Filter=="")
  1.1977 +			{
  1.1978 +				string savePath = ArmiesPath;
  1.1979 +			
  1.1980 +				if (!Directory.Exists(savePath))
  1.1981 +				{
  1.1982 +					Directory.CreateDirectory(savePath);
  1.1983 +				}
  1.1984 +
  1.1985 +				openArmyDialog.InitialDirectory = savePath;
  1.1986 +				openArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
  1.1987 +				openArmyDialog.Title = Translation.GetTranslation("openArmyDialog");
  1.1988 +
  1.1989 +			}
  1.1990 +
  1.1991 +			DialogResult dr = openArmyDialog.ShowDialog(this);
  1.1992 +
  1.1993 +			if (dr == DialogResult.OK)
  1.1994 +			{
  1.1995 +				if (CloseCurrentArmy())
  1.1996 +				{
  1.1997 +					try
  1.1998 +					{
  1.1999 +						string newFilePath = openArmyDialog.FileName;
  1.2000 +						CurrentArmy = WarFoundryLoader.GetDefault().LoadArmy(new FileInfo(newFilePath));
  1.2001 +						loadedFilePath = newFilePath;
  1.2002 +						return true;
  1.2003 +					}
  1.2004 +					catch (RequiredDataMissingException ex)
  1.2005 +					{
  1.2006 +						log.Error(ex);
  1.2007 +						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  1.2008 +						return false;
  1.2009 +					}
  1.2010 +					catch (InvalidFileException ex)
  1.2011 +					{
  1.2012 +						log.Error(ex);
  1.2013 +						MessageBox.Show(this, ex.Message, Translation.GetTranslation("InvalidArmyFileBoxTitle", "invalid army file"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  1.2014 +						return false;
  1.2015 +					}
  1.2016 +				}
  1.2017 +				else
  1.2018 +				{
  1.2019 +					return false;
  1.2020 +				}
  1.2021 +			}
  1.2022 +			else
  1.2023 +			{
  1.2024 +				return false;
  1.2025 +			}
  1.2026 +		}
  1.2027 +
  1.2028 +		private bool CloseCurrentArmy()
  1.2029 +		{
  1.2030 +			if (CurrentArmy!=null)
  1.2031 +			{
  1.2032 +				bool canClose = false;
  1.2033 +
  1.2034 +				if (CommandStack.IsDirty())
  1.2035 +				{
  1.2036 +					string saveChanges = Translation.GetTranslation("SaveChangesQuestion", "the army \"{0}\" has been modified\r\nsave changes before closing army?", CurrentArmy.Name);
  1.2037 +					string saveChangesTitle = Translation.GetTranslation("SaveChangesTitle", "unsaved changes");
  1.2038 +					DialogResult dr = MessageBox.Show(this, saveChanges, saveChangesTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3);
  1.2039 +
  1.2040 +					if (dr == DialogResult.Yes)
  1.2041 +					{
  1.2042 +						canClose = SaveCurrentArmy();
  1.2043 +					}
  1.2044 +					else if (dr == DialogResult.No)
  1.2045 +					{
  1.2046 +						canClose = true;
  1.2047 +					}
  1.2048 +					//else they said cancel and we default to "canClose = false" so do nothing
  1.2049 +				}
  1.2050 +				else
  1.2051 +				{
  1.2052 +					canClose = true;
  1.2053 +				}
  1.2054 +
  1.2055 +				if (canClose)
  1.2056 +				{
  1.2057 +					//do close
  1.2058 +					DisableCategoryButtons();
  1.2059 +					CurrentArmy = null;
  1.2060 +					return true;
  1.2061 +				}
  1.2062 +				else
  1.2063 +				{
  1.2064 +					return false;
  1.2065 +				}
  1.2066 +			}
  1.2067 +			else
  1.2068 +			{
  1.2069 +				DisableCategoryButtons();
  1.2070 +				//pretend we succeeded
  1.2071 +				return true;
  1.2072 +			}
  1.2073 +		}
  1.2074 +
  1.2075 +		private void UndoLastAction()
  1.2076 +		{
  1.2077 +			if (commandStack.CanUndo())
  1.2078 +			{
  1.2079 +				commandStack.Undo();
  1.2080 +			}
  1.2081 +		}
  1.2082 +
  1.2083 +		private void RedoAction()
  1.2084 +		{
  1.2085 +			if (commandStack.CanRedo())
  1.2086 +			{
  1.2087 +				commandStack.Redo();
  1.2088 +			}
  1.2089 +		}
  1.2090 +
  1.2091 +		private bool SaveCurrentArmy()
  1.2092 +		{
  1.2093 +			bool saved = false;
  1.2094 +
  1.2095 +			string filePath = loadedFilePath;
  1.2096 +
  1.2097 +			if (filePath == null)
  1.2098 +			{
  1.2099 +				filePath = PromptForArmyFilePath();
  1.2100 +			}
  1.2101 +
  1.2102 +			if (filePath != null)
  1.2103 +			{
  1.2104 +				saved = SaveCurrentArmyToFile(filePath);
  1.2105 +			}
  1.2106 +
  1.2107 +			return saved;
  1.2108 +		}
  1.2109 +
  1.2110 +		private bool SaveCurrentArmyAs()
  1.2111 +		{
  1.2112 +			bool saved = false;
  1.2113 +			string filePath = PromptForArmyFilePath();
  1.2114 +
  1.2115 +			if (filePath != null)
  1.2116 +			{
  1.2117 +				saved = SaveCurrentArmyToFile(filePath);
  1.2118 +			}
  1.2119 +			
  1.2120 +			return saved;
  1.2121 +		}
  1.2122 +
  1.2123 +		private bool SaveCurrentArmyToFile(string filePath)
  1.2124 +		{
  1.2125 +			if (WarFoundrySaver.GetSaver().Save(CurrentArmy, filePath))
  1.2126 +			{
  1.2127 +				loadedFilePath = filePath;
  1.2128 +				miSaveArmy.Enabled = false;
  1.2129 +				bttnSaveArmy.Enabled = false;
  1.2130 +				CommandStack.setCleanMark();
  1.2131 +				return true;
  1.2132 +			}
  1.2133 +			else
  1.2134 +			{
  1.2135 +				MessageBox.Show(this, Translation.GetTranslation("SaveFailed", "file save failed - check log for details"), Translation.GetTranslation("SaveFailedTitle", "file save failed"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  1.2136 +				return false;
  1.2137 +			}
  1.2138 +		}
  1.2139 +
  1.2140 +		private string PromptForArmyFilePath()
  1.2141 +		{
  1.2142 +			if (saveArmyDialog.Filter == "")
  1.2143 +			{
  1.2144 +				string savePath = ArmiesPath;
  1.2145 +				
  1.2146 +				if (!Directory.Exists(savePath))
  1.2147 +				{
  1.2148 +					Directory.CreateDirectory(savePath);
  1.2149 +				}
  1.2150 +
  1.2151 +				saveArmyDialog.InitialDirectory = savePath;
  1.2152 +				saveArmyDialog.Filter = Translation.GetTranslation("armyFileFilter")+"|*.army";
  1.2153 +				saveArmyDialog.Title = Translation.GetTranslation("saveArmyDialog");
  1.2154 +			}
  1.2155 +
  1.2156 +			DialogResult dr = saveArmyDialog.ShowDialog(this);
  1.2157 +
  1.2158 +			if (dr == DialogResult.OK)
  1.2159 +			{
  1.2160 +				return saveArmyDialog.FileName;
  1.2161 +			}
  1.2162 +			else
  1.2163 +			{
  1.2164 +				return null;
  1.2165 +			}
  1.2166 +		}
  1.2167 +
  1.2168 +		public GameSystem CurrentGameSystem
  1.2169 +		{
  1.2170 +			get { return WarFoundryCore.CurrentGameSystem; }
  1.2171 +			set { WarFoundryCore.CurrentGameSystem = value; }
  1.2172 +		}
  1.2173 +
  1.2174 +		public Army CurrentArmy
  1.2175 +		{
  1.2176 +			get { return WarFoundryCore.CurrentArmy; }
  1.2177 +			set { SetArmy(value); }
  1.2178 +		}
  1.2179 +
  1.2180 +		private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem)
  1.2181 +		{
  1.2182 +			SetAppTitle();
  1.2183 +			RemoveCategoryButtons();
  1.2184 +		}
  1.2185 +
  1.2186 +		private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy)
  1.2187 +		{
  1.2188 +			CommandStack.Reset();
  1.2189 +			loadedFilePath = null;
  1.2190 +			miSaveArmy.Enabled = false;
  1.2191 +			bttnSaveArmy.Enabled = false;
  1.2192 +			SetPointsPanelText();
  1.2193 +			SetAppTitle();
  1.2194 +		}
  1.2195 +
  1.2196 +		private void SetArmy(Army newArmy)
  1.2197 +		{
  1.2198 +			IgnoreArmy(CurrentArmy);
  1.2199 +			CloseAllUnitWindows();
  1.2200 +
  1.2201 +			if (newArmy == null)
  1.2202 +			{
  1.2203 +				SetNullArmyState();
  1.2204 +			}
  1.2205 +			else
  1.2206 +			{
  1.2207 +				WarFoundryCore.CurrentGameSystem = newArmy.GameSystem;
  1.2208 +				ListenToArmy(newArmy);
  1.2209 +				SetNonNullArmyState(newArmy);
  1.2210 +			}
  1.2211 +			
  1.2212 +			WarFoundryCore.CurrentArmy = newArmy;
  1.2213 +		}
  1.2214 +
  1.2215 +		private void IgnoreArmy(Army oldArmy)
  1.2216 +		{
  1.2217 +			if (oldArmy != null)
  1.2218 +			{
  1.2219 +				oldArmy.UnitAdded -= UnitAddedMethod;
  1.2220 +				oldArmy.UnitRemoved -= UnitRemovedMethod;
  1.2221 +				oldArmy.PointsValueChanged -= PointsValueChangedMethod;
  1.2222 +			}
  1.2223 +		}
  1.2224 +
  1.2225 +		private void CloseAllUnitWindows()
  1.2226 +		{
  1.2227 +			FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows);
  1.2228 +
  1.2229 +			foreach (FrmUnit window in unitForms)
  1.2230 +			{
  1.2231 +				window.Close();
  1.2232 +			}
  1.2233 +
  1.2234 +			unitWindows.Clear();
  1.2235 +		}
  1.2236 +
  1.2237 +		private void ListenToArmy(Army newArmy)
  1.2238 +		{
  1.2239 +			if (newArmy != null)
  1.2240 +			{
  1.2241 +				newArmy.UnitAdded += UnitAddedMethod;
  1.2242 +				newArmy.UnitRemoved += UnitRemovedMethod;
  1.2243 +				newArmy.PointsValueChanged += PointsValueChangedMethod;
  1.2244 +			}
  1.2245 +		}
  1.2246 +
  1.2247 +		private void SetNullArmyState()
  1.2248 +		{
  1.2249 +			miSaveArmyAs.Enabled = false;
  1.2250 +			miCloseArmy.Enabled = false;
  1.2251 +			miExportArmyAs.Enabled = false;
  1.2252 +			DisableCategoryButtons();
  1.2253 +			armyTree.Hide();
  1.2254 +		}
  1.2255 +
  1.2256 +		private void SetNonNullArmyState(Army newArmy)
  1.2257 +		{
  1.2258 +			SetCategoryButtons(newArmy.Race.Categories);
  1.2259 +			EnableCategoryButtons();
  1.2260 +			miSaveArmyAs.Enabled = true;
  1.2261 +			miCloseArmy.Enabled = true;
  1.2262 +			miExportArmyAs.Enabled = true;
  1.2263 +			armyTree.Show();
  1.2264 +		}
  1.2265 +
  1.2266 +		private void SetCategoryButtons(Category[] cats)
  1.2267 +		{
  1.2268 +			if (CategoryButtonsHaveChanged(cats))
  1.2269 +			{
  1.2270 +				RemoveCategoryButtons();
  1.2271 +				AddCategoryButtons(cats);
  1.2272 +			}
  1.2273 +		}
  1.2274 +
  1.2275 +		private bool CategoryButtonsHaveChanged(Category[] cats)
  1.2276 +		{
  1.2277 +			int catCount = cats.Length;
  1.2278 +			ToolStripItemCollection items = catToolStrip.Items;
  1.2279 +			bool haveChanged = (!catToolStrip.Visible || catCount != items.Count);
  1.2280 +
  1.2281 +			if (!haveChanged)
  1.2282 +			{
  1.2283 +				for (int i = 0; i < catCount; i++)
  1.2284 +				{
  1.2285 +					if (cats[i].Equals(items[i+1].Tag))
  1.2286 +					{
  1.2287 +						haveChanged = true;
  1.2288 +						break;
  1.2289 +					}
  1.2290 +				}
  1.2291 +			}
  1.2292 +
  1.2293 +			return haveChanged;
  1.2294 +		}
  1.2295 +
  1.2296 +		private void RemoveCategoryButtons()
  1.2297 +		{
  1.2298 +			this.Invoke(new MethodInvoker(catToolStrip.Items.Clear));
  1.2299 +		}
  1.2300 +
  1.2301 +		private void AddCategoryButtons(Category[] cats)
  1.2302 +		{
  1.2303 +			int catCount = cats.Length;
  1.2304 +			Category cat;
  1.2305 +			IBBToolStripButton[] categoryButtons = new IBBToolStripButton[catCount];
  1.2306 +
  1.2307 +			for (int i = 0; i < catCount; i++)
  1.2308 +			{
  1.2309 +				cat = cats[i];
  1.2310 +				IBBToolStripButton button = new IBBToolStripButton();
  1.2311 +				button.Text = cat.Name;
  1.2312 +				button.Tag = cat;
  1.2313 +				button.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
  1.2314 +				button.Enabled = false;
  1.2315 +				button.Click += new EventHandler(CreateUnitForCategoryButtonClick);
  1.2316 +				categoryButtons[i] = button;
  1.2317 +			}
  1.2318 +
  1.2319 +			this.Invoke(new ArrayMethodInvoker<IBBToolStripButton>(catToolStrip.Items.AddRange), new object[]{ categoryButtons });
  1.2320 +		}
  1.2321 +
  1.2322 +		private void CreateUnitForCategoryButtonClick(object sender, EventArgs e)
  1.2323 +		{
  1.2324 +			if (sender is IBBToolStripButton)
  1.2325 +			{
  1.2326 +				IBBToolStripButton button = (IBBToolStripButton)sender;
  1.2327 +				object tag = button.Tag;
  1.2328 +
  1.2329 +				if (tag is Category)
  1.2330 +				{
  1.2331 +					AddUnitFromCategory((Category)tag);
  1.2332 +				}
  1.2333 +			}
  1.2334 +		}
  1.2335 +
  1.2336 +		private void EnableCategoryButtons()
  1.2337 +		{
  1.2338 +			catToolStrip.Visible = true;
  1.2339 +			SetCategoryButtonState(true);
  1.2340 +		}
  1.2341 +
  1.2342 +		private void DisableCategoryButtons()
  1.2343 +		{
  1.2344 +			catToolStrip.Visible = false;
  1.2345 +			SetCategoryButtonState(false);
  1.2346 +		}
  1.2347 +
  1.2348 +		private void SetCategoryButtonState(bool state)
  1.2349 +		{
  1.2350 +			foreach (IBBToolStripButton button in catToolStrip.Items)
  1.2351 +			{
  1.2352 +				button.Enabled = state;
  1.2353 +			}
  1.2354 +		}
  1.2355 +
  1.2356 +		private void miSaveArmyAs_Click(object sender, System.EventArgs e)
  1.2357 +		{
  1.2358 +			SaveCurrentArmyAs();
  1.2359 +		}
  1.2360 +
  1.2361 +		private void commandStack_CommandStackUpdated()
  1.2362 +		{
  1.2363 +			bttnUndo.Enabled = commandStack.CanUndo();
  1.2364 +			miUndo.Enabled = bttnUndo.Enabled;
  1.2365 +			bttnRedo.Enabled = commandStack.CanRedo();
  1.2366 +			miRedo.Enabled = bttnRedo.Enabled;
  1.2367 +
  1.2368 +			PopulateRedoMenu();
  1.2369 +			PopulateUndoMenu();
  1.2370 +
  1.2371 +			bttnSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null;
  1.2372 +			miSaveArmy.Enabled = commandStack.IsDirty() && CurrentArmy!=null;
  1.2373 +		}
  1.2374 +
  1.2375 +		private void PopulateRedoMenu()
  1.2376 +		{
  1.2377 +			int redoLength = commandStack.RedoLength;
  1.2378 +			int maxRedo = Math.Min(10, redoLength);
  1.2379 +			ToolStripItemCollection dropDownItems = bttnRedo.DropDownItems;
  1.2380 +			dropDownItems.Clear();
  1.2381 +
  1.2382 +			for (int i = 1; i <= maxRedo; i++)
  1.2383 +			{
  1.2384 +				Command cmd = commandStack.PeekRedoCommand(i);
  1.2385 +
  1.2386 +				if (cmd == null)
  1.2387 +				{
  1.2388 +					break;
  1.2389 +				}
  1.2390 +
  1.2391 +				dropDownItems.Add(cmd.Description, null, redoMenu_Click);
  1.2392 +			}
  1.2393 +
  1.2394 +			if (redoLength > 0)
  1.2395 +			{
  1.2396 +				bttnRedo.Text = commandStack.PeekRedoCommand(1).Description;
  1.2397 +			}
  1.2398 +			else
  1.2399 +			{
  1.2400 +				bttnRedo.Text = Translation.GetTranslation("bttnRedo");
  1.2401 +			}
  1.2402 +		}
  1.2403 +
  1.2404 +		private void PopulateUndoMenu()
  1.2405 +		{
  1.2406 +			int undoLength = commandStack.UndoLength;
  1.2407 +			int maxUndo = Math.Min(10, undoLength);
  1.2408 +			ToolStripItemCollection dropDownItems = bttnUndo.DropDownItems;
  1.2409 +			dropDownItems.Clear();
  1.2410 +
  1.2411 +			for (int i = 1; i <= maxUndo; i++)
  1.2412 +			{
  1.2413 +				Command cmd = commandStack.PeekUndoCommand(i);
  1.2414 +
  1.2415 +				if (cmd == null)
  1.2416 +				{
  1.2417 +					break;
  1.2418 +				}
  1.2419 +
  1.2420 +				dropDownItems.Add(cmd.UndoDescription, null, undoMenu_Click);
  1.2421 +			}
  1.2422 +
  1.2423 +			if (undoLength > 0)
  1.2424 +			{
  1.2425 +				bttnUndo.Text = commandStack.PeekUndoCommand(1).UndoDescription;
  1.2426 +			}
  1.2427 +			else
  1.2428 +			{
  1.2429 +				bttnUndo.Text = Translation.GetTranslation("bttnUndo");
  1.2430 +			}
  1.2431 +		}
  1.2432 +
  1.2433 +		private void miSaveArmy_Click(object sender, System.EventArgs e)
  1.2434 +		{
  1.2435 +			SaveCurrentArmy();
  1.2436 +		}
  1.2437 +
  1.2438 +		private void SetAppTitle()
  1.2439 +		{
  1.2440 +			string str = AppTitle;
  1.2441 +
  1.2442 +			if (CurrentGameSystem!=null)
  1.2443 +			{
  1.2444 +				str+= " - "+CurrentGameSystem.Name;
  1.2445 +			}
  1.2446 +
  1.2447 +			if (CurrentArmy!=null)
  1.2448 +			{
  1.2449 +				str+= " - "+CurrentArmy.Name;
  1.2450 +			}
  1.2451 +
  1.2452 +			this.Text = str;
  1.2453 +		}
  1.2454 +
  1.2455 +		private void AddUnitFromCategory(Category cat)
  1.2456 +		{
  1.2457 +			FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy);
  1.2458 +			DialogResult dr = newUnit.ShowDialog(this);
  1.2459 +
  1.2460 +			if (dr == DialogResult.OK)
  1.2461 +			{
  1.2462 +				CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat));
  1.2463 +				commandStack.Execute(cmd);
  1.2464 +				OpenUnitDialog(cmd.Unit);
  1.2465 +			}
  1.2466 +		}
  1.2467 +
  1.2468 +		internal void OpenUnitDialog(Unit unit)
  1.2469 +		{
  1.2470 +			string unitID = unit.ID;
  1.2471 +
  1.2472 +			if (unitWindows.ContainsKey(unitID))
  1.2473 +			{
  1.2474 +				unitWindows[unitID].Focus();
  1.2475 +			}
  1.2476 +			else
  1.2477 +			{
  1.2478 +				FrmUnit unitForm = new FrmUnit(unit, commandStack);
  1.2479 +				unitWindows.Add(unitID, unitForm);
  1.2480 +				unitForm.MdiParent = this;
  1.2481 +				unitForm.Closing += new CancelEventHandler(unitForm_Closing);
  1.2482 +				unitForm.Show();
  1.2483 +			}
  1.2484 +		}
  1.2485 +
  1.2486 +		private void unitForm_Closing(object sender, CancelEventArgs e)
  1.2487 +		{
  1.2488 +			if (sender is FrmUnit)
  1.2489 +			{
  1.2490 +				FrmUnit unitForm = (FrmUnit) sender;
  1.2491 +				unitWindows.Remove(unitForm.Unit.ID);
  1.2492 +			}
  1.2493 +		}
  1.2494 +
  1.2495 +		private void FrmMain_UnitAddedMethod(object unitObj)
  1.2496 +		{
  1.2497 +			if (unitObj is Unit)
  1.2498 +			{
  1.2499 +				Unit unit = (Unit)unitObj;
  1.2500 +				sbErrorPanel.Text = "";
  1.2501 +			}
  1.2502 +		}
  1.2503 +
  1.2504 +		private void FrmMain_UnitRemovedMethod(object unitObj)
  1.2505 +		{
  1.2506 +			if (unitObj is Unit)
  1.2507 +			{
  1.2508 +				Unit unit = (Unit)unitObj;
  1.2509 +				sbErrorPanel.Text = "";
  1.2510 +
  1.2511 +				//check if window is open, and close it if it is
  1.2512 +				foreach (Form frm in this.MdiChildren)
  1.2513 +				{
  1.2514 +					if (frm is FrmUnit)
  1.2515 +					{
  1.2516 +						if (((FrmUnit)frm).Unit == unit)
  1.2517 +						{
  1.2518 +							frm.Close();
  1.2519 +							break;
  1.2520 +						}
  1.2521 +					}
  1.2522 +				}
  1.2523 +			}
  1.2524 +		}
  1.2525 +
  1.2526 +		/*private void FrmMain_FailedUnitRequirement(FailedUnitRequirement failedRequirement)
  1.2527 +		{
  1.2528 +			sbErrorPanel.Text = Translation.GetTranslation("UnitRequirementFailed", "Unit Requirement Failed");
  1.2529 +			sbErrorPanel.Tag = failedRequirement.Description;
  1.2530 +		}*/
  1.2531 +
  1.2532 +		/*public void MdiChildMoved()
  1.2533 +		{
  1.2534 +			Point mouseAt = PointToClient(ActiveMdiChild.Location);
  1.2535 +
  1.2536 +			if (Comparisons.ValueWithinAmount(pnlRight.Right, ActiveMdiChild.Right, 10))
  1.2537 +			{
  1.2538 +				pnlRight.Visible = true;
  1.2539 +				//pnlRight.Container.Add(ActiveMdiChild);
  1.2540 +			}
  1.2541 +			else
  1.2542 +			{
  1.2543 +				pnlRight.Visible = false;
  1.2544 +			}
  1.2545 +		}*/
  1.2546 +
  1.2547 +		private void miUndo_Click(object sender, System.EventArgs e)
  1.2548 +		{
  1.2549 +			UndoLastAction();
  1.2550 +		}
  1.2551 +
  1.2552 +		private void miRedo_Click(object sender, System.EventArgs e)
  1.2553 +		{
  1.2554 +			RedoAction();
  1.2555 +		}
  1.2556 +
  1.2557 +		private void miCloseArmy_Click(object sender, EventArgs e)
  1.2558 +		{
  1.2559 +			CloseCurrentArmy();
  1.2560 +		}
  1.2561 +
  1.2562 +		private void miOpenArmy_Click(object sender, EventArgs e)
  1.2563 +		{
  1.2564 +			OpenArmy();
  1.2565 +		}
  1.2566 +
  1.2567 +		private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal)
  1.2568 +		{
  1.2569 +			if (obj is Army)
  1.2570 +			{
  1.2571 +				SetPointsPanelText();
  1.2572 +			}
  1.2573 +		}
  1.2574 +
  1.2575 +		private void SetPointsPanelText()
  1.2576 +		{	
  1.2577 +			if (CurrentArmy==null)
  1.2578 +			{
  1.2579 +				sbPointsPanel.Text = "";
  1.2580 +				sbPointsPanel.ResetColor();
  1.2581 +			}
  1.2582 +			else 
  1.2583 +			{
  1.2584 +				sbPointsPanel.Text = String.Format(Translation.GetTranslation("statusPanelPoints"), CurrentArmy.Points, CurrentArmy.MaxPoints);
  1.2585 +
  1.2586 +				if (CurrentArmy.Points>CurrentArmy.MaxPoints)
  1.2587 +				{
  1.2588 +					sbPointsPanel.Color = Color.Red;
  1.2589 +				}
  1.2590 +				else
  1.2591 +				{
  1.2592 +					sbPointsPanel.ResetColor();
  1.2593 +				}
  1.2594 +			}
  1.2595 +		}
  1.2596 +
  1.2597 +		private void redoMenu_Click(object sender, EventArgs e)
  1.2598 +		{
  1.2599 +			if (sender is ToolStripDropDownItem)
  1.2600 +			{
  1.2601 +				ToolStripDropDownItem item = (ToolStripDropDownItem)sender;
  1.2602 +					//we know it's an redo menu item so find it's index and redo everything					
  1.2603 +				int max = bttnRedo.DropDownItems.IndexOf(item);
  1.2604 +
  1.2605 +				if (max >= 0)
  1.2606 +				{
  1.2607 +					for (int i = 0; i <= max; i++)
  1.2608 +					{
  1.2609 +						commandStack.Redo();
  1.2610 +					}
  1.2611 +				}
  1.2612 +			}
  1.2613 +		}
  1.2614 +
  1.2615 +		private void undoMenu_Click(object sender, EventArgs e)
  1.2616 +		{
  1.2617 +			if (sender is ToolStripDropDownItem)
  1.2618 +			{
  1.2619 +				ToolStripDropDownItem item = (ToolStripDropDownItem)sender;
  1.2620 +				//we know it's an redo menu item so find it's index and redo everything					
  1.2621 +				int max = bttnUndo.DropDownItems.IndexOf(item);
  1.2622 +
  1.2623 +				if (max >= 0)
  1.2624 +				{
  1.2625 +					for (int i = 0; i <= max; i++)
  1.2626 +					{
  1.2627 +						commandStack.Undo();
  1.2628 +					}
  1.2629 +				}
  1.2630 +			}
  1.2631 +		}
  1.2632 +
  1.2633 +		private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
  1.2634 +		{
  1.2635 +			statusBar.ColorableStatusBarDrawItem(sender, sbdevent);
  1.2636 +		}
  1.2637 +
  1.2638 +		private void FrmMain_Closing(object sender, CancelEventArgs e)
  1.2639 +		{
  1.2640 +			if (!CloseCurrentArmy())
  1.2641 +			{
  1.2642 +				e.Cancel = true;
  1.2643 +			}
  1.2644 +		}
  1.2645 +
  1.2646 +		private void miReloadFiles_Click(object sender, System.EventArgs e)
  1.2647 +		{
  1.2648 +			WarFoundryLoader.GetDefault().LoadFiles();
  1.2649 +			sbMainPanel.Text = Translation.GetTranslation("GameSystemFilesReloaded", "Game system and race files reloaded");
  1.2650 +			statusBarTimer.Enabled = true;
  1.2651 +		}
  1.2652 +
  1.2653 +		private void statusBarTimer_Tick(object sender, System.EventArgs e)
  1.2654 +		{
  1.2655 +			sbMainPanel.Text = "";
  1.2656 +			statusBarTimer.Enabled = false;
  1.2657 +		}
  1.2658 +
  1.2659 +		private void statusBar_PanelClick(object sender, StatusBarPanelClickEventArgs e)
  1.2660 +		{
  1.2661 +			if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="")
  1.2662 +			{
  1.2663 +				MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1.2664 +			}
  1.2665 +		}
  1.2666 +
  1.2667 +		private void miExportArmyAsBasicHTML_Click(object sender, EventArgs e)
  1.2668 +		{
  1.2669 +			SaveFileDialog dialog = new SaveFileDialog();
  1.2670 +			dialog.Filter = Translation.GetTranslation("armyExportBasicHtmlFilter", "HTML pages") + "|*.html";
  1.2671 +			dialog.Title = Translation.GetTranslation("exportArmyDialog", "Export army");
  1.2672 +
  1.2673 +			DialogResult dr = dialog.ShowDialog(this);
  1.2674 +
  1.2675 +			if (dr == DialogResult.OK)
  1.2676 +			{
  1.2677 +				Army army = CurrentArmy;
  1.2678 +				string filePath = dialog.FileName;
  1.2679 +				log.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath);
  1.2680 +				WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath);
  1.2681 +			}
  1.2682 +		}
  1.2683 +
  1.2684 +		private void FrmMain_Load(object sender, EventArgs e)
  1.2685 +		{
  1.2686 +			string gameSystemID = Preferences.GetStringProperty("currSystem");
  1.2687 +
  1.2688 +			if (gameSystemID != null && !"".Equals(gameSystemID))
  1.2689 +			{
  1.2690 +				log.Debug("Attempting to load current game system from properties");
  1.2691 +				GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
  1.2692 +
  1.2693 +				if (sys != null)
  1.2694 +				{
  1.2695 +					WarFoundryCore.CurrentGameSystem = sys;
  1.2696 +					log.InfoFormat("Loaded game system {0} from properties", gameSystemID);
  1.2697 +				}
  1.2698 +			}
  1.2699 +		}
  1.2700 +
  1.2701 +		private void miAbout_Click(object sender, EventArgs e)
  1.2702 +		{
  1.2703 +			FrmAbout about = new FrmAbout();
  1.2704 +			about.ShowDialog(this);
  1.2705 +		}
  1.2706 +	}
  1.2707 +}