Re: NSTableView, file promises, and the message queue
Re: NSTableView, file promises, and the message queue
- Subject: Re: NSTableView, file promises, and the message queue
- From: Tim Hewett <email@hidden>
- Date: Tue, 13 May 2003 17:41:42 +0100
I have promised file drag&drop working (it was a joyous
occasion when that happened :-) ), no application sticking.
It looks like you are trying to fit promised files around the
more normal drag&drop API, I don't think you can do that,
I think you have to subclass NSTableView (see below) and
overload some methods. Don't rely on the Jaguar developer
CD Cocoa documentation to cover promised files properly,
it doesn't (well mine doesn't), you have to look at the Apple
on-line documentation. That is where my code came from.
There are a couple of slight anomalies in its behaviour, which
if someone knows how to fix then I'd be glad to hear:
1. You can't start a drag until your app is at the front, which
is different to normal drag&drop.
2. The drag starts immediately rather after a slight mouse
movement with the button down, i.e. all you have to do is
click.
Otherwise it works great, the Finder responds with the path
of the folder the drag was dropped onto perfectly and (after
some initial struggling to get it to work) no application sticking.
Tim.
@implementation MyTableView
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
if (isLocal) return NSDragOperationNone;
else return NSDragOperationCopy;
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint dragPosition;
NSRect imageLocation;
int row;
dragPosition = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
row = [self rowAtPoint:dragPosition];
if ( (row != -1) && (row < [[self delegate] nRows]) ) {
[self selectRow:row byExtendingSelection:NO];
dragPosition.x -= 16;
dragPosition.y -= 16;
imageLocation.origin = dragPosition;
imageLocation.size = NSMakeSize( 32, 32 );
printf ( "mouseDown: called (x: %f, y:%f, row:%d)\n", dragPosition.x,
dragPosition.y, row );
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:@""]
fromRect:imageLocation source:self slideBack:YES event:theEvent];
}
}
- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)url
{
printf( "Dropped to: %s\n", [[url path] cString] );
return nil;
}
@end
On Tuesday, May 13, 2003, at 15:53 Europe/London,
email@hidden wrote:
>
OK, I've searched the archives and found this,
>
<http://cocoa.mamasam.com/COCOADEV/2003/03/1/57866.php>, which
>
describes my problem exactly, but no one answered.
>
>
I've set up an NSTableView to do drag-and-drop, and it's done by using
>
file promises. Since there isn't any way currently to create a file
>
promise pasteboard, I'm using the workaround I read about, which is to
>
manually call -dragPromisedFilesOfType: within the data source's
>
-tableView:writeRows:toPasteboard: method.
>
>
Things work fine, but now I'm having yet another weird problem:
>
Drag-and-drop works, but after the drop, the application just "sticks".
>
That is, the message queue just stops until the user clicks somewhere
>
in the application, and then it magically restarts.
>
>
Is there any workaround or fix for this? I'm using something similar
>
(but not the same) as this:
>
>
- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray *)rows
>
toPasteboard:(NSPasteboard *)pboard
>
{
>
NSPoint dragPosition = [tableView convertPoint:[window
>
convertScreenToBase:[NSEvent mouseLocation]] fromView:nil];
>
NSRect imageLocation;
>
long i;
>
>
// This code sets up the "image" so that it appears directly in
>
the
>
center of the cursor.
>
dragPosition.x -= 16;
>
dragPosition.y -= 16;
>
imageLocation.origin = dragPosition;
>
imageLocation.size = NSMakeSize(32,32);
>
>
[tableView dragPromisedFilesOfTypes:[NSArray arrayWithObject:@""]
>
fromRect:imageLocation source:tableView slideBack:YES event:[NSApp
>
currentEvent]];
>
return NO;
>
}
>
>
Any ideas would be appreciated...
>
>
Nick Zitzmann
>
AIM/iChat: dragonsdontsleep
>
Check out my software page: http://dreamless.home.attbi.com/
_______________________________________________
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.