• 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
Drag&Drop NSTextView not working?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drag&Drop NSTextView not working?


  • Subject: Drag&Drop NSTextView not working?
  • From: <email@hidden>
  • Date: Thu, 10 Mar 2005 6:59:42 +0000

I know, I know, subjects like "not working" are taboo here, but I can't think of any other way to put it.  I'm trying to implement my NSTextView subclass to allow the dropping of files from the Finder on it, and I've added all the code from the Apple docs and various examples on the web.  But when I run my app, I try to drag a single file from the Finder over my NSTextView subclass, and it just plain doesn't take the drop.  Here's the relevant code:

First, I've overridden - (void)acceptableDragTypes to add NSFilenamesPboardType to the acceptableDragTypes array.  I also had this set in the init method with registerForDraggedTypes, still didn't work.

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
   NSPasteboard* pboard;
   NSDragOperation sourceDragMask;

   sourceDragMask = [sender draggingSourceOperationMask];
   pboard = [sender draggingPasteboard];

   if ([[pboard types] containsObject:NSFilenamesPboardType])
   {
      if (sourceDragMask & NSDragOperationLink)
      {
         return NSDragOperationLink;
      }
      else if (sourceDragMask & NSDragOperationCopy)
      {
         return NSDragOperationCopy;
      }
   }

   return NSDragOperationNone;
}

- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
   return YES;
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
   NSPasteboard* pboard;
   NSDragOperation sourceDragMask;

   sourceDragMask = [sender draggingSourceOperationMask];
   pboard = [sender draggingPasteboard];

   if ([[pboard types] containsObject:NSFilenamesPboardType])
   {
      NSArray* array = [pboard propertyListForType:NSFilenamesPboardType];
      [self setFiles:array]; // sets the array to an ivar
   }

   return YES;
}

- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
	[self writeFilesToView]; // simply writes the filenames to the textview
}

Am I missing something?  Thanks.

James

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Drag&Drop NSTextView not working?
      • From: Gregg Witmer <email@hidden>
  • Prev by Date: Re: [newbie] SIGSEGV and GDB
  • Next by Date: Re: Detect URL in NSTextView
  • Previous by thread: Re: Asymmetrical behavior in NSMutableArray
  • Next by thread: Re: Drag&Drop NSTextView not working?
  • Index(es):
    • Date
    • Thread