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 diff
     1.1 --- a/FrmNewUnitFromTree.Designer.cs	Sat Aug 20 16:12:15 2011 +0100
     1.2 +++ b/FrmNewUnitFromTree.Designer.cs	Sat Aug 20 17:05:45 2011 +0100
     1.3 @@ -28,7 +28,11 @@
     1.4          /// </summary>
     1.5          private void InitializeComponent()
     1.6          {
     1.7 +            this.components = new System.ComponentModel.Container();
     1.8              this.unitTypeTree = new System.Windows.Forms.TreeView();
     1.9 +            this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
    1.10 +            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
    1.11 +            this.contextMenu.SuspendLayout();
    1.12              this.SuspendLayout();
    1.13              // 
    1.14              // unitTypeTree
    1.15 @@ -36,12 +40,28 @@
    1.16              this.unitTypeTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    1.17                          | System.Windows.Forms.AnchorStyles.Left)
    1.18                          | System.Windows.Forms.AnchorStyles.Right)));
    1.19 +            this.unitTypeTree.ContextMenuStrip = this.contextMenu;
    1.20              this.unitTypeTree.Location = new System.Drawing.Point(0, 0);
    1.21              this.unitTypeTree.Name = "unitTypeTree";
    1.22              this.unitTypeTree.Size = new System.Drawing.Size(199, 287);
    1.23              this.unitTypeTree.TabIndex = 0;
    1.24              this.unitTypeTree.DoubleClick += new System.EventHandler(this.unitTypeTree_DoubleClick);
    1.25              // 
    1.26 +            // contextMenu
    1.27 +            // 
    1.28 +            this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    1.29 +            this.toolStripMenuItem1});
    1.30 +            this.contextMenu.Name = "contextMenu";
    1.31 +            this.contextMenu.Size = new System.Drawing.Size(154, 26);
    1.32 +            // 
    1.33 +            // toolStripMenuItem1
    1.34 +            // 
    1.35 +            this.toolStripMenuItem1.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
    1.36 +            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
    1.37 +            this.toolStripMenuItem1.Size = new System.Drawing.Size(153, 22);
    1.38 +            this.toolStripMenuItem1.Text = "Add Unit Type";
    1.39 +            this.toolStripMenuItem1.Click += new System.EventHandler(this.AddUnitClicked);
    1.40 +            // 
    1.41              // FrmNewUnitFromTree
    1.42              // 
    1.43              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    1.44 @@ -52,6 +72,7 @@
    1.45              this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
    1.46              this.Name = "FrmNewUnitFromTree";
    1.47              this.Text = "Available Unit Types";
    1.48 +            this.contextMenu.ResumeLayout(false);
    1.49              this.ResumeLayout(false);
    1.50  
    1.51          }
    1.52 @@ -59,5 +80,7 @@
    1.53          #endregion
    1.54  
    1.55          private System.Windows.Forms.TreeView unitTypeTree;
    1.56 +        private System.Windows.Forms.ContextMenuStrip contextMenu;
    1.57 +        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
    1.58      }
    1.59  }
    1.60 \ No newline at end of file
     2.1 --- a/FrmNewUnitFromTree.cs	Sat Aug 20 16:12:15 2011 +0100
     2.2 +++ b/FrmNewUnitFromTree.cs	Sat Aug 20 17:05:45 2011 +0100
     2.3 @@ -55,7 +55,17 @@
     2.4  
     2.5          private void unitTypeTree_DoubleClick(object sender, EventArgs e)
     2.6          {
     2.7 +            AddUnitType();
     2.8 +        }
     2.9 +
    2.10 +        private void AddUnitType()
    2.11 +        {
    2.12              TreeNode selected = unitTypeTree.SelectedNode;
    2.13 +            AddUnitType(selected);
    2.14 +        }
    2.15 +
    2.16 +        private void AddUnitType(TreeNode selected)
    2.17 +        {
    2.18              object tagData = selected.Tag;
    2.19  
    2.20              if (tagData is UnitType)
    2.21 @@ -71,5 +81,19 @@
    2.22              get { return (FrmMain)base.MdiParent; }
    2.23              set { base.MdiParent = value; }
    2.24          }
    2.25 +
    2.26 +        private void AddUnitClicked(object sender, EventArgs e)
    2.27 +        {
    2.28 +            //FIXME: We need to do some kind of maths here
    2.29 +            // context menu position appears to be relative to the window, not the tree control!
    2.30 +            int left = contextMenu.Left - unitTypeTree.Left;
    2.31 +            int top = contextMenu.Top - unitTypeTree.Top;
    2.32 +            TreeNode node = unitTypeTree.GetNodeAt(left, top);
    2.33 +
    2.34 +            if (node != null)
    2.35 +            {
    2.36 +                AddUnitType(node);
    2.37 +            }
    2.38 +        }
    2.39      }
    2.40  }
     3.1 --- a/FrmNewUnitFromTree.resx	Sat Aug 20 16:12:15 2011 +0100
     3.2 +++ b/FrmNewUnitFromTree.resx	Sat Aug 20 17:05:45 2011 +0100
     3.3 @@ -117,4 +117,7 @@
     3.4    <resheader name="writer">
     3.5      <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     3.6    </resheader>
     3.7 +  <metadata name="contextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     3.8 +    <value>17, 17</value>
     3.9 +  </metadata>
    3.10  </root>
    3.11 \ No newline at end of file