From 7a8a10f2673ce531fcb38cfec89a04991bbe09c0 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 5 Jan 2011 21:53:16 -0500 Subject: [PATCH] Add drag and drop for the table view. --- English.lproj/Breakpoints.xib | 12 ++++++++++-- Source/BreakpointController.m | 30 +++++++++++++++++++++++++++++- Source/BreakpointManager.m | 22 ++++++++++++---------- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/English.lproj/Breakpoints.xib b/English.lproj/Breakpoints.xib index 1574853..c1093b5 100644 --- a/English.lproj/Breakpoints.xib +++ b/English.lproj/Breakpoints.xib @@ -12,7 +12,7 @@ YES - + YES @@ -480,6 +480,14 @@ 50 + + + dataSource + + + + 51 + @@ -741,7 +749,7 @@ - 50 + 51 diff --git a/Source/BreakpointController.m b/Source/BreakpointController.m index ef3e5a9..1f08eba 100644 --- a/Source/BreakpointController.m +++ b/Source/BreakpointController.m @@ -43,6 +43,8 @@ */ - (void)awakeFromNib { + NSArray* dragTypes = [NSArray arrayWithObject:NSFilenamesPboardType]; + [tableView_ registerForDraggedTypes:dragTypes]; } /** @@ -86,7 +88,8 @@ Breakpoint* bp = [selection objectAtIndex:0]; [sourceView_ setFile:[bp file]]; - [sourceView_ scrollToLine:[bp line]]; + if ([bp line] > 0) + [sourceView_ scrollToLine:[bp line]]; [[sourceView_ numberView] setMarkers:[NSSet setWithArray:[manager breakpointsForFile:[bp file]]]]; } @@ -99,6 +102,8 @@ writeRowsWithIndexes:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard*)pboard { + NSLog(@"begin"); + return [[pboard types] containsObject:NSFilenamesPboardType]; } /** @@ -109,6 +114,14 @@ proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation { + NSLog(@"validate"); + NSPasteboard* pboard = [info draggingPasteboard]; + if ([[pboard types] containsObject:NSFilenamesPboardType]) { + NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; + if ([files count]) + return NSDragOperationGeneric; + } + return NSDragOperationNone; } /** @@ -119,6 +132,21 @@ row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation { + NSLog(@"accept"); + BOOL valid = [self tableView:aTableView + validateDrop:info + proposedRow:row + proposedDropOperation:operation] == NSDragOperationGeneric; + if (valid) { + NSPasteboard* pboard = [info draggingPasteboard]; + NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; + for (NSString* file in files) { + Breakpoint* bp = [[[Breakpoint alloc] initWithLine:0 inFile:file] autorelease]; + [manager addBreakpoint:bp]; + } + return YES; + } + return NO; } #pragma mark BSSourceView Delegate diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m index 0407a47..6d4bcb8 100644 --- a/Source/BreakpointManager.m +++ b/Source/BreakpointManager.m @@ -67,13 +67,14 @@ */ - (void)addBreakpoint:(Breakpoint*)bp; { - if (![breakpoints containsObject:bp]) - { + if (![breakpoints containsObject:bp]) { [breakpoints addObject:bp]; - [connection addBreakpoint:bp]; - - [savedBreakpoints addObject:[bp dictionary]]; - [[NSUserDefaults standardUserDefaults] setValue:savedBreakpoints forKey:@"Breakpoints"]; + if (bp.line > 0) { + [connection addBreakpoint:bp]; + + [savedBreakpoints addObject:[bp dictionary]]; + [[NSUserDefaults standardUserDefaults] setValue:savedBreakpoints forKey:@"Breakpoints"]; + } [self updateDisplaysForFile:[bp file]]; } @@ -89,11 +90,12 @@ if ([b line] == line && [[b file] isEqualToString:file]) { [breakpoints removeObject:b]; - [connection removeBreakpoint:b]; - + if (b.line > 0) + [connection removeBreakpoint:b]; + [savedBreakpoints removeObject:[b dictionary]]; [[NSUserDefaults standardUserDefaults] setValue:savedBreakpoints forKey:@"Breakpoints"]; - + [self updateDisplaysForFile:file]; return b; } @@ -109,7 +111,7 @@ NSMutableArray* matches = [NSMutableArray array]; for (Breakpoint* b in breakpoints) { - if ([[b file] isEqualToString:file]) + if ([[b file] isEqualToString:file] && [b line] > 0) { [matches addObject:b]; } -- 2.43.5