Add drag and drop support on BSSourceView and enable it in the BreakpointController.
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 6 Jan 2011 03:16:34 +0000 (22:16 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 6 Jan 2011 03:17:51 +0000 (22:17 -0500)
CHANGES
Source/BSSourceView.h
Source/BSSourceView.m
Source/BreakpointController.m

diff --git a/CHANGES b/CHANGES
index e89fe85f70ee3e2af9908439a96559148aac4f1b..622e35e04f60c9fb9d5ab139c8a0f507703ae7e7 100644 (file)
--- 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
index b81619dee1a4c9b1968472c7bdf40b60fc38d1fd..f4332dbd865d7769c08b3bea9ff682477eb53ed7 100644 (file)
@@ -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
index 2449e89371c9a3f8148b389cfaabf510ac0bc7c3..55481eb0eca721226e9c2a0b1d80ff51a5e488f8 100644 (file)
   [[textView textContainer] setHeightTracksTextView:NO];
   [textView setAutoresizingMask:NSViewNotSizable];
   [scrollView setDocumentView:textView];
+
+  NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType];
+  [self registerForDraggedTypes:types];
 }
 
 /**
   [textView setString:contents];
 }
 
+/**
+ * Validates an initiated drag operation.
+ */
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)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<NSDraggingInfo>)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
index 879086038abbc88b1d9479a7c3b1de9bc620c603..f50a63c957af6110d1264869afb1b8ec9c092d85 100644 (file)
   [[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