Skip navigation.
 
mlRe: How do I capture the filename of an image dropped in an NSImageView?
FROM : Mark Lilback
DATE : Wed Nov 17 19:00:50 2004

At 7:48 AM -0700 11/17/2004, Charles Crowley wrote:
>In my application I store the filename of an image rather than the
>image data itself. When a user drops an image on an NSImageView
>there does not seem to be an obvious way to get the filename of the
>image. Does anyone know how to do this?


Here is the subclass I use to get this information. And I agree, it
should be accessible. I've filed a bug report and I'd suggest you do,
too.

@implementation RTImageView
/*"
   RTImageView is a subclass of NSImageView that will send out a
   notification when an image file is dropped on view. The notification
   will include the path to the file in the userInfo dict under the
   key @"File".
"*/
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
   BOOL val = [super performDragOperation: sender];
   if (val) {
       NSPasteboard *pboard = [sender draggingPasteboard];
       NSString *plist = [pboard stringForType:
NSFilenamesPboardType];
       if (plist) {

           NSArray *files = [NSPropertyListSerialization
propertyListFromData:
               [plist dataUsingEncoding: NSUTF8StringEncoding]
               mutabilityOption:
NSPropertyListImmutable format: nil errorDescription: nil];
           if ([files count] == 1)
               [[NSNotificationCenter defaultCenter]
postNotificationName: RTImageDroppedNotification
                   object: self userInfo:
[NSDictionary dictionaryWithObject: [files objectAtIndex: 0]
                       forKey: @"File"]];
       }
   }
   return val;
}

@end

--
__________________________________________________________________________
                          "The fetters imposed on liberty at home have ever
Mark J. Lilback          been forged out of the weapons provided for
<<email_removed>>        defence against real, pretended, or imaginary
http://www.lilback.com/  dangers from abroad."  -- James Madison

Related mailsAuthorDate
mlHow do I capture the filename of an image dropped in an NSImageView? Charles Crowley Nov 17, 15:48
mlRe: How do I capture the filename of an image dropped in an NSImageView? Thomas Davie Nov 17, 15:53
mlRe: How do I capture the filename of an image dropped in an NSImageView? Nicko van Someren Nov 17, 16:11
mlRe: How do I capture the filename of an image dropped in an NSImageView? Mark Lilback Nov 17, 19:00