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 diff
     1.1 --- a/FrmArmyTree.Designer.cs	Sat Jan 21 11:35:09 2012 +0000
     1.2 +++ b/FrmArmyTree.Designer.cs	Sat Jan 21 11:36:23 2012 +0000
     1.3 @@ -38,6 +38,8 @@
     1.4  			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
     1.5  			this.bttnEdit = new System.Windows.Forms.ToolStripButton();
     1.6  			this.bttnDelete = new System.Windows.Forms.ToolStripButton();
     1.7 +			this.miAddUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
     1.8 +			this.bttnAdd = new IBBoard.Windows.Forms.IBBToolStripButton();
     1.9  			this.toolStripContainer1.ContentPanel.SuspendLayout();
    1.10  			this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
    1.11  			this.toolStripContainer1.SuspendLayout();
    1.12 @@ -83,16 +85,17 @@
    1.13  			this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    1.14              this.miEditArmy,
    1.15              this.miEditUnit,
    1.16 -            this.miDeleteUnit});
    1.17 +            this.miDeleteUnit,
    1.18 +            this.miAddUnit});
    1.19  			this.contextMenuStrip.Name = "contextMenuStrip1";
    1.20 -			this.contextMenuStrip.Size = new System.Drawing.Size(153, 92);
    1.21 +			this.contextMenuStrip.Size = new System.Drawing.Size(137, 92);
    1.22  			this.contextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip_Opening);
    1.23  			// 
    1.24  			// miEditArmy
    1.25  			// 
    1.26  			this.miEditArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit;
    1.27  			this.miEditArmy.Name = "miEditArmy";
    1.28 -			this.miEditArmy.Size = new System.Drawing.Size(152, 22);
    1.29 +			this.miEditArmy.Size = new System.Drawing.Size(136, 22);
    1.30  			this.miEditArmy.Text = "edit army";
    1.31  			this.miEditArmy.Click += new System.EventHandler(this.miEditArmy_Click);
    1.32  			// 
    1.33 @@ -100,7 +103,7 @@
    1.34  			// 
    1.35  			this.miEditUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit;
    1.36  			this.miEditUnit.Name = "miEditUnit";
    1.37 -			this.miEditUnit.Size = new System.Drawing.Size(152, 22);
    1.38 +			this.miEditUnit.Size = new System.Drawing.Size(136, 22);
    1.39  			this.miEditUnit.Text = "edit unit";
    1.40  			this.miEditUnit.Click += new System.EventHandler(this.miEdit_Click);
    1.41  			// 
    1.42 @@ -108,7 +111,7 @@
    1.43  			// 
    1.44  			this.miDeleteUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_delete;
    1.45  			this.miDeleteUnit.Name = "miDeleteUnit";
    1.46 -			this.miDeleteUnit.Size = new System.Drawing.Size(152, 22);
    1.47 +			this.miDeleteUnit.Size = new System.Drawing.Size(136, 22);
    1.48  			this.miDeleteUnit.Text = "delete unit";
    1.49  			this.miDeleteUnit.Click += new System.EventHandler(this.miDelete_Click);
    1.50  			// 
    1.51 @@ -116,11 +119,12 @@
    1.52  			// 
    1.53  			this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
    1.54  			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    1.55 +            this.bttnAdd,
    1.56              this.bttnEdit,
    1.57              this.bttnDelete});
    1.58  			this.toolStrip1.Location = new System.Drawing.Point(3, 0);
    1.59  			this.toolStrip1.Name = "toolStrip1";
    1.60 -			this.toolStrip1.Size = new System.Drawing.Size(58, 25);
    1.61 +			this.toolStrip1.Size = new System.Drawing.Size(112, 25);
    1.62  			this.toolStrip1.TabIndex = 0;
    1.63  			// 
    1.64  			// bttnEdit
    1.65 @@ -145,6 +149,24 @@
    1.66  			this.bttnDelete.Text = "toolStripButton2";
    1.67  			this.bttnDelete.Click += new System.EventHandler(this.bttnDelete_Click);
    1.68  			// 
    1.69 +			// miAddUnit
    1.70 +			// 
    1.71 +			this.miAddUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
    1.72 +			this.miAddUnit.Name = "miAddUnit";
    1.73 +			this.miAddUnit.Size = new System.Drawing.Size(136, 22);
    1.74 +			this.miAddUnit.Text = "add unit";
    1.75 +			this.miAddUnit.Click += new System.EventHandler(this.miAddUnit_Click);
    1.76 +			// 
    1.77 +			// bttnAdd
    1.78 +			// 
    1.79 +			this.bttnAdd.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
    1.80 +			this.bttnAdd.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
    1.81 +			this.bttnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
    1.82 +			this.bttnAdd.Name = "bttnAdd";
    1.83 +			this.bttnAdd.Size = new System.Drawing.Size(23, 22);
    1.84 +			this.bttnAdd.Text = "ibbToolStripButton1";
    1.85 +			this.bttnAdd.Click += new System.EventHandler(this.bttnAdd_Click);
    1.86 +			// 
    1.87  			// FrmArmyTree
    1.88  			// 
    1.89  			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    1.90 @@ -179,5 +201,7 @@
    1.91  		private Windows.Forms.IBBToolStripMenuItem miEditArmy;
    1.92  		private Windows.Forms.IBBToolStripMenuItem miEditUnit;
    1.93  		private Windows.Forms.IBBToolStripMenuItem miDeleteUnit;
    1.94 +		private Windows.Forms.IBBToolStripMenuItem miAddUnit;
    1.95 +		private Windows.Forms.IBBToolStripButton bttnAdd;
    1.96  	}
    1.97  }
    1.98 \ No newline at end of file
     2.1 --- a/FrmArmyTree.cs	Sat Jan 21 11:35:09 2012 +0000
     2.2 +++ b/FrmArmyTree.cs	Sat Jan 21 11:36:23 2012 +0000
     2.3 @@ -263,8 +263,12 @@
     2.4  			{
     2.5  				EditArmy((Army)tagData);
     2.6  			}
     2.7 +			else if (tagData is ArmyCategory)
     2.8 +			{
     2.9 +				AddUnitFromCategory((ArmyCategory)tagData);
    2.10 +			}
    2.11  		}
    2.12 -
    2.13 +		
    2.14  		private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
    2.15  		{
    2.16  			if (obj is ICostedWarFoundryObject)
    2.17 @@ -294,7 +298,7 @@
    2.18  		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
    2.19  		{
    2.20  			TreeNode node = treeView.SelectedNode;
    2.21 -
    2.22 +			bttnAdd.Enabled = (node != null && node.Tag is ArmyCategory);
    2.23  			bttnDelete.Enabled = (node != null && node.Tag is Unit);
    2.24  			bttnEdit.Enabled = (node != null && (node.Tag is Unit || node.Tag is Army));
    2.25  		}
    2.26 @@ -327,8 +331,9 @@
    2.27  			Object tag = (node != null) ? node.Tag : null;
    2.28  			bool tagIsUnit = (tag is Unit);
    2.29  			bool tagIsArmy = (tag is Army);
    2.30 +			bool tagIsCategory = (tag is ArmyCategory);
    2.31  
    2.32 -			if (!tagIsUnit && !tagIsArmy)
    2.33 +			if (!tagIsUnit && !tagIsArmy && !tagIsCategory)
    2.34  			{
    2.35  				e.Cancel = true;
    2.36  			}
    2.37 @@ -337,7 +342,29 @@
    2.38  				miDeleteUnit.Visible = tagIsUnit;
    2.39  				miEditUnit.Visible = tagIsUnit;
    2.40  				miEditArmy.Visible = tagIsArmy;
    2.41 +				miAddUnit.Visible = tagIsCategory;
    2.42  			}
    2.43  		}
    2.44 +
    2.45 +		private void miAddUnit_Click(object sender, EventArgs e)
    2.46 +		{
    2.47 +			AddUnit();
    2.48 +		}
    2.49 +
    2.50 +		private void AddUnit()
    2.51 +		{
    2.52 +			ArmyCategory tagData = treeView.SelectedNode.Tag as ArmyCategory;
    2.53 +			AddUnitFromCategory(tagData);
    2.54 +		}
    2.55 +
    2.56 +		private void AddUnitFromCategory(ArmyCategory tagData)
    2.57 +		{
    2.58 +			MdiParent.AddUnitFromCategory(tagData.Category);
    2.59 +		}
    2.60 +
    2.61 +		private void bttnAdd_Click(object sender, EventArgs e)
    2.62 +		{
    2.63 +			AddUnit();
    2.64 +		}
    2.65  	}
    2.66  }
     3.1 --- a/FrmMain.cs	Sat Jan 21 11:35:09 2012 +0000
     3.2 +++ b/FrmMain.cs	Sat Jan 21 11:36:23 2012 +0000
     3.3 @@ -1203,7 +1203,7 @@
     3.4  			this.Text = str;
     3.5  		}
     3.6  
     3.7 -		private void AddUnitFromCategory(Category cat)
     3.8 +		internal void AddUnitFromCategory(Category cat)
     3.9  		{
    3.10  			FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy);
    3.11  			DialogResult dr = newUnit.ShowDialog(this);