• 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 Content Sensitive Menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextField Content Sensitive Menu


  • Subject: NSTextField Content Sensitive Menu
  • From: John Nairn <email@hidden>
  • Date: Wed, 31 Dec 2008 09:07:40 -0800

I added a menu to an NSTextField and it works when first clicked, but when the field is the first responder, the Field Editor takes over with its own menu (as I should have guessed). My plan was

1. Insert custom field editor
2. Overide menuForEvent, capture the default menu, append my commands

It was looking promising, but two problems arose:

1. My NSTextView subclass only overrides menuForEvent, but other crucial field editor tasks are lost. For example, the tab key inserts a tab key rather then tabbing to the next field. Apple has help on "subclassing NSTextView", but I could not find anything on the tasks one needs to support manually to duplicate the default field editor.

2. I first created the field editor using code from Apple documentation:

- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id) anObject
{
if([anObject isKindOfClass:[NSTextField class]])
{ NSLog(@"getting field editor");
return [[BrowserFieldEditor alloc] init];
}
}
return nil;
}


I inserted a NSLog() line to watch this event and was surprised it was called over and over again even when I was not initiating editing. To avoid passing on multiple editors, I added one editor to my window controlled and revised it to be

- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id) anObject
{
if([anObject isKindOfClass:[NSTextField class]])
{ if(!customEditor)
{ NSLog(@"getting field editor");
customEditor=[[BrowserFieldEditor alloc] init];
}
return customEditor;
}
return nil;
}


This worked OK, but my controller crashed when, as recommended, I deallocated this custom editor when the window controller got deallocated. Thus, I was confused on how to handle a custom field editor.

---------------
John Nairn
GEDitCOM - Genealogy Software for the Macintosh
http://www.geditcom.com


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Reversing a String
  • Next by Date: Re: Pull Down Toolbar Item
  • Previous by thread: Re: Automatically filling an app with test data
  • Next by thread: mydoc.myext/QuickLook/Preview.html and full screen
  • Index(es):
    • Date
    • Thread