Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6517 for trunk/sources


Ignore:
Timestamp:
07/06/11 17:01:30 (13 years ago)
Author:
mkommend
Message:

#1555: Implemented context menu to collapse & expand nodes.

Location:
trunk/sources/HeuristicLab.Optimization.Views/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.Designer.cs

    r6496 r6517  
    3434    private void InitializeComponent() {
    3535      this.components = new System.ComponentModel.Container();
     36      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExperimentTreeView));
    3637      this.optimizersGroupBox = new System.Windows.Forms.GroupBox();
    3738      this.splitContainer = new System.Windows.Forms.SplitContainer();
     
    4142      this.moveDownButton = new System.Windows.Forms.Button();
    4243      this.addButton = new System.Windows.Forms.Button();
    43       this.optimizerTreeView = new System.Windows.Forms.TreeView();
     44      this.optimizerTreeView = new HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView();
    4445      this.imageList = new System.Windows.Forms.ImageList(this.components);
    4546      this.detailsGroupBox = new System.Windows.Forms.GroupBox();
    4647      this.detailsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     48      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     49      this.ExpandToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     50      this.CollapseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    4751      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    4852      this.optimizersGroupBox.SuspendLayout();
     
    5256      this.splitContainer.SuspendLayout();
    5357      this.detailsGroupBox.SuspendLayout();
     58      this.contextMenuStrip.SuspendLayout();
    5459      this.SuspendLayout();
    5560      //
     
    163168      this.optimizerTreeView.TabIndex = 10;
    164169      this.optimizerTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.optimizerTreeView_ItemDrag);
     170      this.optimizerTreeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeview_NodeMouseClick);
     171      this.optimizerTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeView_NodeMouseDoubleClick);
    165172      this.optimizerTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragDrop);
    166173      this.optimizerTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragEnter);
     
    168175      this.optimizerTreeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.optimizerTreeView_KeyDown);
    169176      this.optimizerTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.optimizerTreeView_MouseDown);
    170       this.optimizerTreeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeview_NodeMouseClick);
    171       this.optimizerTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(optimizerTreeView_NodeMouseDoubleClick);
     177      this.optimizerTreeView.RightClick += new System.EventHandler(optimizerTreeView_RightClick);
    172178      //
    173179      // imageList
     
    206212      this.detailsViewHost.ViewType = null;
    207213      //
     214      // contextMenuStrip
     215      //
     216      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     217            this.ExpandToolStripMenuItem,
     218            this.CollapseToolStripMenuItem});
     219      this.contextMenuStrip.Name = "contextMenuStrip";
     220      this.contextMenuStrip.Size = new System.Drawing.Size(120, 48);
     221      //
     222      // ExpandToolStripMenuItem
     223      //
     224      this.ExpandToolStripMenuItem.Name = "ExpandToolStripMenuItem";
     225      this.ExpandToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
     226      this.ExpandToolStripMenuItem.Text = "Expand";
     227      this.ExpandToolStripMenuItem.Click += new System.EventHandler(this.ExpandToolStripMenuItem_Click);
     228      //
     229      // CollapseToolStripMenuItem
     230      //
     231      this.CollapseToolStripMenuItem.Name = "CollapseToolStripMenuItem";
     232      this.CollapseToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
     233      this.CollapseToolStripMenuItem.Text = "Collapse";
     234      this.CollapseToolStripMenuItem.Click += new System.EventHandler(this.CollapseToolStripMenuItem_Click);
     235      //
    208236      // ExperimentTreeView
    209237      //
     
    219247      this.splitContainer.ResumeLayout(false);
    220248      this.detailsGroupBox.ResumeLayout(false);
     249      this.contextMenuStrip.ResumeLayout(false);
    221250      this.ResumeLayout(false);
    222251
     
    226255    private System.Windows.Forms.GroupBox optimizersGroupBox;
    227256    private System.Windows.Forms.SplitContainer splitContainer;
    228     private System.Windows.Forms.TreeView optimizerTreeView;
     257    private HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView optimizerTreeView;
    229258    private System.Windows.Forms.GroupBox detailsGroupBox;
    230259    private MainForm.WindowsForms.ViewHost detailsViewHost;
     
    236265    private System.Windows.Forms.Button addButton;
    237266    private System.Windows.Forms.ImageList imageList;
     267    private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
     268    private System.Windows.Forms.ToolStripMenuItem ExpandToolStripMenuItem;
     269    private System.Windows.Forms.ToolStripMenuItem CollapseToolStripMenuItem;
    238270
    239271  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.cs

    r6513 r6517  
    498498    #region control events
    499499    private void optimizerTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
     500      if (rightClickOccured) return;
    500501      if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return;
    501       optimizerTreeView.SelectedNode.Toggle();
     502      e.Node.Toggle();
    502503      IOptimizer optimizer = (IOptimizer)e.Node.Tag;
    503504      MainFormManager.MainForm.ShowContent(optimizer);
     
    511512    private void optimizerTreeView_MouseDown(object sender, MouseEventArgs e) {
    512513      // enables deselection of treeNodes
    513       if (e.Button != System.Windows.Forms.MouseButtons.Left) return;
     514      if (e.Button != MouseButtons.Right) rightClickOccured = false;
    514515      if (optimizerTreeView.SelectedNode == null) return;
    515516      Point coordinates = new Point(e.X, e.Y);
     
    522523    }
    523524
     525
    524526    private void optimizerTreeView_KeyDown(object sender, KeyEventArgs e) {
    525527      if (ReadOnly) return;
     
    542544      UpdateDetailsViewHost();
    543545      RebuildImageList();
     546    }
     547
     548    private bool rightClickOccured = true;
     549    private TreeNode toolStripMenuNode = null;
     550    private void optimizerTreeView_RightClick(object sender, EventArgs e) {
     551      rightClickOccured = true;
     552      Point coordinates = optimizerTreeView.PointToClient(Cursor.Position);
     553      toolStripMenuNode = optimizerTreeView.GetNodeAt(coordinates);
     554
     555      if (toolStripMenuNode != null && coordinates.X >= toolStripMenuNode.Bounds.Left && coordinates.X <= toolStripMenuNode.Bounds.Right) {
     556        optimizerTreeView.SelectedNode = toolStripMenuNode;
     557        detailsViewHost.Content = (IContent)toolStripMenuNode.Tag;
     558        SetEnabledStateOfControls();
     559
     560        ExpandToolStripMenuItem.Enabled = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
     561        ExpandToolStripMenuItem.Visible = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
     562        CollapseToolStripMenuItem.Enabled = toolStripMenuNode.IsExpanded;
     563        CollapseToolStripMenuItem.Visible = toolStripMenuNode.IsExpanded;
     564        if (contextMenuStrip.Items.Cast<ToolStripMenuItem>().Any(item => item.Enabled))
     565          contextMenuStrip.Show(Cursor.Position);
     566      }
     567    }
     568
     569    private void ExpandToolStripMenuItem_Click(object sender, EventArgs e) {
     570      if (toolStripMenuNode != null) toolStripMenuNode.ExpandAll();
     571    }
     572    private void CollapseToolStripMenuItem_Click(object sender, EventArgs e) {
     573      if (toolStripMenuNode != null) toolStripMenuNode.Collapse();
    544574    }
    545575
     
    689719    }
    690720    #endregion
     721
     722
     723    public sealed class CustomTreeView : System.Windows.Forms.TreeView {
     724      protected override void WndProc(ref System.Windows.Forms.Message m) {
     725        const int WM_RBUTTONDOWN = 0x204;
     726        if (m.Msg == WM_RBUTTONDOWN) {
     727          //Raise your custom event right click event to prevent node highlighting
     728          OnRightClick();
     729          return;
     730        }
     731        base.WndProc(ref m);
     732      }
     733
     734      public event EventHandler RightClick;
     735      private void OnRightClick() {
     736        var handler = RightClick;
     737        if (handler != null) RightClick(this, EventArgs.Empty);
     738      }
     739    }
    691740  }
    692741}
Note: See TracChangeset for help on using the changeset viewer.