changeset 249:a11faa64c333

Re #354: Single-button Add Unit * Add right-click menu (doesn't work yet because of position maths)
author IBBoard <dev@ibboard.co.uk>
date Sat, 20 Aug 2011 17:05:45 +0100
parents 19a88383dfa7
children 694f23814ec2
files FrmNewUnitFromTree.Designer.cs FrmNewUnitFromTree.cs FrmNewUnitFromTree.resx
diffstat 3 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/FrmNewUnitFromTree.Designer.cs	Sat Aug 20 16:12:15 2011 +0100
+++ b/FrmNewUnitFromTree.Designer.cs	Sat Aug 20 17:05:45 2011 +0100
@@ -28,7 +28,11 @@
         /// </summary>
         private void InitializeComponent()
         {
+            this.components = new System.ComponentModel.Container();
             this.unitTypeTree = new System.Windows.Forms.TreeView();
+            this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
+            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
+            this.contextMenu.SuspendLayout();
             this.SuspendLayout();
             // 
             // unitTypeTree
@@ -36,12 +40,28 @@
             this.unitTypeTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                         | System.Windows.Forms.AnchorStyles.Left)
                         | System.Windows.Forms.AnchorStyles.Right)));
+            this.unitTypeTree.ContextMenuStrip = this.contextMenu;
             this.unitTypeTree.Location = new System.Drawing.Point(0, 0);
             this.unitTypeTree.Name = "unitTypeTree";
             this.unitTypeTree.Size = new System.Drawing.Size(199, 287);
             this.unitTypeTree.TabIndex = 0;
             this.unitTypeTree.DoubleClick += new System.EventHandler(this.unitTypeTree_DoubleClick);
             // 
+            // contextMenu
+            // 
+            this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.toolStripMenuItem1});
+            this.contextMenu.Name = "contextMenu";
+            this.contextMenu.Size = new System.Drawing.Size(154, 26);
+            // 
+            // toolStripMenuItem1
+            // 
+            this.toolStripMenuItem1.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
+            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
+            this.toolStripMenuItem1.Size = new System.Drawing.Size(153, 22);
+            this.toolStripMenuItem1.Text = "Add Unit Type";
+            this.toolStripMenuItem1.Click += new System.EventHandler(this.AddUnitClicked);
+            // 
             // FrmNewUnitFromTree
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -52,6 +72,7 @@
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
             this.Name = "FrmNewUnitFromTree";
             this.Text = "Available Unit Types";
+            this.contextMenu.ResumeLayout(false);
             this.ResumeLayout(false);
 
         }
@@ -59,5 +80,7 @@
         #endregion
 
         private System.Windows.Forms.TreeView unitTypeTree;
+        private System.Windows.Forms.ContextMenuStrip contextMenu;
+        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
     }
 }
\ No newline at end of file
--- a/FrmNewUnitFromTree.cs	Sat Aug 20 16:12:15 2011 +0100
+++ b/FrmNewUnitFromTree.cs	Sat Aug 20 17:05:45 2011 +0100
@@ -55,7 +55,17 @@
 
         private void unitTypeTree_DoubleClick(object sender, EventArgs e)
         {
+            AddUnitType();
+        }
+
+        private void AddUnitType()
+        {
             TreeNode selected = unitTypeTree.SelectedNode;
+            AddUnitType(selected);
+        }
+
+        private void AddUnitType(TreeNode selected)
+        {
             object tagData = selected.Tag;
 
             if (tagData is UnitType)
@@ -71,5 +81,19 @@
             get { return (FrmMain)base.MdiParent; }
             set { base.MdiParent = value; }
         }
+
+        private void AddUnitClicked(object sender, EventArgs e)
+        {
+            //FIXME: We need to do some kind of maths here
+            // context menu position appears to be relative to the window, not the tree control!
+            int left = contextMenu.Left - unitTypeTree.Left;
+            int top = contextMenu.Top - unitTypeTree.Top;
+            TreeNode node = unitTypeTree.GetNodeAt(left, top);
+
+            if (node != null)
+            {
+                AddUnitType(node);
+            }
+        }
     }
 }
--- a/FrmNewUnitFromTree.resx	Sat Aug 20 16:12:15 2011 +0100
+++ b/FrmNewUnitFromTree.resx	Sat Aug 20 17:05:45 2011 +0100
@@ -117,4 +117,7 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
+  <metadata name="contextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
 </root>
\ No newline at end of file