~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/ThreadsPad.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ThreadsPad.cs
 
2
//
 
3
// Author:
 
4
//   Alfonso Santos Luaces <asantosluaces@gmail.com>
 
5
//   Lluis Sanchez Gual <lluis@novell.com>
 
6
//
 
7
// Copyright (c) 2008 Alfonso Santos Luaces
 
8
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
 
9
//
 
10
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
11
// of this software and associated documentation files (the "Software"), to deal
 
12
// in the Software without restriction, including without limitation the rights
 
13
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
14
// copies of the Software, and to permit persons to whom the Software is
 
15
// furnished to do so, subject to the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be included in
 
18
// all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
21
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
22
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
23
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
24
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
25
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
26
// THE SOFTWARE.
 
27
 
 
28
 
 
29
using GLib;
 
30
using Gtk;
 
31
using GtkSharp;
 
32
 
 
33
using System;
 
34
using System.Text;
 
35
using System.IO;
 
36
using System.Collections;
 
37
using System.Globalization;
 
38
using System.Runtime.InteropServices;
 
39
 
 
40
using Stock = MonoDevelop.Core.Gui.Stock;
 
41
using MonoDevelop.Core;
 
42
using MonoDevelop.Core.Gui;
 
43
using MonoDevelop.Ide.Gui;
 
44
using MonoDevelop.Components;
 
45
 
 
46
using Mono.Debugging.Client;
 
47
 
 
48
 
 
49
namespace MonoDevelop.Debugger
 
