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