changeset 38:a9c1e60d0e4d

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