50
{
 
51
        public class ThreadsPad : Gtk.ScrolledWindow, IPadContent
 
52
        {
 
53
                Gtk.TreeView tree;
 
54
                Gtk.TreeStore store;
 
55
                
 
56
                TreeViewState treeViewState;
 
57
                
 
58
                enum Columns
 
59
                {
 
60
                        Icon,
 
61
                        Id,
 
62
                        Name,
 
63
                        Object,
 
64
                        Weight,
 
65
                        Location
 
66
                }
 
67
                
 
68
                public ThreadsPad()
 
69
                {
 
70
                        this.ShadowType = ShadowType.In;
 
71
 
 
72
                        store = new TreeStore (typeof(string), typeof (string), typeof(string), typeof(object), typeof(int), typeof(string));
 
73
 
 
74
                        tree = new TreeView (store);
 
75
                        tree.RulesHint = true;
 
76
                        tree.HeadersVisible = true;
 
77
                        treeViewState = new TreeViewState (tree, (int)Columns.Object);
 
78
                        
 
79
                        TreeViewColumn col = new TreeViewColumn ();
 
80
                        CellRenderer crp = new CellRendererPixbuf ();
 
81
                        col.PackStart (crp, false);
 
82
                        col.AddAttribute (crp, "stock_id", (int) Columns.Icon);
 
83
                        tree.AppendColumn (col);
 
84
                                
 
85
                        TreeViewColumn FrameCol = new TreeViewColumn ();
 
86
                        CellRendererText frameRenderer = new CellRendererText ();
 
87
                        FrameCol.Title = GettextCatalog.GetString ("Id");
 
88
                        FrameCol.PackStart (frameRenderer, true);
 
89
                        FrameCol.AddAttribute (frameRenderer, "text", (int) Columns.Id);
 
90
                        FrameCol.AddAttribute (frameRenderer, "weight", (int) Columns.Weight);
 
91
                        FrameCol.Resizable = true;
 
92
                        FrameCol.Alignment = 0.0f;
 
93
                        tree.AppendColumn (FrameCol);
 
94
 
 
95
                        col = new TreeViewColumn ();
 
96
                        col.Title = GettextCatalog.GetString ("Name");
 
97
                        col.Resizable = true;
 
98
                        CellRenderer crt = new CellRendererText ();
 
99
                        col.PackStart (crt, false);
 
100
                        col.AddAttribute (crt, "text", (int) Columns.Name);
 
101
                        col.AddAttribute (crt, "weight", (int) Columns.Weight);
 
102
                        tree.AppendColumn (col);
 
103
 
 
104
                        col = new TreeViewColumn ();
 
105
                        col.Title = GettextCatalog.GetString ("Location");
 
106
                        col.Resizable = true;
 
107
                        crt = new CellRendererText ();
 
108
                        col.PackStart (crt, false);
 
109
                        col.AddAttribute (crt, "text", (int) Columns.Location);
 
110
                        col.AddAttribute (crt, "weight", (int) Columns.Weight);
 
111
                        tree.AppendColumn (col);
 
112
                        
 
113
                        Add (tree);
 
114
                        ShowAll ();
 
115
                        
 
116
                        UpdateDisplay ();
 
117
                        
 
118
                        tree.RowActivated += OnRowActivated;
 
119
                        DebuggingService.CallStackChanged += OnStackChanged;
 
120
                        DebuggingService.PausedEvent += OnDebuggerPaused;
 
121
                        DebuggingService.ResumedEvent += OnDebuggerResumed;
 
122
                        DebuggingService.StoppedEvent += OnDebuggerStopped;
 
123
                }
 
124
                
 
125
                public override void Dispose ()
 
126
                {
 
127
                        base.Dispose ();
 
128
                        DebuggingService.CallStackChanged -= OnStackChanged;
 
129
                        DebuggingService.PausedEvent -= OnDebuggerPaused;
 
130
                        DebuggingService.ResumedEvent -= OnDebuggerResumed;
 
131
                        DebuggingService.StoppedEvent -= OnDebuggerStopped;
 
132
                }
 
133
                
 
134
                void OnStackChanged (object s, EventArgs a)
 
135
                {
 
136
                        UpdateDisplay ();
 
137
                }
 
138
                
 
139
                void IPadContent.Initialize (IPadWindow window)
 
140
                {
 
141
                        window.Title = "Threads List";
 
142
                        window.Icon = Stock.OutputIcon;
 
143
                }
 
144
                
 
145
                public void UpdateDisplay ()
 
146
                {
 
147
                        treeViewState.Save ();
 
148
                        
 
149
                        store.Clear ();
 
150
                        
 
151
                        if (DebuggingService.DebuggerSession == null)
 
152
                                return;
 
153
                        
 
154
                        ProcessInfo[] currentProcesses = DebuggingService.DebuggerSession.GetPocesses ();
 
155
                        
 
156
                        if (currentProcesses.Length == 1) {
 
157
                                AppendThreads (TreeIter.Zero, currentProcesses [0]);
 
158
                        }
 
159
                        else {
 
160
                                foreach (ProcessInfo p in currentProcesses) {
 
161
                                        TreeIter it = store.AppendValues (null, p.Id.ToString (), p.Name, p, (int) Pango.Weight.Normal, "");
 
162
                                        AppendThreads (it, p);
 
163
                                }
 
164
                        }
 
165
                        tree.ExpandAll ();
 
166
                        
 
167
                        treeViewState.Load ();
 
168
                }
 
169
                
 
170
                void AppendThreads (TreeIter it, ProcessInfo p)
 
171
                {
 
172
                        ThreadInfo[] threads = p.GetThreads ();
 
173
                        Array.Sort (threads, delegate (ThreadInfo t1, ThreadInfo t2) {
 
174
                                return t1.Id.CompareTo (t2.Id);
 
175
                        });
 
176
                        foreach (ThreadInfo t in threads) {
 
177
                                ThreadInfo activeThread = DebuggingService.DebuggerSession.ActiveThread;
 
178
                                Pango.Weight wi = t == activeThread ? Pango.Weight.Bold : Pango.Weight.Normal;
 
179
                                string icon = t == activeThread ? Gtk.Stock.GoForward : null;
 
180
                                if (it.Equals (TreeIter.Zero))
 
181
                                        store.AppendValues (icon, t.Id.ToString (), t.Name, t, (int) wi, t.Location);
 
182
                                else
 
183
                                        store.AppendValues (it, icon, t.Id.ToString (), t.Name, t, (int) wi, t.Location);
 
184
                        }
 
185
                }
 
186
                
 
187
                void OnRowActivated (object s, Gtk.RowActivatedArgs args)
 
188
                {
 
189
                        TreeIter it;
 
190
                        tree.Selection.GetSelected (out it);
 
191
                        ThreadInfo t = store.GetValue (it, (int)Columns.Object) as ThreadInfo;
 
192
                        if (t != null)
 
193
                                DebuggingService.ActiveThread = t;
 
194
                }
 
195
                
 
196
                public Gtk.Widget Control {
 
197
                        get {
 
198
                                return this;
 
199
                        }
 
200
                }
 
201
 
 
202
                public string Id {
 
203
                        get { return "MonoDevelop.Debugger.ThreadsPad"; }
 
204
                }
 
205
 
 
206
                public string DefaultPlacement {
 
207
                        get { return "Bottom"; }
 
208
                }
 
209
 
 
210
                public void RedrawContent ()
 
211
                {
 
212
                        UpdateDisplay ();
 
213
                }
 
214
                
 
215
                void OnDebuggerPaused (object s, EventArgs a)
 
216
                {
 
217
                        Sensitive = true;
 
218
                }
 
219
                
 
220
                void OnDebuggerResumed (object s, EventArgs a)
 
221
                {
 
222
                        Sensitive = false;
 
223
                }
 
224
                
 
225
                void OnDebuggerStopped (object s, EventArgs a)
 
226
                {
 
227
                        Sensitive = false;
 
228
                }
 
229
        }
 
230
}