Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7274


Ignore:
Timestamp:
01/05/12 03:03:50 (13 years ago)
Author:
swagner
Message:

Added context menu items to expand or collapse all tree nodes in the ExperimentTreeView (#1726)

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

    r7259 r7274  
    4848      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
    4949      this.ExpandToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     50      this.ExpandAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5051      this.CollapseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     52      this.CollapseAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5153      this.EditNodeLabelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5254      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     
    222224            this.EditNodeLabelToolStripMenuItem,
    223225            this.ExpandToolStripMenuItem,
    224             this.CollapseToolStripMenuItem});
     226            this.ExpandAllToolStripMenuItem,
     227            this.CollapseToolStripMenuItem,
     228            this.CollapseAllToolStripMenuItem});
    225229      this.contextMenuStrip.Name = "contextMenuStrip";
    226230      this.contextMenuStrip.Size = new System.Drawing.Size(120, 48);
     
    233237      this.ExpandToolStripMenuItem.Click += new System.EventHandler(this.ExpandToolStripMenuItem_Click);
    234238      //
     239      // ExpandAllToolStripMenuItem
     240      //
     241      this.ExpandAllToolStripMenuItem.Name = "ExpandAllToolStripMenuItem";
     242      this.ExpandAllToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
     243      this.ExpandAllToolStripMenuItem.Text = "Expand All";
     244      this.ExpandAllToolStripMenuItem.Click += new System.EventHandler(this.ExpandAllToolStripMenuItem_Click);
     245      //
    235246      // CollapseToolStripMenuItem
    236247      //
     
    239250      this.CollapseToolStripMenuItem.Text = "Collapse";
    240251      this.CollapseToolStripMenuItem.Click += new System.EventHandler(this.CollapseToolStripMenuItem_Click);
     252      //
     253      // CollapseAllToolStripMenuItem
     254      //
     255      this.CollapseAllToolStripMenuItem.Name = "CollapseAllToolStripMenuItem";
     256      this.CollapseAllToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
     257      this.CollapseAllToolStripMenuItem.Text = "Collapse All";
     258      this.CollapseAllToolStripMenuItem.Click += new System.EventHandler(this.CollapseAllToolStripMenuItem_Click);
    241259      //
    242260      // EditNodeLabelToolStripMenuItem
     
    281299    private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
    282300    private System.Windows.Forms.ToolStripMenuItem ExpandToolStripMenuItem;
     301    private System.Windows.Forms.ToolStripMenuItem ExpandAllToolStripMenuItem;
    283302    private System.Windows.Forms.ToolStripMenuItem CollapseToolStripMenuItem;
     303    private System.Windows.Forms.ToolStripMenuItem CollapseAllToolStripMenuItem;
    284304    private System.Windows.Forms.ToolStripMenuItem EditNodeLabelToolStripMenuItem;
    285305
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.cs

    r7259 r7274  
    652652        SetEnabledStateOfControls();
    653653
    654         ExpandToolStripMenuItem.Enabled = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
    655         ExpandToolStripMenuItem.Visible = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
    656         CollapseToolStripMenuItem.Enabled = toolStripMenuNode.IsExpanded;
    657         CollapseToolStripMenuItem.Visible = toolStripMenuNode.IsExpanded;
    658         EditNodeLabelToolStripMenuItem.Enabled = !Locked && !ReadOnly && toolStripMenuNode.Tag != null && toolStripMenuNode.Tag is INamedItem && ((INamedItem)toolStripMenuNode.Tag).CanChangeName;
    659         EditNodeLabelToolStripMenuItem.Visible = !Locked && !ReadOnly && toolStripMenuNode.Tag != null && toolStripMenuNode.Tag is INamedItem && ((INamedItem)toolStripMenuNode.Tag).CanChangeName;
    660         if (contextMenuStrip.Items.Cast<ToolStripMenuItem>().Any(item => item.Enabled))
    661           contextMenuStrip.Show(Cursor.Position);
    662       }
     654        ExpandToolStripMenuItem.Enabled = ExpandToolStripMenuItem.Visible = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
     655        CollapseToolStripMenuItem.Enabled = CollapseToolStripMenuItem.Visible = toolStripMenuNode.IsExpanded;
     656        EditNodeLabelToolStripMenuItem.Enabled = EditNodeLabelToolStripMenuItem.Visible = !Locked && !ReadOnly && toolStripMenuNode.Tag != null && toolStripMenuNode.Tag is INamedItem && ((INamedItem)toolStripMenuNode.Tag).CanChangeName;
     657      } else {
     658        ExpandToolStripMenuItem.Enabled = ExpandToolStripMenuItem.Visible = false;
     659        CollapseToolStripMenuItem.Enabled = CollapseToolStripMenuItem.Visible = false;
     660        EditNodeLabelToolStripMenuItem.Enabled = EditNodeLabelToolStripMenuItem.Visible = false;
     661      }
     662      ExpandAllToolStripMenuItem.Enabled = ExpandAllToolStripMenuItem.Visible = !treeView.Nodes.OfType<TreeNode>().All(x => TreeNodeIsFullyExpanded(x));
     663      CollapseAllToolStripMenuItem.Enabled = CollapseAllToolStripMenuItem.Visible = treeView.Nodes.OfType<TreeNode>().Any(x => x.IsExpanded);
     664      if (contextMenuStrip.Items.Cast<ToolStripMenuItem>().Any(item => item.Enabled))
     665        contextMenuStrip.Show(Cursor.Position);
    663666    }
    664667
     
    681684      if (toolStripMenuNode != null) toolStripMenuNode.ExpandAll();
    682685    }
     686    private void ExpandAllToolStripMenuItem_Click(object sender, EventArgs e) {
     687      treeView.ExpandAll();
     688    }
    683689    private void CollapseToolStripMenuItem_Click(object sender, EventArgs e) {
    684690      if (toolStripMenuNode != null) toolStripMenuNode.Collapse();
     691    }
     692    private void CollapseAllToolStripMenuItem_Click(object sender, EventArgs e) {
     693      treeView.CollapseAll();
    685694    }
    686695    private void EditNodeLabelToolStripMenuItem_Click(object sender, EventArgs e) {
     
    723732            algorithm.Problem = problem;
    724733          }
    725         } catch (Exception ex) {
     734        }
     735        catch (Exception ex) {
    726736          ErrorHandling.ShowErrorDialog(this, ex);
    727737        }
     
    871881    }
    872882
     883    private bool TreeNodeIsFullyExpanded(TreeNode node) {
     884      return (node.Nodes.Count == 0) || (node.IsExpanded && node.Nodes.OfType<TreeNode>().All(x => TreeNodeIsFullyExpanded(x)));
     885    }
     886
    873887    private void RebuildImageList() {
    874888      if (InvokeRequired) {
Note: See TracChangeset for help on using the changeset viewer.