Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DebugEngine.Views/3.3/ExecutionStackView.cs @ 14194

Last change on this file since 14194 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Collections;
28using HeuristicLab.Common.Resources;
29using HeuristicLab.Core;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32
33namespace HeuristicLab.DebugEngine {
34
35  [View("Execution Stack View")]
36  [Content(typeof(ExecutionStack), IsDefaultView = true)]
37  public partial class ExecutionStackView : AsynchronousContentView {
38    public new ExecutionStack Content {
39      get { return (ExecutionStack)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public ExecutionStackView() {
44      InitializeComponent();
45    }
46
47    protected override void DeregisterContentEvents() {
48      Content.CollectionReset -= Content_Changed;
49      Content.ItemsAdded -= Content_Changed;
50      Content.ItemsRemoved -= Content_Changed;
51      Content.ItemsMoved -= Content_Changed;
52      Content.ItemsReplaced -= Content_Changed;
53      base.DeregisterContentEvents();
54    }
55
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.CollectionReset += Content_Changed;
59      Content.ItemsAdded += Content_Changed;
60      Content.ItemsRemoved += Content_Changed;
61      Content.ItemsMoved += Content_Changed;
62      Content.ItemsReplaced += Content_Changed;
63    }
64
65    #region Event Handlers (Content)
66    void Content_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperation>> e) {
67      if (InvokeRequired)
68        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IOperation>>>(Content_Changed), sender, e);
69      else
70        UpdateExecutionStack();
71    }
72
73
74    private void UpdateExecutionStack() {
75      treeView.BeginUpdate();
76      treeView.Nodes.Clear();
77      treeView.ImageList.Images.Clear();
78      treeView.ImageList.Images.Add(VSImageLibrary.Method);
79      treeView.ImageList.Images.Add(VSImageLibrary.Module);
80      treeView.ImageList.Images.Add(VSImageLibrary.BreakpointActive);
81      int totalNodes = AddStackOperations(treeView.Nodes, ((IEnumerable<IOperation>)Content).Reverse());
82      if (treeView.Nodes.Count > 0)
83        treeView.TopNode = treeView.Nodes[0];
84      treeView.ExpandAll();
85      treeView.EndUpdate();
86      groupBox.Text = string.Format("Execution Stack ({0})", totalNodes);
87    }
88
89    private int AddStackOperations(TreeNodeCollection nodes, IEnumerable<IOperation> operations) {
90      int count = 0;
91      foreach (IOperation op in operations) {
92        if (op is IAtomicOperation) {
93          IAtomicOperation atom = op as IAtomicOperation;
94          TreeNode node = nodes.Add(atom.Operator.Name ?? atom.Operator.ItemName);
95          node.Tag = atom;
96          node.ToolTipText = string.Format("{0}{1}{1}{2}",
97            Utils.TypeName(atom.Operator), Environment.NewLine,
98            Utils.Wrap(atom.Operator.Description ?? atom.Operator.ItemDescription, 60));
99          if (atom.Operator.Breakpoint) {
100            node.ForeColor = Color.Red;
101            node.ImageIndex = 2;
102            node.SelectedImageIndex = 2;
103          } else {
104            node.ImageIndex = 0;
105            node.SelectedImageIndex = 0;
106          }
107          count++;
108        } else if (op is OperationCollection) {
109          OperationCollection ops = op as OperationCollection;
110          TreeNode node = nodes.Add(
111            string.Format("{0} {2}Operation{1}",
112            ops.Count,
113            ops.Count == 1 ? string.Empty : "s",
114            ops.Parallel ? "Parallel " : string.Empty
115            ));
116          node.Tag = op;
117          node.ToolTipText = Utils.TypeName(ops);
118          node.ImageIndex = 1;
119          node.SelectedImageIndex = 1;
120          count += AddStackOperations(node.Nodes, ops);
121        }
122      }
123      return count;
124    }
125    #endregion
126
127    protected override void OnContentChanged() {
128      base.OnContentChanged();
129      if (Content == null) {
130        treeView.Nodes.Clear();
131      } else {
132        UpdateExecutionStack();
133      }
134    }
135
136
137    protected override void SetEnabledStateOfControls() {
138      base.SetEnabledStateOfControls();
139    }
140
141    #region Event Handlers (child controls)
142    private void treeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
143      if (e.Node != null) {
144        IAtomicOperation op = e.Node.Tag as IAtomicOperation;
145        if (op != null)
146          MainFormManager.MainForm.ShowContent(op.Operator);
147      }
148    }
149    #endregion
150  }
151}
Note: See TracBrowser for help on using the repository browser.