Styling the NSTextView source viewer to be a fixed-width font and to have a horizonta...
[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 * Before the display get's comfortable, set up the NSTextView to scroll horizontally
42 */
43 - (void)awakeFromNib
44 {
45 // set up the scroller for the source viewer
46 [_sourceViewer setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
47 [[_sourceViewer textContainer] setContainerSize: NSMakeSize(FLT_MAX, FLT_MAX)];
48 [[_sourceViewer textContainer] setWidthTracksTextView: NO];
49 [_sourceViewer setHorizontallyResizable: YES];
50 [_sourceViewerScroller setHasHorizontalScroller: YES];
51 [_sourceViewerScroller display];
52 }
53
54 /**
55 * Release object members
56 */
57 - (void)dealloc
58 {
59 [_connection release];
60
61 [super dealloc];
62 }
63
64 /**
65 * Sets the status and clears any error message
66 */
67 - (void)setStatus: (NSString *)status
68 {
69 [_error setHidden: YES];
70 [_status setStringValue: status];
71 [[self window] setTitle: [NSString stringWithFormat: @"GDBp @ %@:%d/%@", [_connection remoteHost], [_connection port], [_connection session]]];
72 }
73
74 /**
75 * Sets the status to be "Error" and then displays the error message
76 */
77 - (void)setError: (NSString *)error
78 {
79 [_error setStringValue: error];
80 [self setStatus: @"Error"];
81 [_error setHidden: NO];
82 }
83
84 /**
85 * Sets the root node element of the stacktrace
86 */
87 - (void)setStack: (NSArray *)stack
88 {
89 if (_stack != nil)
90 {
91 [_stack release];
92 }
93
94 _stack = stack;
95 [_stack retain];
96 }
97
98 /**
99 * Forwards the message to run script execution to the connection
100 */
101 - (IBAction)run: (id)sender
102 {
103 [_connection run];
104 }
105
106 /**
107 * Forwards the message to "step in" to the connection
108 */
109 - (IBAction)stepIn: (id)sender
110 {
111 [_connection stepIn];
112 }
113
114 /**
115 * Forwards the message to "step out" to the connection
116 */
117 - (IBAction)stepOut: (id)sender
118 {
119 [_connection stepOut];
120 }
121
122 /**
123 * Forwards the message to "step over" to the connection
124 */
125 - (IBAction)stepOver: (id)sender
126 {
127 [_connection stepOver];
128 }
129
130 /**
131 * NSTableView delegate method that informs the controller that the stack selection did change and that
132 * we should update the source viewer
133 */
134 - (void)tableViewSelectionDidChange: (NSNotification *)notif
135 {
136 [self updateSourceViewer];
137 }
138 /**
139 * Does the actual updating of the source viewer by reading in the file
140 */
141 - (void)updateSourceViewer
142 {
143 NSString *filename = [[_stackController selection] valueForKey: @"filename"];
144 if (filename == NSNoSelectionMarker)
145 {
146 _currentFile = nil;
147 [_sourceViewer setString: @""];
148 return;
149 }
150
151 filename = [[NSURL URLWithString: filename] path];
152 if (filename == _currentFile)
153 {
154 return;
155 }
156
157 _currentFile = filename;
158 [_sourceViewer setString: [NSString stringWithContentsOfFile: _currentFile]];
159 [_sourceViewer setFont: [NSFont fontWithName: @"Monaco" size: 10.0]];
160 }
161
162 @end