Re: cocoa-dev digest, Vol 2 #729 - 17 msgs
Re: cocoa-dev digest, Vol 2 #729 - 17 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #729 - 17 msgs
- From: Michael McCracken <email@hidden>
- Date: Sun, 2 Jun 2002 18:09:20 -0700
This was answered over on the macosx-dev list at omnigroup's lists.
Here's the mamasam link:
http://cocoa.mamasam.com/MACOSXDEV/2002/05/1/34007.php
(I searched for "NSPasteboard AND filenames" and the message was titled
"Re: Finder drops")
And here's a copy of what I wrote:
Finder gives you an array of paths (strings)
in property list format. I call NSPasteboard's propertyListForType:
method to get it.
Here is some code from my project - it works for me, your mileage may
vary.
You register for NSFilenamesPboardType, then:
In
- (BOOL)tableView:(NSTableView*)tv
acceptDrop:(id <NSDraggingInfo>)info
row:(int)row
dropOperation:(NSTableViewDropOperation)op{
...
NSString *pbString;
NSArray *pbArray;
NSEnumerator *fileNameEnum;
NSPasteboard *pb;
...
pb = [info draggingPasteboard];
if([pb hasType:NSFilenamesPboardType]){
pbArray = [pb propertyListForType:NSFilenamesPboardType]; // we
will get an array
NSLog(@"got filenames %@", pbArray);
fileNameEnum = [pbArray objectEnumerator];
while(fnStr = [fileNameEnum nextObject]){
//use fnStr. it will be a path.
}
return YES;
}
Hope this works for you. There might be some other details you need to
work out specific to your use, but this should be a start.
-Mike
On Sunday, June 2, 2002, at 05:35 PM, email@hidden
wrote:
Message: 15
Date: Sun, 02 Jun 2002 17:10:19 -0700
Subject: Pasteboards and filenames
From: Sam Goldman <email@hidden>
To: Cocoa Dev <email@hidden>
OK, so I have drag and drop working the way it should be working and I
have
solved a few other problems on the way, but now there is this one I am
having with pasteboards and arrays.
The table view is set up to accept NSFilenamesPBoardType only.
In the method: -
tableView:validateDrop:proposedRow:proposedDropOperation:,
I get the NSDraggingInfo and then get the pasteboard from that with this
code: [[info draggingPasteboard] stringForType:NSFilenamesPboardType]
What I want to do is check to see whether the filename is a directory
of a
regular file. Since there is the possibility of having multiple files,
it
makes some amount of sense that the string comes out like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM
"file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<array>
<string>/Users/sgoldman/Desktop/Happy Happy Joy Joy.mp3</string>
</array>
</plist>
I don't mind working with this, but I don't see any way of getting the
data
into an array without first writing it to a file and then reading it
back
in. There has to be a better way...
- Sam
--
Michael McCracken
email@hidden
_______________________________________________
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.