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"
18 #import "AppDelegate.h"
21 @implementation BreakpointController
23 @synthesize tableView
= tableView_
;
24 @synthesize arrayController
= arrayController_
;
25 @synthesize sourceView
= sourceView_
;
32 if (self = [super initWithWindowNibName
:@
"Breakpoints"])
34 manager
= [BreakpointManager sharedManager
];
35 if ([[NSUserDefaults standardUserDefaults
] boolForKey
:@
"BreakpointsWindowVisible"])
36 [[self window
] orderBack
:nil];
46 NSArray
* dragTypes
= [NSArray arrayWithObject
:NSFilenamesPboardType
];
47 [tableView_ registerForDraggedTypes
:dragTypes
];
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
)
61 [sourceView_ setFile
:[panel filename
]];
65 * Removes a breakpoint
67 - (IBAction
)removeBreakpoint
:(id)sender
69 NSArray
* selection
= [arrayController_ selectedObjects
];
70 if ([selection count
] < 1)
73 for (Breakpoint
* bp
in selection
)
74 [manager removeBreakpointAt
:[bp line
] inFile
:[bp file
]];
77 #pragma mark NSTableView Delegate
80 * NSTableView delegate method that informs the controller that the stack selection did change and that
81 * we should update the source viewer
83 - (void)tableViewSelectionDidChange
:(NSNotification
*)notif
85 NSArray
* selection
= [arrayController_ selectedObjects
];
86 if ([selection count
] < 1)
89 Breakpoint
* bp
= [selection objectAtIndex
:0];
90 [sourceView_ setFile
:[bp file
]];
92 [sourceView_ scrollToLine
:[bp line
]];
93 [[sourceView_ numberView
] setMarkers
:[NSSet setWithArray
:[manager breakpointsForFile
:[bp file
]]]];
96 #pragma mark NSTableView Data Source
99 * Handles the beginning of a drag operation.
101 - (BOOL)tableView
:(NSTableView
*)aTableView
102 writeRowsWithIndexes
:(NSIndexSet
*)rowIndexes
103 toPasteboard
:(NSPasteboard
*)pboard
106 return [[pboard types
] containsObject
:NSFilenamesPboardType
];
110 * Validates the drag operation.
112 - (NSDragOperation
)tableView
:(NSTableView
*)aTableView
113 validateDrop
:(id<NSDraggingInfo
>)info
114 proposedRow
:(NSInteger
)row
115 proposedDropOperation
:(NSTableViewDropOperation
)operation
118 NSPasteboard
* pboard
= [info draggingPasteboard
];
119 if ([[pboard types
] containsObject
:NSFilenamesPboardType
]) {
120 NSArray
* files
= [pboard propertyListForType
:NSFilenamesPboardType
];
122 return NSDragOperationGeneric
;
124 return NSDragOperationNone
;
128 * Incorporates the dropped data.
130 - (BOOL)tableView
:(NSTableView
*)aTableView
131 acceptDrop
:(id<NSDraggingInfo
>)info
133 dropOperation
:(NSTableViewDropOperation
)operation
136 BOOL valid
= [self tableView
:aTableView
139 proposedDropOperation
:operation
] == NSDragOperationGeneric
;
141 NSPasteboard
* pboard
= [info draggingPasteboard
];
142 NSArray
* files
= [pboard propertyListForType
:NSFilenamesPboardType
];
143 for (NSString
* file
in files
) {
144 Breakpoint
* bp
= [[[Breakpoint alloc
] initWithLine
:0 inFile
:file
] autorelease
];
145 [manager addBreakpoint
:bp
];
152 #pragma mark BSSourceView Delegate
155 * The gutter was clicked, which indicates that a breakpoint needs to be changed
157 - (void)gutterClickedAtLine
:(int)line forFile
:(NSString
*)file
159 if ([manager hasBreakpointAt
:line inFile
:file
]) {
160 [manager removeBreakpointAt
:line inFile
:file
];
162 Breakpoint
* bp
= [[Breakpoint alloc
] initWithLine
:line inFile
:file
];
163 [manager addBreakpoint
:bp
];
167 [[sourceView_ numberView
] setMarkers
:[NSSet setWithArray
:[manager breakpointsForFile
:file
]]];
168 [[sourceView_ numberView
] setNeedsDisplay
:YES
];