From: Adam M. <ama...@us...> - 2005-08-31 05:04:38
|
Update of /cvsroot/bibdesk/bibdesk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15206 Modified Files: Tag: BR_1x BDSKForm.h BDSKForm.m Log Message: Implement dragging files, URLs, and weblocs from the form cells. Needs testing on 10.3 to see if it crashes. Also, the event queue may still bog down the app, particularly after dragging a file around. Index: BDSKForm.m =================================================================== RCS file: /cvsroot/bibdesk/bibdesk/Attic/BDSKForm.m,v retrieving revision 1.1.4.7 retrieving revision 1.1.4.8 diff -C2 -d -r1.1.4.7 -r1.1.4.8 *** BDSKForm.m 30 Aug 2005 21:42:38 -0000 1.1.4.7 --- BDSKForm.m 31 Aug 2005 05:04:26 -0000 1.1.4.8 *************** *** 40,47 **** --- 40,51 ---- #import "BDSKComplexString.h" + #import "BibEditor.h" + // private methods for getting the rect(s) of each cell in the matrix @interface BDSKForm (Private) - (id)cellAtPoint:(NSPoint)point usingButton:(BOOL)usingButton; + (NSCursor *)fingerCursor; + - (void)setPromisedDragURL:(NSURL *)theURL; + - (void)setPromisedDragFilename:(NSString *)theFilename; @end *************** *** 54,58 **** if (![[self prototype] isKindOfClass:[BDSKFormCell class]]){ BDSKFormCell *cell = [[BDSKFormCell alloc] init]; ! [cell setFont:[[self prototype] font]]; [cell setTitleFont:[[self prototype] titleFont]]; [cell setWraps:[[self prototype] wraps]]; --- 58,62 ---- if (![[self prototype] isKindOfClass:[BDSKFormCell class]]){ BDSKFormCell *cell = [[BDSKFormCell alloc] init]; ! [cell setFont:[(NSCell *)[self prototype] font]]; [cell setTitleFont:[[self prototype] titleFont]]; [cell setWraps:[[self prototype] wraps]]; *************** *** 72,75 **** --- 76,89 ---- } + -(void)drawRect:(NSRect)rect{ + [super drawRect:rect]; + if (!highlight || dragRow == -1) return; + + [NSGraphicsContext saveGraphicsState]; + NSSetFocusRingStyle(NSFocusRingOnly); + NSRectFill([self cellFrameAtRow:dragRow column:0]); + [NSGraphicsContext restoreGraphicsState]; + } + - (void)dealloc{ [super dealloc]; *************** *** 93,96 **** --- 107,158 ---- case NSLeftMouseDragged: [cell setButtonHighlighted:isInside]; + if(isInside && [cell hasFileIcon]){ + NSImage *dragImage; + id delegate = [self delegate]; + + // all we really need from the editor is our model object, so it would be easy to implement a formal protocol or add other object types + if(![delegate isMemberOfClass:[BibEditor class]]) + [NSException raise:NSInternalInconsistencyException format:@"Dragging sources other than BibEditor are not supported yet."]; + + BibItem *pub = [delegate currentBib]; + NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; + NSArray *types = nil; + NSString *field = [cell title]; + + NSURL *url = [pub remoteURLForField:field]; + [self setPromisedDragURL:url]; + + NSString *pathExtension = @""; + + if([url isFileURL]){ + NSString *path = [pub localFilePathForField:field]; + pathExtension = [path pathExtension]; + types = [NSArray arrayWithObjects:NSURLPboardType, NSFilenamesPboardType, NSFilesPromisePboardType, nil]; + [pboard declareTypes:types owner:nil]; + [url writeToPasteboard:pboard]; + [self setPromisedDragFilename:[path lastPathComponent]]; + [pboard setPropertyList:[NSArray arrayWithObject:promisedDragFilename] forType:NSFilesPromisePboardType]; + [pboard setPropertyList:[NSArray arrayWithObject:path] forType:NSFilenamesPboardType]; + } else { + pathExtension = @"webloc"; + types = [NSArray arrayWithObjects:NSURLPboardType, NSFilesPromisePboardType, nil]; + [pboard declareTypes:types owner:nil]; + [url writeToPasteboard:pboard]; + [self setPromisedDragFilename:[[pub title] stringByAppendingPathExtension:@"webloc"]]; + [pboard setPropertyList:[NSArray arrayWithObject:promisedDragFilename] forType:NSFilesPromisePboardType]; + } + NSRect imageLocation; + + mouseLoc.x -= 16; + mouseLoc.y -= 16; + imageLocation.origin = mouseLoc; + imageLocation.size = NSMakeSize(32,32); + [self dragPromisedFilesOfTypes:[NSArray arrayWithObject:pathExtension] + fromRect:imageLocation + source:self + slideBack:YES + event:theEvent]; + [cell setButtonHighlighted:NO]; + } break; case NSLeftMouseUp: *************** *** 103,106 **** --- 165,170 ---- [cell setButtonHighlighted:NO]; keepOn = NO; + // need to flush the event queue after a drag + [NSApp discardEventsMatchingMask:NSAnyEventMask beforeEvent:theEvent]; break; default: *************** *** 253,264 **** } ! -(void)drawRect:(NSRect)rect{ ! [super drawRect:rect]; ! if (!highlight || dragRow == -1) return; ! ! [NSGraphicsContext saveGraphicsState]; ! NSSetFocusRingStyle(NSFocusRingOnly); ! NSRectFill([self cellFrameAtRow:dragRow column:0]); ! [NSGraphicsContext restoreGraphicsState]; } --- 317,350 ---- } ! #pragma mark - ! #pragma mark NSDraggingSource protocol ! ! - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination{ ! NSString *dstPath = [dropDestination path]; ! ! // queue the file creation so we don't block while waiting for this method to return ! if([promisedDragURL isFileURL]){ ! [[OFMessageQueue mainQueue] queueSelector:@selector(copyPath:toPath:handler:) ! forObject:[NSFileManager defaultManager] ! withObject:[promisedDragURL path] ! withObject:[dstPath stringByAppendingPathComponent:promisedDragFilename] ! withObject:nil]; ! } else { ! [[OFMessageQueue mainQueue] queueSelector:@selector(createWeblocFileAtPath:withURL:) ! forObject:[NSFileManager defaultManager] ! withObject:[dstPath stringByAppendingPathComponent:promisedDragFilename] ! withObject:promisedDragURL]; ! } ! ! return [NSArray arrayWithObject:promisedDragFilename]; ! } ! ! - (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)isLocal{ ! return NSDragOperationCopy; ! } ! ! - (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation{ ! [self setPromisedDragURL:nil]; ! [self setPromisedDragFilename:nil]; } *************** *** 314,317 **** --- 400,417 ---- } + // used to cache the destination webloc file's URL + - (void)setPromisedDragURL:(NSURL *)theURL{ + [theURL retain]; + [promisedDragURL release]; + promisedDragURL = theURL; + } + + // used to cache the filename (not the full path) of the promised file + - (void)setPromisedDragFilename:(NSString *)theFilename{ + if(promisedDragFilename != theFilename){ + [promisedDragFilename release]; + promisedDragFilename = [theFilename copy]; + } + } @end Index: BDSKForm.h =================================================================== RCS file: /cvsroot/bibdesk/bibdesk/Attic/BDSKForm.h,v retrieving revision 1.1.4.7 retrieving revision 1.1.4.8 diff -C2 -d -r1.1.4.7 -r1.1.4.8 *** BDSKForm.h 31 Aug 2005 00:39:33 -0000 1.1.4.7 --- BDSKForm.h 31 Aug 2005 05:04:26 -0000 1.1.4.8 *************** *** 41,46 **** --- 41,49 ---- @interface BDSKForm : NSForm { + @private int dragRow; BOOL highlight; + NSString *promisedDragFilename; + NSURL *promisedDragURL; } /*! |