Re: How drag files from an NSTableView?
Re: How drag files from an NSTableView?
- Subject: Re: How drag files from an NSTableView?
- From: Tim Hewett <email@hidden>
- Date: Thu, 8 May 2003 08:39:24 +0100
Uli,
Don't forget you have to subclass NSTableView and override the
draggingSourceOperationMaskForLocal: method otherwise drags
can only be local to the table view. This is what works for me:
@implementation MyTableView
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
if (isLocal) return NSDragOperationNone;
else return NSDragOperationCopy;
}
@end
You also have to add the subclass to the GUI definition in Interface
Builder, otherwise the table view will still get created as NSTableView.
This is the tableView:writeRows:toPasteboard: method which I had before
switching to using promised files:
- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows
toPasteboard:(NSPasteboard*)pboard
{
[pboard declareTypes:[NSArray arrayWithObjects: nil] owner:self];
[pboard declareTypes:[NSArray arrayWithObjects:
NSFilenamesPboardType, nil] owner:self];
[pboard setPropertyList:[NSArray arrayWithObjects: nil]
forType:NSFilenamesPboardType];
[pboard setPropertyList:[NSArray arrayWithObjects:
@"/Users/timhewett/testfile", nil] forType:NSFilenamesPboardType];
return YES;
}
With this, when dragged from the table view to a Finder folder, the
Finder copied /Users/timhewett/testfile to that folder.
Regards,
Tim.
On Thursday, May 8, 2003, at 03:00 Europe/London,
email@hidden wrote:
Date: Wed, 7 May 2003 23:52:21 +0200
Subject: How drag files from an NSTableView?
From: Uli Kusterer <email@hidden>
To: email@hidden
Hi,
I have an NSTableView that lists some objects, to each of which
belongs a file. Now I want the user to be able to drag an item from the
list to e.g. drag the file to the Finder. However, the Finder doesn't
seem to see my file. I found no docs and no sample code on this, and
Hillegass doesn't demonstrate how to drag files. Anybody know what's
wrong with my code?
-(BOOL) tableView: (NSTableView *)tv writeRows: (NSArray*)rows
toPasteboard: (NSPasteboard*)pboard
{
NSNumber* theRow = [rows objectAtIndex:0];
Slide* slide = [presentation getSlideAtIndex: [theRow intValue]];
NSString* slidePath;
NSString* pasteboardType;
NSArray* types;
NSArray* files;
slidePath = [self makeSlidePath: slide];
pasteboardType = NSCreateFilenamePboardType( [slidePath pathExtension]
);
[pasteboardType autoRelease];
// types = [NSArray arrayWithObject: pasteboardType];
files = [NSArray arrayWithObject: slidePath];
[pboard declareTypes: types owner: nil];
[pboard setPropertyList: files forType: pasteboardType];
//[pboard setString: slidePath forType: pasteboardType];
NSLog(@"File dragged %@, extension %@, pasteboard type %@",
slidePath, [slidePath pathExtension], pasteboardType );
return YES;
}
The data that is output by the NSLog call looks valid:
2003-05-07 23:40:10.940 foo[1716] File dragged
/Users/witness/Movies/Myst3-Promo.mov, extension mov, pasteboard type
NSTypedFilenamesPboardType:mov
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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.