• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dragging from Finder into View
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dragging from Finder into View


  • Subject: Re: Dragging from Finder into View
  • From: "John C. Randolph" <email@hidden>
  • Date: Sun, 14 Oct 2001 15:04:57 -0700

On Sunday, October 14, 2001, at 02:05 PM, Jeff Disher wrote:

Hello,

In a program I am working on I want to try to use drag
& drop onto my program's window in the same fashion
that I can use drag & drop onto its icon. Basically,
I only need to extract the path to the dropped file.

I have seen the documentation on how to extract
various data representations but does anyone know how
to extract just the file path?

I did it like this, in a subclass of NSImageView:

- (unsigned int) draggingEntered:(id <NSDraggingInfo>)sender
/*"Tests whether the object being dragged is a set of filenames, and if so, changes the displayed icon to match that of the dragged items."*/
{
id
pasteboard = [sender draggingPasteboard];

if ([[self class] _activeDragWell] != self) // Drag from self is a NoOp
if ([pasteboard containsFiles] && ([sender draggingSourceOperationMask] & NSDragOperationCopy))
{
id
draggedPaths = [pasteboard propertyListForType:NSFilenamesPboardType];
if ([self canAcceptPaths:draggedPaths])
{
[self setImage:[[NSWorkspace sharedWorkspace] iconForFiles: draggedPaths]];
if (fileNameField)
[fileNameField setStringValue:[self nameToDisplayForPaths:draggedPaths]];
if (fullPathField)
[fullPathField setStringValue:[self fullPathToDisplayForPaths:draggedPaths]];
return NSDragOperationAll;
}
}
return NSDragOperationNone;
}

To make it more readable, I'd added this category to NSPasteboard:

@implementation NSPasteboard (JCRDragWellExtensions)

- (BOOL) hasType:aType /*"Returns TRUE if aType is one of the types available from the receiving pastebaord."*/
{ return ([[self types] indexOfObject:aType] == NSNotFound ? NO : YES); }

- (BOOL) containsFiles /*"Returns TRUE if there are filenames available in the receiving pasteboard."*/
{ return [self hasType:NSFilenamesPboardType]; }

@end


"I fear all we have done is to awaken a sleeping giant and fill him with a terrible resolve." -Admiral Isoroku Yamamoto, Dec 7, 1941.


References: 
 >Dragging from Finder into View (From: Jeff Disher <email@hidden>)

  • Prev by Date: Re: Displaying an alert box
  • Next by Date: Re: Cocoa Java vs Swing Java classes
  • Previous by thread: Dragging from Finder into View
  • Next by thread: getting path info from PDF image?
  • Index(es):
    • Date
    • Thread