Add backend Breakpoint support for symbolic breakpoints.
[macgdbp.git] / Source / BreakpointController.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 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 "BreakpointController.h"
18
19 #import "AppDelegate.h"
20 #import "PreferenceNames.h"
21
22 @implementation BreakpointController {
23 BreakpointManager* _manager;
24
25 BSSourceView* _sourceView;
26 NSArrayController* _arrayController;
27 }
28
29 /**
30 * Constructor
31 */
32 - (instancetype)initWithBreakpointManager:(BreakpointManager*)breakpointManager
33 sourceView:(BSSourceView*)sourceView
34 {
35 if ((self = [super initWithNibName:@"Breakpoints" bundle:nil])) {
36 _manager = breakpointManager;
37 _sourceView = sourceView;
38 }
39 return self;
40 }
41
42 /**
43 * Adds a breakpoint by calling up a file chooser and selecting a file for
44 * breaking in
45 */
46 - (IBAction)addBreakpoint:(id)sender
47 {
48 NSOpenPanel* panel = [NSOpenPanel openPanel];
49
50 if ([panel runModal] != NSOKButton)
51 {
52 return;
53 }
54
55 [_sourceView setFile:[[panel URL] path]];
56 }
57
58 /**
59 * Removes a breakpoint
60 */
61 - (IBAction)removeBreakpoint:(id)sender
62 {
63 NSArray* selection = [_arrayController selectedObjects];
64 if ([selection count] < 1)
65 {
66 return;
67 }
68
69 for (Breakpoint* bp in selection)
70 {
71 [_manager removeBreakpointAt:[bp line] inFile:[bp file]];
72 }
73 }
74
75 #pragma mark NSTableView Delegate
76
77 /**
78 * NSTableView delegate method that informs the controller that the stack selection did change and that
79 * we should update the source viewer
80 */
81 - (void)tableViewSelectionDidChange:(NSNotification*)notif
82 {
83 NSArray* selection = [_arrayController selectedObjects];
84 if ([selection count] < 1)
85 {
86 return;
87 }
88
89 Breakpoint* bp = [selection objectAtIndex:0];
90 [_sourceView setFile:[bp file]];
91 [_sourceView scrollToLine:[bp line]];
92 [_sourceView setMarkers:[_manager breakpointsForFile:bp.file]];
93 }
94
95 #pragma mark BSSourceView Delegate
96
97 /**
98 * Accepts a file dragged to set the contents of the display.
99 */
100 - (BOOL)sourceView:(BSSourceView*)sv acceptsDropOfFile:(NSString*)filename
101 {
102 return YES;
103 }
104
105 @end