From 5397ab6b80eca2884491d113ca4fd19000adf5e7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 5 Jan 2011 22:16:34 -0500 Subject: [PATCH] Add drag and drop support on BSSourceView and enable it in the BreakpointController. --- CHANGES | 3 ++- Source/BSSourceView.h | 3 +++ Source/BSSourceView.m | 33 +++++++++++++++++++++++++++++++++ Source/BreakpointController.m | 8 ++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index e89fe85..622e35e 100644 --- a/CHANGES +++ b/CHANGES @@ -4,8 +4,9 @@ MacGDBp CHANGE LOG 1.4 Beta 2 ##################### - Fix: After clicking on a stack frame with a virtual file, the debugger front end would hang -- Fix: Crash on clicking "Install & Relaunch" from Sparkle. +- Fix: Crash on clicking "Install & Relaunch" from Sparkle - New: #210 Add a "Stop" button to detach the debugger from the current session +- New: #209 Drag a file onto the source view in the Breakpoints window to load the contents 1.4 Beta 1 diff --git a/Source/BSSourceView.h b/Source/BSSourceView.h index b81619d..f4332db 100644 --- a/Source/BSSourceView.h +++ b/Source/BSSourceView.h @@ -45,4 +45,7 @@ @interface NSObject (BSSourceViewDelegate) - (void)gutterClickedAtLine:(int)line forFile:(NSString*)file; + +// Whether to accept a file drop. +- (BOOL)sourceView:(BSSourceView*)sv acceptsDropOfFile:(NSString*)fileName; @end diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index 2449e89..55481eb 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -216,6 +216,9 @@ [[textView textContainer] setHeightTracksTextView:NO]; [textView setAutoresizingMask:NSViewNotSizable]; [scrollView setDocumentView:textView]; + + NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType]; + [self registerForDraggedTypes:types]; } /** @@ -235,4 +238,34 @@ [textView setString:contents]; } +/** + * Validates an initiated drag operation. + */ +- (NSDragOperation)draggingEntered:(id)sender +{ + if ([delegate respondsToSelector:@selector(sourceView:acceptsDropOfFile:)]) + return NSDragOperationCopy; + return NSDragOperationNone; +} + +/** + * Performs a dragging operation of files to set the contents of the file. + */ +- (BOOL)performDragOperation:(id)sender +{ + NSPasteboard* pboard = [sender draggingPasteboard]; + if ([[pboard types] containsObject:NSFilenamesPboardType]) { + NSArray* files = [pboard propertyListForType:NSFilenamesPboardType]; + if ([files count]) { + NSString* filename = [files objectAtIndex:0]; + if ([delegate respondsToSelector:@selector(sourceView:acceptsDropOfFile:)] && + [delegate sourceView:self acceptsDropOfFile:filename]) { + [self setFile:filename]; + return YES; + } + } + } + return NO; +} + @end diff --git a/Source/BreakpointController.m b/Source/BreakpointController.m index 8790860..f50a63c 100644 --- a/Source/BreakpointController.m +++ b/Source/BreakpointController.m @@ -111,4 +111,12 @@ [[sourceView numberView] setNeedsDisplay:YES]; } +/** + * Accepts a file dragged to set the contents of the display. + */ +- (BOOL)sourceView:(BSSourceView*)sv acceptsDropOfFile:(NSString*)filename +{ + return YES; +} + @end -- 2.43.5