Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DebugEngine/OperatorTraceView.cs @ 4925

Last change on this file since 4925 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: 3.5 KB
Line 
1using System;
2using System.Windows.Forms;
3using HeuristicLab.Collections;
4using HeuristicLab.Common.Resources;
5using HeuristicLab.Core;
6using HeuristicLab.Core.Views;
7using HeuristicLab.MainForm;
8using HeuristicLab.Operators;
9
10namespace HeuristicLab.DebugEngine {
11
12  [View("Operator Trace View")]
13  [Content(typeof(ItemList<IOperator>), IsDefaultView = true)]
14  public sealed partial class OperatorTraceView : ItemView {
15
16    public new ItemList<IOperator> Content {
17      get { return (ItemList<IOperator>)base.Content; }
18      set { base.Content = value; }
19    }
20
21    public OperatorTraceView() {
22      InitializeComponent();
23    }
24
25    protected override void DeregisterContentEvents() {
26      Content.CollectionReset -= Content_CollectionChanged;
27      Content.ItemsAdded -= Content_CollectionChanged;
28      Content.ItemsMoved -= Content_CollectionChanged;
29      Content.ItemsRemoved -= Content_CollectionChanged;
30      Content.ItemsReplaced -= Content_CollectionChanged;
31      base.DeregisterContentEvents();
32    }
33
34    protected override void RegisterContentEvents() {
35      base.RegisterContentEvents();
36      Content.CollectionReset += Content_CollectionChanged;
37      Content.ItemsAdded += Content_CollectionChanged;
38      Content.ItemsMoved += Content_CollectionChanged;
39      Content.ItemsRemoved += Content_CollectionChanged;
40      Content.ItemsReplaced += Content_CollectionChanged;
41    }
42
43    #region Event Handlers (Content)
44    void Content_CollectionChanged(object sender, CollectionItemsChangedEventArgs<Collections.IndexedItem<IOperator>> e) {
45      if (InvokeRequired)
46        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IOperator>>>(Content_CollectionChanged), sender, e);
47      else
48        UpdateOperatorTrace();
49    }
50    #endregion
51
52    private void UpdateOperatorTrace() {
53      if (suspended)
54        return;
55      listView.BeginUpdate();
56      listView.Items.Clear();
57      listView.SmallImageList.Images.Clear();
58      listView.SmallImageList.Images.Add(VS2008ImageLibrary.Method);
59      listView.SmallImageList.Images.Add(VS2008ImageLibrary.Module);
60      foreach (var item in Content) {
61        var viewItem = listView.Items.Add(item.Name ?? item.ItemName);
62        viewItem.ToolTipText = string.Format("{0}{1}{1}{2}",
63          Utils.TypeName(item), Environment.NewLine,
64          Utils.Wrap(item.Description, 60));
65        viewItem.Tag = item;
66        viewItem.ImageIndex = item is CombinedOperator ? 1 : 0;
67      }
68      if (listView.Items.Count > 0) {
69        for (int i = 0; i < listView.Columns.Count; i++)
70          listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
71      }
72      listView.EndUpdate();
73    }
74
75    protected override void OnContentChanged() {
76      base.OnContentChanged();
77      if (Content == null) {
78        listView.Items.Clear();
79      } else {
80        UpdateOperatorTrace();
81      }
82    }
83
84    #region Event Handlers (child controls)
85    private void listView_ItemActivate(object sender, EventArgs e) {
86      if (listView.SelectedItems.Count > 0) {
87        IOperator op = listView.SelectedItems[0].Tag as IOperator;
88        if (op != null) {
89          MainFormManager.MainForm.ShowContent(op);
90        }
91      }
92    }
93    #endregion
94
95    private bool suspended = false;
96    public void SuspendUpdate() {
97      suspended = true;
98    }
99    public void ResumeUpdate() {
100      suspended = false;
101      UpdateOperatorTrace();
102    }
103  }
104
105}
Note: See TracBrowser for help on using the repository browser.