Revert "Add drag and drop for the table 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 #import "AppDelegate.h"
19
20
21 @implementation BreakpointController
22
23 @synthesize tableView = tableView_;
24 @synthesize arrayController = arrayController_;
25 @synthesize sourceView = sourceView_;
26
27 /**
28 * Constructor
29 */
30 - (id)init
31 {
32 if (self = [super initWithWindowNibName:@"Breakpoints"])
33 {
34 manager = [BreakpointManager sharedManager];
35 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"BreakpointsWindowVisible"])
36 [[self window] orderBack:nil];
37 }
38 return self;
39 }
40
41 /**
42 * Awake from NIB.
43 */
44 - (void)awakeFromNib
45 {
46 }
47
48 /**
49 * Adds a breakpoint by calling up a file chooser and selecting a file for
50 * breaking in
51 */
52 - (IBAction)addBreakpoint:(id)sender
53 {
54 NSOpenPanel* panel = [NSOpenPanel openPanel];
55
56 if ([panel runModal] != NSOKButton)
57 return;
58
59 [sourceView_ setFile:[panel filename]];
60 }
61
62 /**
63 * Removes a breakpoint
64 */
65 - (IBAction)removeBreakpoint:(id)sender
66 {
67 NSArray* selection = [arrayController_ selectedObjects];
68 if ([selection count] < 1)
69 return;
70
71 for (Breakpoint* bp in selection)
72 [manager removeBreakpointAt:[bp line] inFile:[bp file]];
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 return;
86
87 Breakpoint* bp = [selection objectAtIndex:0];
88 [sourceView_ setFile:[bp file]];
89 [sourceView_ scrollToLine:[bp line]];
90 [[sourceView_ numberView] setMarkers:[NSSet setWithArray:[manager breakpointsForFile:[bp file]]]];
91 }
92
93 #pragma mark NSTableView Data Source
94
95 /**
96 * Handles the beginning of a drag operation.
97 */
98 - (BOOL)tableView:(NSTableView*)aTableView
99 writeRowsWithIndexes:(NSIndexSet*)rowIndexes
100 toPasteboard:(NSPasteboard*)pboard
101 {
102 }
103
104 /**
105 * Validates the drag operation.
106 */
107 - (NSDragOperation)tableView:(NSTableView*)aTableView
108 validateDrop:(id<NSDraggingInfo>)info
109 proposedRow:(NSInteger)row
110 proposedDropOperation:(NSTableViewDropOperation)operation
111 {
112 }
113
114 /**
115 * Incorporates the dropped data.
116 */
117 - (BOOL)tableView:(NSTableView*)aTableView
118 acceptDrop:(id<NSDraggingInfo>)info
119 row:(NSInteger)row
120 dropOperation:(NSTableViewDropOperation)operation
121 {
122 }
123
124 #pragma mark BSSourceView Delegate
125
126 /**
127 * The gutter was clicked, which indicates that a breakpoint needs to be changed
128 */
129 - (void)gutterClickedAtLine:(int)line forFile:(NSString*)file
130 {
131 if ([manager hasBreakpointAt:line inFile:file]) {
132 [manager removeBreakpointAt:line inFile:file];
133 } else {
134 Breakpoint* bp = [[Breakpoint alloc] initWithLine:line inFile:file];
135 [manager addBreakpoint:bp];
136 [bp release];
137 }
138
139 [[sourceView_ numberView] setMarkers:[NSSet setWithArray:[manager breakpointsForFile:file]]];
140 [[sourceView_ numberView] setNeedsDisplay:YES];
141 }
142
143 @end