File: LoadedClassChooser.cs

package info (click to toggle)
mono-tools 4.2-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 13,868 kB
  • sloc: cs: 100,909; sh: 3,845; makefile: 2,040; javascript: 1,557; xml: 126
file content (91 lines) | stat: -rw-r--r-- 2,667 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// LoadedClassChooser.cs created with MonoDevelop
// User: massi at 10:14 PMĀ 4/18/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using Gtk;

namespace Mono.Profiler
{
	public partial class LoadedClassChooser : Gtk.Dialog
	{
		IHeapItemSetStatisticsSubject result;
		public IHeapItemSetStatisticsSubject Result {
			get {
				return result;
			}
		}
		
		IHeapItemSetStatisticsBySubject currentSelection;
		
		LoadedClassChooser()
		{
			this.Build();
			HeapSnapshotExplorer.PrepareTreeViewForStatisticsDisplay (ClassList);
			ClassList.NodeSelection.Changed += new EventHandler (OnSelectionChanged);
			currentSelection = null;
		}
		
		void OnSelectionChanged (object o, System.EventArgs args) {
			Gtk.NodeSelection selection = (Gtk.NodeSelection) o;
			HeapSnapshotExplorer.StatisticsNode node = (HeapSnapshotExplorer.StatisticsNode) selection.SelectedNode;
			if (node != null) {
				currentSelection = node.Statistics;
			} else {
				currentSelection = null;
			}
		}
		
		void FillList (IHeapItemSetStatisticsBySubject[] statistics) {
			HeapSnapshotExplorer.FillTreeViewWithStatistics (ClassList, statistics);
			currentSelection = null;
		}

		protected virtual void OnCancel (object sender, System.EventArgs e)
		{
			result = null;
		}

		protected virtual void OnOK (object sender, System.EventArgs e)
		{
			if (currentSelection != null) {
				result = currentSelection.Subject;
			} else {
				result = null;
			}
		}
		
		static LoadedClassChooser chooser;
		
		static IHeapItemSetStatisticsSubject ChooseSubject (IHeapItemSetStatisticsBySubject[] subjects, string subjectName) {
			IHeapItemSetStatisticsSubject result;
			if (chooser == null) {
				chooser = new LoadedClassChooser ();
			}
			chooser.Title = "Choose " + subjectName;
			chooser.FillList (subjects);
			ResponseType response = (ResponseType) chooser.Run ();
			if (response == ResponseType.Ok) {
				result = chooser.result;
			} else {
				result = null;
			}
			chooser.Hide ();
			return result;
		}
		public static LoadedClass ChooseClass (IHeapItemSetStatisticsBySubject[] subjects) {
			IHeapItemSetStatisticsSubject result = ChooseSubject (subjects, "class");
			return result as LoadedClass;
		}
		public static LoadedMethod ChooseMethod (IHeapItemSetStatisticsBySubject[] subjects) {
			IHeapItemSetStatisticsSubject result = ChooseSubject (subjects, "method");
			return result as LoadedMethod;
		}
		public static StackTrace ChooseCallStack (IHeapItemSetStatisticsBySubject[] subjects) {
			IHeapItemSetStatisticsSubject result = ChooseSubject (subjects, "call stack");
			return result as StackTrace;
		}
	}
}