Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextField Content Sensitive Menu



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.