Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DebugEngine/ExecutionStackView.cs @ 4949

Last change on this file since 4949 was 4909, checked in by epitzer, 14 years ago

Several GUI improvements (#47)

  • add icons and tool tips
  • add support for suspending the operator trace view
  • faster skipping of stack-only operations
  • remove log view and execution time view
File size: 5.0 KB
RevLine 
[4871]1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Windows.Forms;
6using HeuristicLab.Collections;
[4909]7using HeuristicLab.Common.Resources;
[4871]8using HeuristicLab.Core;
[4903]9using HeuristicLab.MainForm;
[4871]10using HeuristicLab.MainForm.WindowsForms;
11
12namespace HeuristicLab.DebugEngine {
13
14  [View("Execution Stack View")]
15  [Content(typeof(ExecutionStack), IsDefaultView = true)]
16  public partial class ExecutionStackView : AsynchronousContentView {
17    public new ExecutionStack Content {
18      get { return (ExecutionStack)base.Content; }
19      set { base.Content = value; }
20    }
21
22    public ExecutionStackView() {
23      InitializeComponent();
24    }
25
26    protected override void DeregisterContentEvents() {
27      Content.CollectionReset -= Content_Changed;
28      Content.ItemsAdded -= Content_Changed;
29      Content.ItemsRemoved -= Content_Changed;
30      Content.ItemsMoved -= Content_Changed;
31      Content.ItemsReplaced -= Content_Changed;
32      base.DeregisterContentEvents();
33    }
34
35    protected override void RegisterContentEvents() {
36      base.RegisterContentEvents();
37      Content.CollectionReset += Content_Changed;
38      Content.ItemsAdded += Content_Changed;
39      Content.ItemsRemoved += Content_Changed;
40      Content.ItemsMoved += Content_Changed;
41      Content.ItemsReplaced += Content_Changed;
42    }
43
44    #region Event Handlers (Content)
45    void Content_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperation>> e) {
46      if (InvokeRequired)
47        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IOperation>>>(Content_Changed), sender, e);
48      else
49        UpdateExecutionStack();
50    }
51
[4903]52
[4871]53    private void UpdateExecutionStack() {
[4909]54      if (suspended) {
55        groupBox.Text = string.Format("Execution Stack ({0})", CountOperations(Content));
56      } else {
[4871]57        treeView.BeginUpdate();
58        treeView.Nodes.Clear();
[4909]59        treeView.ImageList.Images.Clear();
60        treeView.ImageList.Images.Add(VS2008ImageLibrary.Method);
61        treeView.ImageList.Images.Add(VS2008ImageLibrary.Module);
[4871]62        int totalNodes = AddStackOperations(treeView.Nodes, ((IEnumerable<IOperation>)Content).Reverse());
63        if (treeView.Nodes.Count > 0)
64          treeView.TopNode = treeView.Nodes[0];
[4903]65        treeView.ExpandAll();
[4871]66        treeView.EndUpdate();
67        groupBox.Text = string.Format("Execution Stack ({0})", totalNodes);
68      }
69    }
70
71    private int CountOperations(IEnumerable<IOperation> operations) {
72      int count = 0;
73      foreach (IOperation op in operations) {
74        count++;
75        OperationCollection ops = op as OperationCollection;
76        if (ops != null)
77          count += CountOperations(ops);
78      }
79      return count;
80    }
81
82    private int AddStackOperations(TreeNodeCollection nodes, IEnumerable<IOperation> operations) {
83      int count = 0;
84      foreach (IOperation op in operations) {
85        if (op is IAtomicOperation) {
86          IAtomicOperation atom = op as IAtomicOperation;
[4909]87          TreeNode node = nodes.Add(atom.Operator.Name ?? atom.Operator.ItemName);
[4871]88          node.Tag = atom;
[4909]89          node.ToolTipText = string.Format("{0}{1}{1}{2}",
90            Utils.TypeName(atom.Operator), Environment.NewLine,
91            Utils.Wrap(atom.Operator.Description ?? atom.Operator.ItemDescription, 60));
92          node.ImageIndex = 0;
93          node.SelectedImageIndex = 0;
[4871]94          if (atom.Operator.Breakpoint)
95            node.ForeColor = Color.Red;
96          count++;
97        } else if (op is OperationCollection) {
98          OperationCollection ops = op as OperationCollection;
99          TreeNode node = treeView.Nodes.Add(
100            string.Format("{0} Operation{1}", ops.Count, ops.Count == 1 ? string.Empty : "s"));
101          node.Tag = op;
102          node.ToolTipText = Utils.TypeName(ops);
[4909]103          node.ImageIndex = 1;
104          node.SelectedImageIndex = 1;
[4871]105          count += AddStackOperations(node.Nodes, ops);
106        }
107      }
108      return count;
109    }
110    #endregion
111
112    protected override void OnContentChanged() {
113      base.OnContentChanged();
114      if (Content == null) {
115        treeView.Nodes.Clear();
116      } else {
117        UpdateExecutionStack();
118      }
119    }
120
121
122    protected override void SetEnabledStateOfControls() {
123      base.SetEnabledStateOfControls();
124    }
125
126    #region Event Handlers (child controls)
127    private void treeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
128      if (e.Node != null) {
129        IAtomicOperation op = e.Node.Tag as IAtomicOperation;
130        if (op != null)
131          MainFormManager.MainForm.ShowContent(op.Operator);
132      }
133    }
134    #endregion
135
136    #region Suspension
137    private bool suspended = false;
138    public virtual void SuspendUpdate() {
139      suspended = true;
140      treeView.Nodes.Clear();
141    }
142
143    public virtual void ResumeUpdate() {
144      suspended = false;
[4909]145      if (Content != null)
146        UpdateExecutionStack();
[4871]147    }
148    #endregion
149  }
150}
Note: See TracBrowser for help on using the repository browser.