changeset 63:4db2c1086a85

Re #173: Add WinForms UI for showing debugging messages * Add starts of an implementation by subscribing to event and logging out for now (matches GTK# version in r273) * Add file logger
author IBBoard <dev@ibboard.co.uk>
date Mon, 21 Sep 2009 19:31:24 +0000
parents 0e7c257ca8d6
children e04bea5b7b3d
files FrmArmyTree.cs FrmMain.cs WarFoundry.exe.log4net
diffstat 3 files changed, 466 insertions(+), 481 deletions(-) [+]
line diff
     1.1 --- a/FrmArmyTree.cs	Sat Sep 19 19:44:45 2009 +0000
     1.2 +++ b/FrmArmyTree.cs	Mon Sep 21 19:31:24 2009 +0000
     1.3 @@ -1,452 +1,452 @@
     1.4 -// This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 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.Collections.Generic;
    1.11 -using System.ComponentModel;
    1.12 -using System.Windows.Forms;
    1.13 +// This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
    1.14 +//
    1.15 +// 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.16 +
    1.17 +using System;
    1.18 +using System.Drawing;
    1.19 +using System.Collections.Generic;
    1.20 +using System.ComponentModel;
    1.21 +using System.Windows.Forms;
    1.22  using IBBoard.Commands;
    1.23 -using IBBoard.Lang;
    1.24 -using IBBoard.Windows.Forms.I18N;
    1.25 -using IBBoard.Windows.Forms;
    1.26 -using IBBoard.WarFoundry.API;
    1.27 -using IBBoard.WarFoundry.API.Commands;
    1.28 -using IBBoard.WarFoundry.API.Objects;
    1.29 -
    1.30 -namespace IBBoard.WarFoundry.GUI.WinForms
    1.31 -{
    1.32 -	/// <summary>
    1.33 -	/// Summary description for FrmArmyTree.
    1.34 -	/// </summary>
    1.35 -	public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
    1.36 -	{
    1.37 -		private System.Windows.Forms.TreeView treeView;
    1.38 -		private IContainer components;
    1.39 -		private Dictionary<string, TreeNode> nodes;
    1.40 -		private System.Windows.Forms.ContextMenu contextMenu;
    1.41 -		private IBBMenuItem miDelete;
    1.42 -		private IBBMenuItem miEdit;
    1.43 -		
    1.44 -		private ObjectAddDelegate UnitAddedMethod;
    1.45 -		private ObjectRemoveDelegate UnitRemovedMethod;
    1.46 -		private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
    1.47 -		private ToolBar toolBar;
    1.48 -		private IBBToolBarButton bttnEdit;
    1.49 -		private IBBToolBarButton bttnDelete;
    1.50 -		private ImageList imageList;
    1.51 -		private CommandStack commandStack;
    1.52 -
    1.53 -		public FrmArmyTree(CommandStack cmdStack)
    1.54 -		{
    1.55 -			commandStack = cmdStack;
    1.56 -			InitializeComponent();
    1.57 -			UnitAddedMethod = new ObjectAddDelegate(UnitAdded);
    1.58 -			UnitRemovedMethod = new ObjectRemoveDelegate(UnitRemoved);
    1.59 -			UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
    1.60 -			ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
    1.61 -			TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
    1.62 -			nodes = new Dictionary<string, TreeNode>();
    1.63 -			this.Name = "ArmyTree";			
    1.64 -			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
    1.65 -
    1.66 -			foreach (Control ctrl in Controls)
    1.67 -			{
    1.68 -				ControlTranslator.TranslateControl(ctrl);
    1.69 -			}
    1.70 -
    1.71 -			foreach (Component comp in components.Components)
    1.72 -			{
    1.73 -				ControlTranslator.TranslateComponent(comp);
    1.74 -			}
    1.75 -
    1.76 -			foreach (IBBMenuItem mi in contextMenu.MenuItems)
    1.77 -			{
    1.78 -				ControlTranslator.TranslateComponent(mi);
    1.79 -			}
    1.80 -		}
    1.81 -
    1.82 -		/// <summary>
    1.83 -		/// Clean up any resources being used.
    1.84 -		/// </summary>
    1.85 -		protected override void Dispose( bool disposing )
    1.86 -		{
    1.87 -			if( disposing )
    1.88 -			{
    1.89 -				if(components != null)
    1.90 -				{
    1.91 -					components.Dispose();
    1.92 -				}
    1.93 -			}
    1.94 -			base.Dispose( disposing );
    1.95 -		}
    1.96 -
    1.97 -		#region Windows Form Designer generated code
    1.98 -		/// <summary>
    1.99 -		/// Required method for Designer support - do not modify
   1.100 -		/// the contents of this method with the code editor.
   1.101 -		/// </summary>
   1.102 -		private void InitializeComponent()
   1.103 -		{
   1.104 -			this.components = new System.ComponentModel.Container();
   1.105 -			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmArmyTree));
   1.106 -			this.contextMenu = new System.Windows.Forms.ContextMenu();
   1.107 -			this.miEdit = new IBBoard.Windows.Forms.IBBMenuItem();
   1.108 -			this.miDelete = new IBBoard.Windows.Forms.IBBMenuItem();
   1.109 -			this.imageList = new System.Windows.Forms.ImageList(this.components);
   1.110 -			this.toolBar = new System.Windows.Forms.ToolBar();
   1.111 -			this.bttnEdit = new IBBoard.Windows.Forms.IBBToolBarButton();
   1.112 -			this.bttnDelete = new IBBoard.Windows.Forms.IBBToolBarButton();
   1.113 -			this.treeView = new System.Windows.Forms.TreeView();
   1.114 -			this.SuspendLayout();
   1.115 -			// 
   1.116 -			// contextMenu
   1.117 -			// 
   1.118 -			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
   1.119 -            this.miEdit,
   1.120 -            this.miDelete});
   1.121 -			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
   1.122 -			// 
   1.123 -			// miEdit
   1.124 -			// 
   1.125 -			this.miEdit.Index = 0;
   1.126 -			this.miEdit.Text = "&edit unit";
   1.127 -			this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
   1.128 -			// 
   1.129 -			// miDelete
   1.130 -			// 
   1.131 -			this.miDelete.Index = 1;
   1.132 -			this.miDelete.Text = "&delete unit";
   1.133 -			this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
   1.134 -			// 
   1.135 -			// imageList
   1.136 -			// 
   1.137 -			this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList.ImageStream")));
   1.138 -			this.imageList.TransparentColor = System.Drawing.Color.Transparent;
   1.139 -			this.imageList.Images.SetKeyName(0, "gtk-edit.png");
   1.140 -			this.imageList.Images.SetKeyName(1, "edit-delete.png");
   1.141 -			// 
   1.142 -			// toolBar
   1.143 -			// 
   1.144 -			this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
   1.145 -            this.bttnEdit,
   1.146 -            this.bttnDelete});
   1.147 -			this.toolBar.ButtonSize = new System.Drawing.Size(16, 16);
   1.148 -			this.toolBar.DropDownArrows = true;
   1.149 -			this.toolBar.ImageList = this.imageList;
   1.150 -			this.toolBar.Location = new System.Drawing.Point(0, 0);
   1.151 -			this.toolBar.Name = "toolBar";
   1.152 -			this.toolBar.ShowToolTips = true;
   1.153 -			this.toolBar.Size = new System.Drawing.Size(240, 28);
   1.154 -			this.toolBar.TabIndex = 3;
   1.155 -			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
   1.156 -			// 
   1.157 -			// bttnEdit
   1.158 -			// 
   1.159 -			this.bttnEdit.Enabled = false;
   1.160 -			this.bttnEdit.ImageIndex = 0;
   1.161 -			this.bttnEdit.Name = "bttnEdit";
   1.162 -			// 
   1.163 -			// bttnDelete
   1.164 -			// 
   1.165 -			this.bttnDelete.Enabled = false;
   1.166 -			this.bttnDelete.ImageIndex = 1;
   1.167 -			this.bttnDelete.Name = "bttnDelete";
   1.168 -			// 
   1.169 -			// treeView
   1.170 -			// 
   1.171 -			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
   1.172 -						| System.Windows.Forms.AnchorStyles.Left)
   1.173 -						| System.Windows.Forms.AnchorStyles.Right)));
   1.174 -			this.treeView.ContextMenu = this.contextMenu;
   1.175 -			this.treeView.FullRowSelect = true;
   1.176 -			this.treeView.Location = new System.Drawing.Point(0, 28);
   1.177 -			this.treeView.Name = "treeView";
   1.178 -			this.treeView.Size = new System.Drawing.Size(240, 250);
   1.179 -			this.treeView.TabIndex = 0;
   1.180 -			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
   1.181 -			this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
   1.182 -			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
   1.183 -			// 
   1.184 -			// FrmArmyTree
   1.185 -			// 
   1.186 -			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.187 -			this.ClientSize = new System.Drawing.Size(240, 277);
   1.188 -			this.ControlBox = false;
   1.189 -			this.Controls.Add(this.toolBar);
   1.190 -			this.Controls.Add(this.treeView);
   1.191 -			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
   1.192 -			this.MaximizeBox = false;
   1.193 -			this.MinimizeBox = false;
   1.194 -			this.Name = "FrmArmyTree";
   1.195 -			this.Text = "FrmArmyTree";
   1.196 -			this.ResumeLayout(false);
   1.197 -			this.PerformLayout();
   1.198 -
   1.199 -		}
   1.200 -		#endregion
   1.201 -
   1.202 -		private void ClearArmy()
   1.203 -		{
   1.204 -			nodes.Clear();
   1.205 -			treeView.Nodes.Clear();
   1.206 -		}
   1.207 -
   1.208 -		private void SetArmy(Army army)
   1.209 -		{
   1.210 -			ClearArmy();
   1.211 -
   1.212 -			if (army != null)
   1.213 -			{
   1.214 -				ArmyCategory[] cats = army.Categories;
   1.215 -				TreeNode[] catNodes = new TreeNode[cats.Length];
   1.216 -				Unit[] units;
   1.217 -
   1.218 -				for (int i = 0; i < cats.Length; i++)
   1.219 -				{
   1.220 -					ArmyCategory cat = cats[i];
   1.221 -					units = army.GetUnits(cat);
   1.222 -					cat.NameChanged += TreeNameChangedMethod;
   1.223 -					cat.PointsValueChanged += NodePointsValueChanged;
   1.224 -					TreeNode[] unitNodes = new TreeNode[units.Length];
   1.225 -					TreeNode temp;
   1.226 -
   1.227 -					for (int j = 0; j < units.Length; j++)
   1.228 -					{
   1.229 -						unitNodes[j] = CreateTreeNode(units[j]);
   1.230 -					}
   1.231 -
   1.232 -					temp = new TreeNode(CreateNodeName(cat), unitNodes);
   1.233 -					temp.Tag = cat;
   1.234 -					catNodes[i] = temp;
   1.235 -					nodes[cat.ID] = temp;
   1.236 +using IBBoard.Lang;
   1.237 +using IBBoard.Windows.Forms.I18N;
   1.238 +using IBBoard.Windows.Forms;
   1.239 +using IBBoard.WarFoundry.API;
   1.240 +using IBBoard.WarFoundry.API.Commands;
   1.241 +using IBBoard.WarFoundry.API.Objects;
   1.242 +
   1.243 +namespace IBBoard.WarFoundry.GUI.WinForms
   1.244 +{
   1.245 +	/// <summary>
   1.246 +	/// Summary description for FrmArmyTree.
   1.247 +	/// </summary>
   1.248 +	public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
   1.249 +	{
   1.250 +		private System.Windows.Forms.TreeView treeView;
   1.251 +		private IContainer components;
   1.252 +		private Dictionary<string, TreeNode> nodes;
   1.253 +		private System.Windows.Forms.ContextMenu contextMenu;
   1.254 +		private IBBMenuItem miDelete;
   1.255 +		private IBBMenuItem miEdit;
   1.256 +		
   1.257 +		private ObjectAddDelegate UnitAddedMethod;
   1.258 +		private ObjectRemoveDelegate UnitRemovedMethod;
   1.259 +		private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
   1.260 +		private ToolBar toolBar;
   1.261 +		private IBBToolBarButton bttnEdit;
   1.262 +		private IBBToolBarButton bttnDelete;
   1.263 +		private ImageList imageList;
   1.264 +		private CommandStack commandStack;
   1.265 +
   1.266 +		public FrmArmyTree(CommandStack cmdStack)
   1.267 +		{
   1.268 +			commandStack = cmdStack;
   1.269 +			InitializeComponent();
   1.270 +			UnitAddedMethod = new ObjectAddDelegate(UnitAdded);
   1.271 +			UnitRemovedMethod = new ObjectRemoveDelegate(UnitRemoved);
   1.272 +			UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
   1.273 +			ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
   1.274 +			TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
   1.275 +			nodes = new Dictionary<string, TreeNode>();
   1.276 +			this.Name = "ArmyTree";			
   1.277 +			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
   1.278 +
   1.279 +			foreach (Control ctrl in Controls)
   1.280 +			{
   1.281 +				ControlTranslator.TranslateControl(ctrl);
   1.282 +			}
   1.283 +
   1.284 +			foreach (Component comp in components.Components)
   1.285 +			{
   1.286 +				ControlTranslator.TranslateComponent(comp);
   1.287 +			}
   1.288 +
   1.289 +			foreach (IBBMenuItem mi in contextMenu.MenuItems)
   1.290 +			{
   1.291 +				ControlTranslator.TranslateComponent(mi);
   1.292 +			}
   1.293 +		}
   1.294 +
   1.295 +		/// <summary>
   1.296 +		/// Clean up any resources being used.
   1.297 +		/// </summary>
   1.298 +		protected override void Dispose( bool disposing )
   1.299 +		{
   1.300 +			if( disposing )
   1.301 +			{
   1.302 +				if(components != null)
   1.303 +				{
   1.304 +					components.Dispose();
   1.305 +				}
   1.306 +			}
   1.307 +			base.Dispose( disposing );
   1.308 +		}
   1.309 +
   1.310 +		#region Windows Form Designer generated code
   1.311 +		/// <summary>
   1.312 +		/// Required method for Designer support - do not modify
   1.313 +		/// the contents of this method with the code editor.
   1.314 +		/// </summary>
   1.315 +		private void InitializeComponent()
   1.316 +		{
   1.317 +			this.components = new System.ComponentModel.Container();
   1.318 +			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmArmyTree));
   1.319 +			this.contextMenu = new System.Windows.Forms.ContextMenu();
   1.320 +			this.miEdit = new IBBoard.Windows.Forms.IBBMenuItem();
   1.321 +			this.miDelete = new IBBoard.Windows.Forms.IBBMenuItem();
   1.322 +			this.imageList = new System.Windows.Forms.ImageList(this.components);
   1.323 +			this.toolBar = new System.Windows.Forms.ToolBar();
   1.324 +			this.bttnEdit = new IBBoard.Windows.Forms.IBBToolBarButton();
   1.325 +			this.bttnDelete = new IBBoard.Windows.Forms.IBBToolBarButton();
   1.326 +			this.treeView = new System.Windows.Forms.TreeView();
   1.327 +			this.SuspendLayout();
   1.328 +			// 
   1.329 +			// contextMenu
   1.330 +			// 
   1.331 +			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
   1.332 +            this.miEdit,
   1.333 +            this.miDelete});
   1.334 +			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
   1.335 +			// 
   1.336 +			// miEdit
   1.337 +			// 
   1.338 +			this.miEdit.Index = 0;
   1.339 +			this.miEdit.Text = "&edit unit";
   1.340 +			this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
   1.341 +			// 
   1.342 +			// miDelete
   1.343 +			// 
   1.344 +			this.miDelete.Index = 1;
   1.345 +			this.miDelete.Text = "&delete unit";
   1.346 +			this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
   1.347 +			// 
   1.348 +			// imageList
   1.349 +			// 
   1.350 +			this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList.ImageStream")));
   1.351 +			this.imageList.TransparentColor = System.Drawing.Color.Transparent;
   1.352 +			this.imageList.Images.SetKeyName(0, "gtk-edit.png");
   1.353 +			this.imageList.Images.SetKeyName(1, "edit-delete.png");
   1.354 +			// 
   1.355 +			// toolBar
   1.356 +			// 
   1.357 +			this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
   1.358 +            this.bttnEdit,
   1.359 +            this.bttnDelete});
   1.360 +			this.toolBar.ButtonSize = new System.Drawing.Size(16, 16);
   1.361 +			this.toolBar.DropDownArrows = true;
   1.362 +			this.toolBar.ImageList = this.imageList;
   1.363 +			this.toolBar.Location = new System.Drawing.Point(0, 0);
   1.364 +			this.toolBar.Name = "toolBar";
   1.365 +			this.toolBar.ShowToolTips = true;
   1.366 +			this.toolBar.Size = new System.Drawing.Size(240, 28);
   1.367 +			this.toolBar.TabIndex = 3;
   1.368 +			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
   1.369 +			// 
   1.370 +			// bttnEdit
   1.371 +			// 
   1.372 +			this.bttnEdit.Enabled = false;
   1.373 +			this.bttnEdit.ImageIndex = 0;
   1.374 +			this.bttnEdit.Name = "bttnEdit";
   1.375 +			// 
   1.376 +			// bttnDelete
   1.377 +			// 
   1.378 +			this.bttnDelete.Enabled = false;
   1.379 +			this.bttnDelete.ImageIndex = 1;
   1.380 +			this.bttnDelete.Name = "bttnDelete";
   1.381 +			// 
   1.382 +			// treeView
   1.383 +			// 
   1.384 +			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
   1.385 +						| System.Windows.Forms.AnchorStyles.Left)
   1.386 +						| System.Windows.Forms.AnchorStyles.Right)));
   1.387 +			this.treeView.ContextMenu = this.contextMenu;
   1.388 +			this.treeView.FullRowSelect = true;
   1.389 +			this.treeView.Location = new System.Drawing.Point(0, 28);
   1.390 +			this.treeView.Name = "treeView";
   1.391 +			this.treeView.Size = new System.Drawing.Size(240, 250);
   1.392 +			this.treeView.TabIndex = 0;
   1.393 +			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
   1.394 +			this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
   1.395 +			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
   1.396 +			// 
   1.397 +			// FrmArmyTree
   1.398 +			// 
   1.399 +			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.400 +			this.ClientSize = new System.Drawing.Size(240, 277);
   1.401 +			this.ControlBox = false;
   1.402 +			this.Controls.Add(this.toolBar);
   1.403 +			this.Controls.Add(this.treeView);
   1.404 +			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
   1.405 +			this.MaximizeBox = false;
   1.406 +			this.MinimizeBox = false;
   1.407 +			this.Name = "FrmArmyTree";
   1.408 +			this.Text = "FrmArmyTree";
   1.409 +			this.ResumeLayout(false);
   1.410 +			this.PerformLayout();
   1.411 +
   1.412 +		}
   1.413 +		#endregion
   1.414 +
   1.415 +		private void ClearArmy()
   1.416 +		{
   1.417 +			nodes.Clear();
   1.418 +			treeView.Nodes.Clear();
   1.419 +		}
   1.420 +
   1.421 +		private void SetArmy(Army army)
   1.422 +		{
   1.423 +			ClearArmy();
   1.424 +
   1.425 +			if (army != null)
   1.426 +			{
   1.427 +				ArmyCategory[] cats = army.Categories;
   1.428 +				TreeNode[] catNodes = new TreeNode[cats.Length];
   1.429 +				Unit[] units;
   1.430 +
   1.431 +				for (int i = 0; i < cats.Length; i++)
   1.432 +				{
   1.433 +					ArmyCategory cat = cats[i];
   1.434 +					units = army.GetUnits(cat);
   1.435 +					cat.NameChanged += TreeNameChangedMethod;
   1.436 +					cat.PointsValueChanged += NodePointsValueChanged;
   1.437 +					TreeNode[] unitNodes = new TreeNode[units.Length];
   1.438 +					TreeNode temp;
   1.439 +
   1.440 +					for (int j = 0; j < units.Length; j++)
   1.441 +					{
   1.442 +						unitNodes[j] = CreateTreeNode(units[j]);
   1.443 +					}
   1.444 +
   1.445 +					temp = new TreeNode(CreateNodeName(cat), unitNodes);
   1.446 +					temp.Tag = cat;
   1.447 +					catNodes[i] = temp;
   1.448 +					nodes[cat.ID] = temp;
   1.449  				}
   1.450  
   1.451 -				TreeNode root = new TreeNode(CreateNodeName(army), catNodes);
   1.452 +				TreeNode root = new TreeNode(CreateNodeName(army), catNodes);
   1.453  				root.Tag = army;
   1.454 -				army.PointsValueChanged += NodePointsValueChanged;
   1.455 -				nodes[army.ID] = root;
   1.456 -				treeView.Nodes.Add(root);
   1.457 -				root.ExpandAll();
   1.458 -			}
   1.459 -		}
   1.460 -		
   1.461 -		private string CreateNodeName(ICostedWarFoundryObject obj)
   1.462 -		{
   1.463 -			return Translation.GetTranslation("treeNodeText", "{0} ({1}pts)", obj.Name, obj.Points);
   1.464 -		}
   1.465 -
   1.466 -		private void NodePointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
   1.467 +				army.PointsValueChanged += NodePointsValueChanged;
   1.468 +				nodes[army.ID] = root;
   1.469 +				treeView.Nodes.Add(root);
   1.470 +				root.ExpandAll();
   1.471 +			}
   1.472 +		}
   1.473 +		
   1.474 +		private string CreateNodeName(ICostedWarFoundryObject obj)
   1.475 +		{
   1.476 +			return Translation.GetTranslation("treeNodeText", "{0} ({1}pts)", obj.Name, obj.Points);
   1.477 +		}
   1.478 +
   1.479 +		private void NodePointsValueChanged(WarFoundryObject obj, double oldValue, double newValue)
   1.480  		{
   1.481  			if (obj is ICostedWarFoundryObject)
   1.482  			{
   1.483  				nodes[obj.ID].Text = CreateNodeName((ICostedWarFoundryObject)obj);
   1.484 -			}
   1.485 -		}
   1.486 -
   1.487 -		private TreeNode CreateTreeNode(Unit unit)
   1.488 +			}
   1.489 +		}
   1.490 +
   1.491 +		private TreeNode CreateTreeNode(Unit unit)
   1.492  		{
   1.493 -			TreeNode temp = new TreeNode(CreateNodeName(unit));
   1.494 -			temp.Tag = unit;
   1.495 -			unit.NameChanged+= UnitNameChangedMethod;
   1.496 -			unit.PointsValueChanged += NodePointsValueChanged;
   1.497 -			nodes[unit.ID] = temp;
   1.498 -			return temp;
   1.499 -		}
   1.500 -
   1.501 -		public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy)
   1.502 -		{
   1.503 -			if (oldArmy != null)
   1.504 -			{
   1.505 -				oldArmy.UnitAdded -= UnitAddedMethod;
   1.506 -				oldArmy.UnitRemoved -= UnitRemovedMethod;
   1.507 -				oldArmy.PointsValueChanged -= NodePointsValueChanged;
   1.508 -			}
   1.509 -
   1.510 -			if (newArmy != null)
   1.511 -			{
   1.512 -				newArmy.UnitAdded += UnitAddedMethod;
   1.513 -				newArmy.UnitRemoved += UnitRemovedMethod;
   1.514 -				newArmy.PointsValueChanged += NodePointsValueChanged;
   1.515 -			}
   1.516 -
   1.517 -			SetArmy(newArmy);
   1.518 -		}
   1.519 -
   1.520 -		private void UnitAdded(WarFoundryObject obj)
   1.521 -		{
   1.522 -			if (obj is Unit)
   1.523 -			{
   1.524 -				Unit unit = (Unit)obj;
   1.525 -				ArmyCategory cat = unit.Category;
   1.526 -				TreeNode parent = nodes[cat.ID];
   1.527 -				TreeNode unitNode = CreateTreeNode(unit);
   1.528 -				parent.Nodes.Add(unitNode);
   1.529 -				parent.Expand(); //make sure it's expanded
   1.530 -			}
   1.531 -		}
   1.532 -
   1.533 -		public new FrmMain MdiParent
   1.534 -		{
   1.535 -			get { return (FrmMain) base.MdiParent; }
   1.536 -			set { base.MdiParent = value; }
   1.537 -		}
   1.538 -
   1.539 -		private void UnitRemoved(WarFoundryObject obj)
   1.540 -		{
   1.541 -			if (obj is Unit)
   1.542 -			{
   1.543 -				Unit unit = (Unit)obj;
   1.544 -				RemoveUnitFromTree(unit);
   1.545 -			}
   1.546 -		}
   1.547 -
   1.548 -		private void RemoveUnitFromTree(Unit unit)
   1.549 -		{
   1.550 -			TreeNode unitNode = nodes[unit.ID];
   1.551 -			unit.NameChanged-= UnitNameChangedMethod;
   1.552 -
   1.553 -			if (unitNode!=null)
   1.554 -			{
   1.555 -				unitNode.Remove();
   1.556 -				nodes.Remove(unit.ID);
   1.557 -			}
   1.558 -		}
   1.559 -
   1.560 -
   1.561 -		private void contextMenu_Popup(object sender, System.EventArgs e)
   1.562 -		{
   1.563 -			TreeNode node = treeView.SelectedNode;
   1.564 -
   1.565 -			if (node!=null && node.Tag is Unit)
   1.566 -			{
   1.567 -				foreach(MenuItem item in contextMenu.MenuItems)
   1.568 -				{
   1.569 -					item.Visible = true;
   1.570 -				}
   1.571 -			}
   1.572 -			else
   1.573 -			{
   1.574 -				foreach(MenuItem item in contextMenu.MenuItems)
   1.575 -				{
   1.576 -					item.Visible = false;
   1.577 -				}
   1.578 -			}
   1.579 -		}
   1.580 -
   1.581 -		private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
   1.582 -		{
   1.583 -			if (e.Button == MouseButtons.Right)
   1.584 -			{
   1.585 -				TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
   1.586 -
   1.587 -				if (tn!=null)
   1.588 -				{
   1.589 -					treeView.SelectedNode = tn;
   1.590 -				}
   1.591 -				else
   1.592 -				{
   1.593 -					treeView.SelectedNode = null;
   1.594 -				}
   1.595 -			}
   1.596 -		}
   1.597 -
   1.598 -		private void miDelete_Click(object sender, System.EventArgs e)
   1.599 -		{
   1.600 -			DeleteUnit();
   1.601 -		}
   1.602 -
   1.603 -		private void DeleteUnit()
   1.604 -		{
   1.605 -
   1.606 -			TreeNode selected = treeView.SelectedNode;
   1.607 -
   1.608 -			if (selected.Tag != null && selected.Tag is Unit)
   1.609 -			{
   1.610 -				Unit unit = (Unit) selected.Tag;
   1.611 -				commandStack.Execute(new RemoveUnitCommand(unit));
   1.612 -			}
   1.613 -		}
   1.614 -
   1.615 -		private void miEdit_Click(object sender, System.EventArgs e)
   1.616 -		{	
   1.617 -			EditUnit();
   1.618 -		}
   1.619 -
   1.620 -		private void treeView_DoubleClick(object sender, System.EventArgs e)
   1.621 -		{
   1.622 -			EditUnit();			
   1.623 -		}
   1.624 -
   1.625 -		private void EditUnit()
   1.626 -		{
   1.627 -			TreeNode selected = treeView.SelectedNode;
   1.628 -			object tagData = selected.Tag;
   1.629 -
   1.630 -			if (tagData is Unit)
   1.631 -			{
   1.632 -				Unit unit = (Unit) tagData;
   1.633 -				MdiParent.OpenUnitDialog(unit);
   1.634 -			}
   1.635 -		}
   1.636 -
   1.637 -		private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
   1.638 -		{
   1.639 -			if (obj is Unit)
   1.640 -			{
   1.641 -				Unit unit = (Unit)obj;
   1.642 -				TreeNode node = nodes[unit.ID];
   1.643 -				
   1.644 -				if (node!=null)
   1.645 -				{
   1.646 -					node.Text = unit.Name;
   1.647 -				}
   1.648 -			}
   1.649 -		}
   1.650 -
   1.651 -		private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue)
   1.652 -		{
   1.653 -			if (obj is Army)
   1.654 -			{
   1.655 -				Army army = (Army)obj;
   1.656 -				TreeNode node = treeView.Nodes[0];
   1.657 -				
   1.658 -				if (node!=null)
   1.659 -				{
   1.660 -					node.Text = army.Name;
   1.661 -				}
   1.662 -			}
   1.663 -		}
   1.664 -
   1.665 -		private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.666 -		{
   1.667 -			TreeNode node = nodes[obj.ID];
   1.668 -
   1.669 -			if (node!=null)
   1.670 -			{
   1.671 -				node.Text = obj.Name;
   1.672 -			}
   1.673 -		}
   1.674 -
   1.675 -		private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
   1.676 -		{
   1.677 -			if (e.Button == bttnDelete)
   1.678 -			{
   1.679 -				DeleteUnit();
   1.680 -			}
   1.681 -			else if (e.Button == bttnEdit)
   1.682 -			{
   1.683 -				EditUnit();
   1.684 -			}
   1.685 -		}
   1.686 -
   1.687 -		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
   1.688 -		{
   1.689 -			TreeNode node = treeView.SelectedNode;
   1.690 -
   1.691 -			bttnDelete.Enabled = (node != null && node.Tag is Unit);
   1.692 -			bttnEdit.Enabled = bttnDelete.Enabled;
   1.693 -		}
   1.694 -	}
   1.695 -}
   1.696 +			TreeNode temp = new TreeNode(CreateNodeName(unit));
   1.697 +			temp.Tag = unit;
   1.698 +			unit.NameChanged+= UnitNameChangedMethod;
   1.699 +			unit.PointsValueChanged += NodePointsValueChanged;
   1.700 +			nodes[unit.ID] = temp;
   1.701 +			return temp;
   1.702 +		}
   1.703 +
   1.704 +		public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy)
   1.705 +		{
   1.706 +			if (oldArmy != null)
   1.707 +			{
   1.708 +				oldArmy.UnitAdded -= UnitAddedMethod;
   1.709 +				oldArmy.UnitRemoved -= UnitRemovedMethod;
   1.710 +				oldArmy.PointsValueChanged -= NodePointsValueChanged;
   1.711 +			}
   1.712 +
   1.713 +			if (newArmy != null)
   1.714 +			{
   1.715 +				newArmy.UnitAdded += UnitAddedMethod;
   1.716 +				newArmy.UnitRemoved += UnitRemovedMethod;
   1.717 +				newArmy.PointsValueChanged += NodePointsValueChanged;
   1.718 +			}
   1.719 +
   1.720 +			SetArmy(newArmy);
   1.721 +		}
   1.722 +
   1.723 +		private void UnitAdded(WarFoundryObject obj)
   1.724 +		{
   1.725 +			if (obj is Unit)
   1.726 +			{
   1.727 +				Unit unit = (Unit)obj;
   1.728 +				ArmyCategory cat = unit.Category;
   1.729 +				TreeNode parent = nodes[cat.ID];
   1.730 +				TreeNode unitNode = CreateTreeNode(unit);
   1.731 +				parent.Nodes.Add(unitNode);
   1.732 +				parent.Expand(); //make sure it's expanded
   1.733 +			}
   1.734 +		}
   1.735 +
   1.736 +		public new FrmMain MdiParent
   1.737 +		{
   1.738 +			get { return (FrmMain) base.MdiParent; }
   1.739 +			set { base.MdiParent = value; }
   1.740 +		}
   1.741 +
   1.742 +		private void UnitRemoved(WarFoundryObject obj)
   1.743 +		{
   1.744 +			if (obj is Unit)
   1.745 +			{
   1.746 +				Unit unit = (Unit)obj;
   1.747 +				RemoveUnitFromTree(unit);
   1.748 +			}
   1.749 +		}
   1.750 +
   1.751 +		private void RemoveUnitFromTree(Unit unit)
   1.752 +		{
   1.753 +			TreeNode unitNode = nodes[unit.ID];
   1.754 +			unit.NameChanged-= UnitNameChangedMethod;
   1.755 +
   1.756 +			if (unitNode!=null)
   1.757 +			{
   1.758 +				unitNode.Remove();
   1.759 +				nodes.Remove(unit.ID);
   1.760 +			}
   1.761 +		}
   1.762 +
   1.763 +
   1.764 +		private void contextMenu_Popup(object sender, System.EventArgs e)
   1.765 +		{
   1.766 +			TreeNode node = treeView.SelectedNode;
   1.767 +
   1.768 +			if (node!=null && node.Tag is Unit)
   1.769 +			{
   1.770 +				foreach(MenuItem item in contextMenu.MenuItems)
   1.771 +				{
   1.772 +					item.Visible = true;
   1.773 +				}
   1.774 +			}
   1.775 +			else
   1.776 +			{
   1.777 +				foreach(MenuItem item in contextMenu.MenuItems)
   1.778 +				{
   1.779 +					item.Visible = false;
   1.780 +				}
   1.781 +			}
   1.782 +		}
   1.783 +
   1.784 +		private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
   1.785 +		{
   1.786 +			if (e.Button == MouseButtons.Right)
   1.787 +			{
   1.788 +				TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
   1.789 +
   1.790 +				if (tn!=null)
   1.791 +				{
   1.792 +					treeView.SelectedNode = tn;
   1.793 +				}
   1.794 +				else
   1.795 +				{
   1.796 +					treeView.SelectedNode = null;
   1.797 +				}
   1.798 +			}
   1.799 +		}
   1.800 +
   1.801 +		private void miDelete_Click(object sender, System.EventArgs e)
   1.802 +		{
   1.803 +			DeleteUnit();
   1.804 +		}
   1.805 +
   1.806 +		private void DeleteUnit()
   1.807 +		{
   1.808 +
   1.809 +			TreeNode selected = treeView.SelectedNode;
   1.810 +
   1.811 +			if (selected.Tag != null && selected.Tag is Unit)
   1.812 +			{
   1.813 +				Unit unit = (Unit) selected.Tag;
   1.814 +				commandStack.Execute(new RemoveUnitCommand(unit));
   1.815 +			}
   1.816 +		}
   1.817 +
   1.818 +		private void miEdit_Click(object sender, System.EventArgs e)
   1.819 +		{	
   1.820 +			EditUnit();
   1.821 +		}
   1.822 +
   1.823 +		private void treeView_DoubleClick(object sender, System.EventArgs e)
   1.824 +		{
   1.825 +			EditUnit();			
   1.826 +		}
   1.827 +
   1.828 +		private void EditUnit()
   1.829 +		{
   1.830 +			TreeNode selected = treeView.SelectedNode;
   1.831 +			object tagData = selected.Tag;
   1.832 +
   1.833 +			if (tagData is Unit)
   1.834 +			{
   1.835 +				Unit unit = (Unit) tagData;
   1.836 +				MdiParent.OpenUnitDialog(unit);
   1.837 +			}
   1.838 +		}
   1.839 +
   1.840 +		private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
   1.841 +		{
   1.842 +			if (obj is Unit)
   1.843 +			{
   1.844 +				Unit unit = (Unit)obj;
   1.845 +				TreeNode node = nodes[unit.ID];
   1.846 +				
   1.847 +				if (node!=null)
   1.848 +				{
   1.849 +					node.Text = unit.Name;
   1.850 +				}
   1.851 +			}
   1.852 +		}
   1.853 +
   1.854 +		private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue)
   1.855 +		{
   1.856 +			if (obj is Army)
   1.857 +			{
   1.858 +				Army army = (Army)obj;
   1.859 +				TreeNode node = treeView.Nodes[0];
   1.860 +				
   1.861 +				if (node!=null)
   1.862 +				{
   1.863 +					node.Text = army.Name;
   1.864 +				}
   1.865 +			}
   1.866 +		}
   1.867 +
   1.868 +		private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
   1.869 +		{
   1.870 +			TreeNode node = nodes[obj.ID];
   1.871 +
   1.872 +			if (node!=null)
   1.873 +			{
   1.874 +				node.Text = obj.Name;
   1.875 +			}
   1.876 +		}
   1.877 +
   1.878 +		private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
   1.879 +		{
   1.880 +			if (e.Button == bttnDelete)
   1.881 +			{
   1.882 +				DeleteUnit();
   1.883 +			}
   1.884 +			else if (e.Button == bttnEdit)
   1.885 +			{
   1.886 +				EditUnit();
   1.887 +			}
   1.888 +		}
   1.889 +
   1.890 +		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
   1.891 +		{
   1.892 +			TreeNode node = treeView.SelectedNode;
   1.893 +
   1.894 +			bttnDelete.Enabled = (node != null && node.Tag is Unit);
   1.895 +			bttnEdit.Enabled = bttnDelete.Enabled;
   1.896 +		}
   1.897 +	}
   1.898 +}
     2.1 --- a/FrmMain.cs	Sat Sep 19 19:44:45 2009 +0000
     2.2 +++ b/FrmMain.cs	Mon Sep 21 19:31:24 2009 +0000
     2.3 @@ -91,6 +91,24 @@
     2.4  		private MenuItem miExportArmyAsBasicHTML;
     2.5  		private System.Windows.Forms.Panel pnlRight;
     2.6  
     2.7 +		/// <summary>
     2.8 +		/// The main entry point for the application.
     2.9 +		/// </summary>
    2.10 +		[STAThread]
    2.11 +		static void Main(string[] args)
    2.12 +		{
    2.13 +			try
    2.14 +			{
    2.15 +				Application.EnableVisualStyles();
    2.16 +				Application.Run(new FrmMain(args));
    2.17 +			}
    2.18 +			catch (Exception ex)
    2.19 +			{
    2.20 +				LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
    2.21 +				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);
    2.22 +			}
    2.23 +		}
    2.24 +
    2.25  		public FrmMain(string[] args)
    2.26  		{
    2.27  			this.Closing+=new CancelEventHandler(FrmMain_Closing);
    2.28 @@ -150,6 +168,7 @@
    2.29              // hack to load default files
    2.30              WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
    2.31              WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
    2.32 +			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
    2.33  			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
    2.34  		}
    2.35  
    2.36 @@ -522,21 +541,11 @@
    2.37  		}
    2.38  		#endregion
    2.39  
    2.40 -		/// <summary>
    2.41 -		/// The main entry point for the application.
    2.42 -		/// </summary>
    2.43 -		[STAThread]
    2.44 -		static void Main(string[] args) 
    2.45 +		private void FileLoadingFinished(List<FileLoadFailure> failures)
    2.46  		{
    2.47 -			try
    2.48 +			foreach (FileLoadFailure failure in failures)
    2.49  			{
    2.50 -				Application.EnableVisualStyles();
    2.51 -				Application.Run(new FrmMain(args));
    2.52 -			}
    2.53 -			catch(Exception ex)
    2.54 -			{
    2.55 -				   LogManager.GetLogger(typeof(FrmMain)).Fatal(ex);
    2.56 -				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);
    2.57 +				logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
    2.58  			}
    2.59  		}
    2.60  
     3.1 --- a/WarFoundry.exe.log4net	Sat Sep 19 19:44:45 2009 +0000
     3.2 +++ b/WarFoundry.exe.log4net	Mon Sep 21 19:31:24 2009 +0000
     3.3 @@ -1,25 +1,1 @@
     3.4 -<?xml version="1.0" encoding="utf-8" ?>
     3.5 -<!-- This section contains the log4net configuration settings -->
     3.6 -<log4net>
     3.7 -	<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
     3.8 -		<layout type="log4net.Layout.PatternLayout">
     3.9 -			<param name="ConversionPattern" value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.10 -		</layout>
    3.11 -	</appender>
    3.12 -	<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    3.13 -		<file value="logfile.txt" />
    3.14 -		<appendToFile value="false" />
    3.15 -		<rollingStyle value="Size" />
    3.16 -		<maxSizeRollBackups value="-1" />
    3.17 -		<maximumFileSize value="100MB" />
    3.18 -		<layout type="log4net.Layout.PatternLayout">
    3.19 -			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.20 -		</layout>
    3.21 -	</appender>
    3.22 -	<root>
    3.23 -		<level value="DEBUG" />
    3.24 -		<appender-ref ref="ConsoleAppender" />
    3.25 -		<appender-ref ref="RollingLogFileAppender" />
    3.26 -	</root>
    3.27 -</log4net>
    3.28 -
    3.29 +<?xml version="1.0" encoding="utf-8" ?>
    3.30 <log4net>
    3.31 	<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    3.32 		<layout type="log4net.Layout.PatternLayout">
    3.33 			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.34 		</layout>
    3.35 	</appender>
    3.36 	<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    3.37 		<file value="logs\WarFoundry.log" />
    3.38 		<appendToFile value="false" />
    3.39 		<rollingStyle value="Size" />
    3.40 		<maxSizeRollBackups value="-1" />
    3.41 		<maximumFileSize value="100MB" />
    3.42 		<layout type="log4net.Layout.PatternLayout">
    3.43 			<conversionPattern value="%-5p [%d{HH:MM:ss}]: %C{1}.%M() - Line: %L - %m%n" />
    3.44 		</layout>
    3.45 	</appender>
    3.46 	<root>
    3.47 		<level value="DEBUG" />
    3.48 		<appender-ref ref="ConsoleAppender" />
    3.49 		<appender-ref ref="RollingLogFileAppender" />
    3.50 	</root>
    3.51 </log4net>
    3.52 
    3.53 \ No newline at end of file