Re: Drag and drop promised files to Finder
Re: Drag and drop promised files to Finder
- Subject: Re: Drag and drop promised files to Finder
- From: Tim Hewett <email@hidden>
- Date: Wed, 20 Aug 2003 10:02:20 +0100
>
Message: 10
>
Date: Tue, 19 Aug 2003 18:51:24 -0700
>
Subject: Re: Drag and drop promised files to Finder
>
Cc: email@hidden
>
To: Renaud Boisjoly <email@hidden>
>
From: Nick Zitzmann <email@hidden>
>
>
On Tuesday, August 19, 2003, at 06:00 PM, Renaud Boisjoly wrote:
>
>
> Buy, this is not as simple as it should be...
>
>
>
> Any sample code out there I could look at?
>
>
Please join several of us here in filing bug reports on this issue. As
>
things stand right now, doing file promise DnD with either NSTableView
>
or NSOutlineView is very difficult to implement correctly, and more or
>
less impossible to implement flawlessly.
>
>
I got it to "work" once by adding the -dragPromisedFilesOfTypes:...
>
call in the NSTableView -tableView:writeRows:toPasteboard: data source
>
method. But if this call returns NO, then the Objective-C message queue
>
eventually freezes, and if it returns YES, then the application
>
eventually crashes. The former can be worked around by clicking once in
>
the application, but I wish it just worked.
>
>
Nick Zitzmann
>
AIM/iChat: dragonsdontsleep
>
Check out my software page: http://seiryu.home.comcast.net/
Renaud,
The code below is what I have working reliably in the subclass of a
NSTableView, it will possibly be useful for your NSOutlineView too.
I really have no problem with it except for the fact that it was hard to
get it working in the first place.
See it for yourself, you can download the evaluation version of the
software at coolatoola.com - create a backup then drag it to the Finder
to exercise the code.
Regards,
Tim.
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint dragPosition;
NSRect imageLocation;
int column;
//
// We need to check that promised files are supported - they are
not in pre-10.2 OSs.
//
if ( [self
respondsToSelector:@selector(dragPromisedFilesOfTypes:fromRect:source:sl
ideBack:event:)] == NO ) {
NSLog( @"Promised file drag-and-drop is not supported." );
[super mouseDown:theEvent];
return;
}
dragPosition = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
restoreDragRow = [self rowAtPoint:dragPosition];
column = [self columnAtPoint:dragPosition];
[self selectRow:restoreDragRow byExtendingSelection:NO];
[NSEvent startPeriodicEventsAfterDelay:0.3 withPeriod:0];
NSEvent *newEvent = [[self window]
nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask];
switch ( [newEvent type] ) {
case NSLeftMouseUp:
[NSEvent stopPeriodicEvents];
break;
case NSLeftMouseDragged:
[NSEvent stopPeriodicEvents];
if ( (restoreDragRow != -1) && (restoreDragRow < /* "Number of rows in
table" */ ) ) {
dragPosition.x -= 28;
dragPosition.y -= 10;
imageLocation.origin = dragPosition;
imageLocation.size = NSMakeSize( 16, 16 );
NSString *extension = [[[self delegate]
getOriginalPath:restoreDragRow] pathExtension];
if ( ![extension length] || ([extension length] > 4) )
extension = @"'docs'";
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:extension]
fromRect:imageLocation source:self slideBack:YES event:theEvent];
}
break;
default:
break;
}
}
- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)url
{
printf( "Dropped to: %s\n", [[url path] cString] );
// Get the finder path out of the URL here;
return nil;
}
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
if (isLocal) return NSDragOperationNone;
else return NSDragOperationCopy;
}
- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent *)theEvent
{
return YES;
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
return YES;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.