Starting to implement the source viewer pane
[macgdbp.git] / Source / DebuggerWindowController.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2002 - 2007, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "DebuggerWindowController.h"
18 #import "DebuggerConnection.h"
19
20 @interface DebuggerWindowController (Private)
21
22 - (void)updateSourceViewer;
23
24 @end
25
26 @implementation DebuggerWindowController
27
28 /**
29 * Initializes the window controller and sets the connection
30 */
31 - (id)initWithConnection: (DebuggerConnection *)cnx
32 {
33 if (self = [super initWithWindowNibName: @"Debugger"])
34 {
35 _connection = [cnx retain];
36 }
37 return self;
38 }
39
40 /**
41 * Release object members
42 */
43 - (void)dealloc
44 {
45 [_connection release];
46
47 [super dealloc];
48 }
49
50 /**
51 * Sets the status and clears any error message
52 */
53 - (void)setStatus: (NSString *)status
54 {
55 [_error setHidden: YES];
56 [_status setStringValue: status];
57 [[self window] setTitle: [NSString stringWithFormat: @"GDBp @ %@:%d/%@", [_connection remoteHost], [_connection port], [_connection session]]];
58 }
59
60 /**
61 * Sets the status to be "Error" and then displays the error message
62 */
63 - (void)setError: (NSString *)error
64 {
65 [_error setStringValue: error];
66 [self setStatus: @"Error"];
67 [_error setHidden: NO];
68 }
69
70 /**
71 * Sets the root node element of the stacktrace
72 */
73 - (void)setStack: (NSArray *)stack
74 {
75 if (_stack != nil)
76 {
77 [_stack release];
78 }
79
80 _stack = stack;
81 [_stack retain];
82 }
83
84 /**
85 * Forwards the message to run script execution to the connection
86 */
87 - (IBAction)run: (id)sender
88 {
89 [_connection run];
90 }
91
92 /**
93 * Forwards the message to "step in" to the connection
94 */
95 - (IBAction)stepIn: (id)sender
96 {
97 [_connection stepIn];
98 }
99
100 /**
101 * Forwards the message to "step out" to the connection
102 */
103 - (IBAction)stepOut: (id)sender
104 {
105 [_connection stepOut];
106 }
107
108 /**
109 * Forwards the message to "step over" to the connection
110 */
111 - (IBAction)stepOver: (id)sender
112 {
113 [_connection stepOver];
114 }
115
116 /**
117 * NSTableView delegate method that informs the controller that the stack selection did change and that
118 * we should update the source viewer
119 */
120 - (void)tableViewSelectionDidChange: (NSNotification *)notif
121 {
122 [self updateSourceViewer];
123 }
124
125 /**
126 * Does the actual updating of the source viewer by reading in the file
127 */
128 - (void)updateSourceViewer
129 {
130 NSString *filename = [[_stackController selection] valueForKey: @"filename"];
131 if (filename == NSNoSelectionMarker)
132 {
133 _currentFile = nil;
134 return;
135 }
136
137 filename = [[NSURL URLWithString: filename] path];
138 if (filename == _currentFile)
139 {
140 return;
141 }
142
143 _currentFile = filename;
144 [_sourceViewer setString: [NSString stringWithContentsOfFile: _currentFile]];
145 }
146
147 @end