3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import "BreakpointController.h"
19 #import "AppDelegate.h"
20 #import "PreferenceNames.h"
22 @implementation BreakpointController
{
23 BreakpointManager
* _manager
;
24 Breakpoint
* _selection
;
26 BSSourceView
* _sourceView
;
28 NSArrayController
* __weak _arrayController
;
34 - (instancetype
)initWithBreakpointManager
:(BreakpointManager
*)breakpointManager
35 sourceView
:(BSSourceView
*)sourceView
37 if ((self = [super initWithNibName
:@
"Breakpoints" bundle
:nil])) {
38 _manager
= breakpointManager
;
39 _sourceView
= sourceView
;
46 [[self.addBreakpointButton cell
] setUsesItemFromMenu
:NO
];
47 [self.addBreakpointButton.cell setMenuItem
:[self.addBreakpointButton.menu itemAtIndex
:0]];
51 * Adds a breakpoint by calling up a file chooser and selecting a file for
54 - (IBAction
)addBreakpoint
:(id)sender
56 NSOpenPanel
* panel
= [NSOpenPanel openPanel
];
58 if ([panel runModal
] != NSOKButton
)
63 [_sourceView setFile
:[[panel URL
] path
]];
66 - (IBAction
)addFunctionBreakpoint
:(id)sender
68 [self.view.window beginSheet
:self.addFunctionBreakpointWindow completionHandler
:nil];
71 - (IBAction
)cancelFunctionBreakpoint
:(id)sender
73 [self.view.window endSheet
:self.addFunctionBreakpointWindow
];
76 - (IBAction
)saveFunctionBreakpoint
:(id)sender
78 [_manager addBreakpoint
:[Breakpoint breakpointOnFunctionNamed
:self.functionNameField.stringValue
]];
79 [self.view.window endSheet
:self.addFunctionBreakpointWindow
];
83 * Removes a breakpoint
85 - (IBAction
)removeBreakpoint
:(id)sender
87 NSArray
* selection
= [_arrayController selectedObjects
];
88 if ([selection count
] < 1)
93 for (Breakpoint
* bp
in selection
) {
94 [_manager removeBreakpoint
:bp
];
98 #pragma mark NSTableView Delegate
101 * NSTableView delegate method that informs the controller that the stack selection did change and that
102 * we should update the source viewer
104 - (void)tableViewSelectionDidChange
:(NSNotification
*)notif
106 if (_selection.type
== kBreakpointTypeFile
) {
107 [_selection stopSecureFileAccess
];
111 NSArray
* selection
= [_arrayController selectedObjects
];
112 if ([selection count
] < 1) {
113 [_sourceView setString
:@
"" asFile
:nil];
114 [_sourceView setMarkers
:[NSSet set
]];
118 _selection
= [selection objectAtIndex
:0];
119 if (_selection.type
!= kBreakpointTypeFile
) {
123 [_selection startSecureFileAccess
];
125 [_sourceView setFile
:[_selection file
]];
126 [_sourceView scrollToLine
:[_selection line
]];
127 [_sourceView setMarkers
:[_manager breakpointsForFile
:_selection.file
]];