Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/15 15:47:07 (10 years ago)
Author:
pfleck
Message:

#2025 Added context menu for expanding and collapsing nodes.

Location:
branches/NewItemDialog/HeuristicLab.Optimizer/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/NewItemDialog/HeuristicLab.Optimizer/3.3/NewItemDialog.Designer.cs

    r12205 r12206  
    6262      this.expandAllButton = new System.Windows.Forms.Button();
    6363      this.collapseAllButton = new System.Windows.Forms.Button();
     64      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     65      this.expandToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     66      this.expandAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     67      this.collapseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     68      this.collapseAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    6469      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    6570      this.splitContainer.Panel1.SuspendLayout();
     
    6873      this.availableItemsGroupBox.SuspendLayout();
    6974      this.descriptionGroupBox.SuspendLayout();
     75      this.contextMenuStrip.SuspendLayout();
    7076      this.SuspendLayout();
    7177      //
     
    167173      this.typesTreeView.VisibleChanged += new System.EventHandler(this.itemsTreeView_VisibleChanged);
    168174      this.typesTreeView.DoubleClick += new System.EventHandler(this.itemTreeView_DoubleClick);
     175      this.typesTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.typesTreeView_MouseDown);
    169176      //
    170177      // imageList
     
    246253      this.collapseAllButton.UseVisualStyleBackColor = true;
    247254      this.collapseAllButton.Click += new System.EventHandler(this.collapseAllButton_Click);
     255      //
     256      // contextMenuStrip
     257      //
     258      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     259            this.expandToolStripMenuItem,
     260            this.expandAllToolStripMenuItem,
     261            this.collapseToolStripMenuItem,
     262            this.collapseAllToolStripMenuItem});
     263      this.contextMenuStrip.Name = "contextMenuStrip";
     264      this.contextMenuStrip.Size = new System.Drawing.Size(153, 114);
     265      //
     266      // expandToolStripMenuItem
     267      //
     268      this.expandToolStripMenuItem.Name = "expandToolStripMenuItem";
     269      this.expandToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     270      this.expandToolStripMenuItem.Text = "Expand";
     271      this.expandToolStripMenuItem.Click += new System.EventHandler(this.expandToolStripMenuItem_Click);
     272      //
     273      // expandAllToolStripMenuItem
     274      //
     275      this.expandAllToolStripMenuItem.Name = "expandAllToolStripMenuItem";
     276      this.expandAllToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     277      this.expandAllToolStripMenuItem.Text = "Expand All";
     278      this.expandAllToolStripMenuItem.Click += new System.EventHandler(this.expandAllToolStripMenuItem_Click);
     279      //
     280      // collapseToolStripMenuItem
     281      //
     282      this.collapseToolStripMenuItem.Name = "collapseToolStripMenuItem";
     283      this.collapseToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     284      this.collapseToolStripMenuItem.Text = "Collapse";
     285      this.collapseToolStripMenuItem.Click += new System.EventHandler(this.collapseToolStripMenuItem_Click);
     286      //
     287      // collapseAllToolStripMenuItem
     288      //
     289      this.collapseAllToolStripMenuItem.Name = "collapseAllToolStripMenuItem";
     290      this.collapseAllToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
     291      this.collapseAllToolStripMenuItem.Text = "Collapse All";
     292      this.collapseAllToolStripMenuItem.Click += new System.EventHandler(this.collapseAllToolStripMenuItem_Click);
    248293      //
    249294      // NewItemDialog
     
    276321      this.descriptionGroupBox.ResumeLayout(false);
    277322      this.descriptionGroupBox.PerformLayout();
     323      this.contextMenuStrip.ResumeLayout(false);
    278324      this.ResumeLayout(false);
    279325
     
    297343    private System.Windows.Forms.TextBox versionTextBox;
    298344    private System.Windows.Forms.TextBox pluginTextBox;
     345    private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
     346    private System.Windows.Forms.ToolStripMenuItem expandToolStripMenuItem;
     347    private System.Windows.Forms.ToolStripMenuItem expandAllToolStripMenuItem;
     348    private System.Windows.Forms.ToolStripMenuItem collapseToolStripMenuItem;
     349    private System.Windows.Forms.ToolStripMenuItem collapseAllToolStripMenuItem;
    299350  }
    300351}
  • branches/NewItemDialog/HeuristicLab.Optimizer/3.3/NewItemDialog.cs

    r12205 r12206  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    101102    }
    102103    private void NewItemDialog_Shown(object sender, EventArgs e) {
    103       SelectedType = null;
     104      searchTextBox.Text = string.Empty;
     105      searchTextBox.Focus();
    104106    }
    105107
     
    263265      typesTreeView.CollapseAll();
    264266    }
     267
     268    private TreeNode toolStripMenuNode = null;
     269    private void typesTreeView_MouseDown(object sender, MouseEventArgs e) {
     270      if (e.Button == MouseButtons.Right) {
     271        Point coordinates = typesTreeView.PointToClient(Cursor.Position);
     272        toolStripMenuNode = typesTreeView.GetNodeAt(coordinates);
     273
     274        if (toolStripMenuNode != null && coordinates.X >= toolStripMenuNode.Bounds.Left &&
     275            coordinates.X <= toolStripMenuNode.Bounds.Right) {
     276          typesTreeView.SelectedNode = toolStripMenuNode;
     277
     278          expandToolStripMenuItem.Enabled =
     279            expandToolStripMenuItem.Visible = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
     280          collapseToolStripMenuItem.Enabled = collapseToolStripMenuItem.Visible = toolStripMenuNode.IsExpanded;
     281        } else {
     282          expandToolStripMenuItem.Enabled = expandToolStripMenuItem.Visible = false;
     283          collapseToolStripMenuItem.Enabled = collapseToolStripMenuItem.Visible = false;
     284        }
     285        expandAllToolStripMenuItem.Enabled =
     286          expandAllToolStripMenuItem.Visible =
     287            !typesTreeView.Nodes.OfType<TreeNode>().All(x => TreeNodeIsFullyExpanded(x));
     288        collapseAllToolStripMenuItem.Enabled =
     289          collapseAllToolStripMenuItem.Visible = typesTreeView.Nodes.OfType<TreeNode>().Any(x => x.IsExpanded);
     290        if (contextMenuStrip.Items.Cast<ToolStripMenuItem>().Any(item => item.Enabled))
     291          contextMenuStrip.Show(Cursor.Position);
     292      }
     293    }
     294    private bool TreeNodeIsFullyExpanded(TreeNode node) {
     295      return (node.Nodes.Count == 0) || (node.IsExpanded && node.Nodes.OfType<TreeNode>().All(x => TreeNodeIsFullyExpanded(x)));
     296    }
     297
     298    private void expandToolStripMenuItem_Click(object sender, EventArgs e) {
     299      if (toolStripMenuNode != null) toolStripMenuNode.ExpandAll();
     300    }
     301    private void expandAllToolStripMenuItem_Click(object sender, EventArgs e) {
     302      typesTreeView.ExpandAll();
     303    }
     304    private void collapseToolStripMenuItem_Click(object sender, EventArgs e) {
     305      if (toolStripMenuNode != null) toolStripMenuNode.Collapse();
     306    }
     307    private void collapseAllToolStripMenuItem_Click(object sender, EventArgs e) {
     308      typesTreeView.CollapseAll();
     309    }
    265310  }
    266311}
Note: See TracChangeset for help on using the changeset viewer.