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
;
25 BSSourceView
* _sourceView
;
27 NSArrayController
* __weak _arrayController
;
33 - (instancetype
)initWithBreakpointManager
:(BreakpointManager
*)breakpointManager
34 sourceView
:(BSSourceView
*)sourceView
36 if ((self = [super initWithNibName
:@
"Breakpoints" bundle
:nil])) {
37 _manager
= breakpointManager
;
38 _sourceView
= sourceView
;
45 [[self.addBreakpointButton cell
] setUsesItemFromMenu
:NO
];
46 [self.addBreakpointButton.cell setMenuItem
:[self.addBreakpointButton.menu itemAtIndex
:0]];
50 * Adds a breakpoint by calling up a file chooser and selecting a file for
53 - (IBAction
)addBreakpoint
:(id)sender
55 NSOpenPanel
* panel
= [NSOpenPanel openPanel
];
57 if ([panel runModal
] != NSOKButton
)
62 [_sourceView setFile
:[[panel URL
] path
]];
65 - (IBAction
)addFunctionBreakpoint
:(id)sender
67 [self.view.window beginSheet
:self.addFunctionBreakpointWindow completionHandler
:nil];
70 - (IBAction
)cancelFunctionBreakpoint
:(id)sender
72 [self.view.window endSheet
:self.addFunctionBreakpointWindow
];
75 - (IBAction
)saveFunctionBreakpoint
:(id)sender
77 [_manager addBreakpoint
:[Breakpoint breakpointOnFunctionNamed
:self.functionNameField.stringValue
]];
78 [self.view.window endSheet
:self.addFunctionBreakpointWindow
];
82 * Removes a breakpoint
84 - (IBAction
)removeBreakpoint
:(id)sender
86 NSArray
* selection
= [_arrayController selectedObjects
];
87 if ([selection count
] < 1)
90 Breakpoint
* bp
= [selection firstObject
];
91 [_manager removeBreakpoint
:bp
];
93 if (bp.type
== kBreakpointTypeFile
&& [_sourceView.file isEqualToString
:bp.file
]) {
94 NSSet
<NSNumber
*>* markers
= [_sourceView.markers objectsPassingTest
:^
BOOL(NSNumber
* obj
, BOOL* stop
) {
95 return obj.unsignedLongValue
!= bp.line
;
97 [_sourceView setMarkers
:markers
];
101 #pragma mark NSTableView Delegate
104 * NSTableView delegate method that informs the controller that the stack selection did change and that
105 * we should update the source viewer
107 - (void)tableViewSelectionDidChange
:(NSNotification
*)notif
109 NSArray
* selection
= [_arrayController selectedObjects
];
110 if ([selection count
] < 1) {
114 Breakpoint
* bp
= [selection objectAtIndex
:0];
115 if (bp.type
!= kBreakpointTypeFile
) {
119 [_sourceView setFile
:[bp file
]];
120 [_sourceView scrollToLine
:[bp line
]];
121 [_sourceView setMarkers
:[_manager breakpointsForFile
:bp.file
]];
122 [_sourceView setMarkedLine
:0];