• 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
NSTextField: drag-and-drop + Command keypresses
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextField: drag-and-drop + Command keypresses


  • Subject: NSTextField: drag-and-drop + Command keypresses
  • From: Alex Reynolds <email@hidden>
  • Date: Fri, 20 Oct 2006 06:35:12 -0400

I have a NSTextField which I subclassed and enabled with the NSDraggingInfo protocol. I set the delegate of this NSTextField and its enclosing NSWindow to my custom Controller class.

Drag and drop works. Specifically I am dragging a file or URL object from a web browser into the NSTextField. It inserts the URI into the insertion point within the NSTextField.

However, I would like to do the following:

1. I would like to replace all the text inside the NSTextField with the URI contained inside the NSPasteboard object

2. Enable Command-C, Command-V etc. keypresses, to be able to copy and paste from the NSPasteboard into my NSTextField


How can I add these features?


To try to answer 1. I looked at the following method which I obtained from http://www.stone.com/The_Cocoa_Files/ Ins_and_Outs_of_Drag_and_D.html:


- (unsigned int) draggingEnteredOrUpdated:(id <NSDraggingInfo>)sender
{
// we want to ignore drags originating in our own window:
if ([sender draggingSource] == controllerWindow)
{
return NSDragOperationNone;
}
else
{
unsigned int sourceMask = [sender draggingSourceOperationMask];
NSPasteboard *pboard = [sender draggingPasteboard];
NSString *type = [pboard availableTypeFromArray:[self acceptableDragTypes]];
if (type) return sourceMask;
NSLog (@"Type: %s",type);
return NSDragOperationNone;
}
}


I tried adding NSLog statements within this method to track what data gets passed around. Unfortunately, the above NSLog never gets called for some reason, even though the drag-and-drop appears to work. Is there another method being called?


To try to answer 2., I have subclassed the enclosing NSWindow to handle sendEvent:


- (void) sendEvent: (NSEvent *) theEvent
{
if (([theEvent type]==NSKeyDown) && ([theEvent keyCode] == 53))
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"notifyEscapeKeyPressed" object:self];
}

[super sendEvent: theEvent];
}


Is this overriding my ability to send Command keypresses to the custom NSTextField object?

If I am calling the super's sendEvent:, why wouldn't this just pass on Command-keypresses upwards?


Thanks for any advice!

Regards,
Alex
_______________________________________________
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


  • Prev by Date: minimal redraw with scrollPoint
  • Next by Date: Tab stop with fill characters
  • Previous by thread: minimal redraw with scrollPoint
  • Next by thread: Tab stop with fill characters
  • Index(es):
    • Date
    • Thread