changeset 234:c06d0865ff27

Fixes #388: Add "Add unit" options to army tree * Add button, context menu and double-click hooks for adding units
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Jan 2012 11:36:23 +0000
parents 1ebbe78f89e7
children f7b0cdb54c9c
files FrmArmyTree.Designer.cs FrmArmyTree.cs FrmMain.cs
diffstat 3 files changed, 61 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/FrmArmyTree.Designer.cs	Sat Jan 21 11:35:09 2012 +0000
+++ b/FrmArmyTree.Designer.cs	Sat Jan 21 11:36:23 2012 +0000
@@ -38,6 +38,8 @@
 			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
 			this.bttnEdit = new System.Windows.Forms.ToolStripButton();
 			this.bttnDelete = new System.Windows.Forms.ToolStripButton();
+			this.miAddUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
+			this.bttnAdd = new IBBoard.Windows.Forms.IBBToolStripButton();
 			this.toolStripContainer1.ContentPanel.SuspendLayout();
 			this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
 			this.toolStripContainer1.SuspendLayout();
@@ -83,16 +85,17 @@
 			this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.miEditArmy,
             this.miEditUnit,
-            this.miDeleteUnit});
+            this.miDeleteUnit,
+            this.miAddUnit});
 			this.contextMenuStrip.Name = "contextMenuStrip1";
-			this.contextMenuStrip.Size = new System.Drawing.Size(153, 92);
+			this.contextMenuStrip.Size = new System.Drawing.Size(137, 92);
 			this.contextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip_Opening);
 			// 
 			// miEditArmy
 			// 
 			this.miEditArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit;
 			this.miEditArmy.Name = "miEditArmy";
-			this.miEditArmy.Size = new System.Drawing.Size(152, 22);
+			this.miEditArmy.Size = new System.Drawing.Size(136, 22);
 			this.miEditArmy.Text = "edit army";
 			this.miEditArmy.Click += new System.EventHandler(this.miEditArmy_Click);
 			// 
@@ -100,7 +103,7 @@
 			// 
 			this.miEditUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit;
 			this.miEditUnit.Name = "miEditUnit";
-			this.miEditUnit.Size = new System.Drawing.Size(152, 22);
+			this.miEditUnit.Size = new System.Drawing.Size(136, 22);
 			this.miEditUnit.Text = "edit unit";
 			this.miEditUnit.Click += new System.EventHandler(this.miEdit_Click);
 			// 
@@ -108,7 +111,7 @@
 			// 
 			this.miDeleteUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_delete;
 			this.miDeleteUnit.Name = "miDeleteUnit";
-			this.miDeleteUnit.Size = new System.Drawing.Size(152, 22);
+			this.miDeleteUnit.Size = new System.Drawing.Size(136, 22);
 			this.miDeleteUnit.Text = "delete unit";
 			this.miDeleteUnit.Click += new System.EventHandler(this.miDelete_Click);
 			// 
@@ -116,11 +119,12 @@
 			// 
 			this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
 			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.bttnAdd,
             this.bttnEdit,
             this.bttnDelete});
 			this.toolStrip1.Location = new System.Drawing.Point(3, 0);
 			this.toolStrip1.Name = "toolStrip1";
-			this.toolStrip1.Size = new System.Drawing.Size(58, 25);
+			this.toolStrip1.Size = new System.Drawing.Size(112, 25);
 			this.toolStrip1.TabIndex = 0;
 			// 
 			// bttnEdit
@@ -145,6 +149,24 @@
 			this.bttnDelete.Text = "toolStripButton2";
 			this.bttnDelete.Click += new System.EventHandler(this.bttnDelete_Click);
 			// 
+			// miAddUnit
+			// 
+			this.miAddUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
+			this.miAddUnit.Name = "miAddUnit";
+			this.miAddUnit.Size = new System.Drawing.Size(136, 22);
+			this.miAddUnit.Text = "add unit";
+			this.miAddUnit.Click += new System.EventHandler(this.miAddUnit_Click);
+			// 
+			// bttnAdd
+			// 
+			this.bttnAdd.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+			this.bttnAdd.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
+			this.bttnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
+			this.bttnAdd.Name = "bttnAdd";
+			this.bttnAdd.Size = new System.Drawing.Size(23, 22);
+			this.bttnAdd.Text = "ibbToolStripButton1";
+			this.bttnAdd.Click += new System.EventHandler(this.bttnAdd_Click);
+			// 
 			// FrmArmyTree
 			// 
 			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -179,5 +201,7 @@
 		private Windows.Forms.IBBToolStripMenuItem miEditArmy;
 		private Windows.Forms.IBBToolStripMenuItem miEditUnit;
 		private Windows.Forms.IBBToolStripMenuItem miDeleteUnit;
+		private Windows.Forms.IBBToolStripMenuItem miAddUnit;
+		private Windows.Forms.IBBToolStripButton bttnAdd;
 	}
 }
\ No newline at end of file
--- a/FrmArmyTree.cs	Sat Jan 21 11:35:09 2012 +0000
+++ b/FrmArmyTree.cs	Sat Jan 21 11:36:23 2012 +0000
@@ -263,8 +263,12 @@
 			{
 				EditArmy((Army)tagData);
 			}
+			else if (tagData is ArmyCategory)
+			{
+				AddUnitFromCategory((ArmyCategory)tagData);
+			}
 		}
-
+		
 		private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
 		{
 			if (obj is ICostedWarFoundryObject)
@@ -294,7 +298,7 @@
 		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
 		{
 			TreeNode node = treeView.SelectedNode;
-
+			bttnAdd.Enabled = (node != null && node.Tag is ArmyCategory);
 			bttnDelete.Enabled = (node != null && node.Tag is Unit);
 			bttnEdit.Enabled = (node != null && (node.Tag is Unit || node.Tag is Army));
 		}
@@ -327,8 +331,9 @@
 			Object tag = (node != null) ? node.Tag : null;
 			bool tagIsUnit = (tag is Unit);
 			bool tagIsArmy = (tag is Army);
+			bool tagIsCategory = (tag is ArmyCategory);
 
-			if (!tagIsUnit && !tagIsArmy)
+			if (!tagIsUnit && !tagIsArmy && !tagIsCategory)
 			{
 				e.Cancel = true;
 			}
@@ -337,7 +342,29 @@
 				miDeleteUnit.Visible = tagIsUnit;
 				miEditUnit.Visible = tagIsUnit;
 				miEditArmy.Visible = tagIsArmy;
+				miAddUnit.Visible = tagIsCategory;
 			}
 		}
+
+		private void miAddUnit_Click(object sender, EventArgs e)
+		{
+			AddUnit();
+		}
+
+		private void AddUnit()
+		{
+			ArmyCategory tagData = treeView.SelectedNode.Tag as ArmyCategory;
+			AddUnitFromCategory(tagData);
+		}
+
+		private void AddUnitFromCategory(ArmyCategory tagData)
+		{
+			MdiParent.AddUnitFromCategory(tagData.Category);
+		}
+
+		private void bttnAdd_Click(object sender, EventArgs e)
+		{
+			AddUnit();
+		}
 	}
 }
--- a/FrmMain.cs	Sat Jan 21 11:35:09 2012 +0000
+++ b/FrmMain.cs	Sat Jan 21 11:36:23 2012 +0000
@@ -1203,7 +1203,7 @@
 			this.Text = str;
 		}
 
-		private void AddUnitFromCategory(Category cat)
+		internal void AddUnitFromCategory(Category cat)
 		{
 			FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy);
 			DialogResult dr = newUnit.ShowDialog(this);