]> src.bluestatic.org Git - macgdbp.git/blob - Source/EvalController.m
Fix a silly memory bug where MessageQueue._message was autoreleased.
[macgdbp.git] / Source / EvalController.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2011, 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 "EvalController.h"
18
19 #import "DebuggerBackEnd.h"
20
21 static EvalController* g_activeEvalController = nil;
22
23 @implementation EvalController
24
25 @synthesize dataField = dataField_;
26 @synthesize resultField = resultField_;
27
28 - (id)initWithBackEnd:(DebuggerBackEnd*)backEnd
29 {
30 if (self = [super initWithWindowNibName:@"Eval"]) {
31 backEnd_ = backEnd;
32 }
33 return self;
34 }
35
36 - (void)dealloc
37 {
38 self.dataField = nil;
39 self.resultField = nil;
40 [super dealloc];
41 }
42
43 - (void)runModalForWindow:(NSWindow*)parent
44 {
45 assert(!g_activeEvalController);
46 g_activeEvalController = self;
47 [NSApp beginSheet:[self window]
48 modalForWindow:parent
49 modalDelegate:self
50 didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
51 contextInfo:nil];
52 }
53
54 - (void)sheetDidEnd:(NSWindow*)sheet
55 returnCode:(NSInteger)returnCode
56 contextInfo:(void*)contextInfo
57 {
58 g_activeEvalController = nil;
59 [self autorelease];
60 }
61
62 - (IBAction)evaluateScript:(id)sender
63 {
64 NSString* code = [self.dataField stringValue];
65 [backEnd_ evalScript:code];
66 }
67
68 - (IBAction)closeWindow:(id)sender
69 {
70 [self close];
71 [NSApp endSheet:[self window]];
72 }
73
74 + (void)scriptWasEvaluatedWithResult:(NSString*)result
75 {
76 [g_activeEvalController.resultField setStringValue:result];
77 }
78
79 @end