Re: NSTextField and contextual menu (solved)
Re: NSTextField and contextual menu (solved)
- Subject: Re: NSTextField and contextual menu (solved)
- From: Arthur Clemens <email@hidden>
- Date: Sun, 15 Sep 2002 18:26:05 +0200
>
I guess you wanna to read the window documentation of "field editor".
>
When edited, the text field is effectively replaced by a NSTextView.
>
Thanks for the golden tip. I would never have come up with this myself,
although I've already spent some time looking around the net. As a
newcomer it is hard to get a global view of how classes and objects are
interrelated.
Just for the record, I'll add my solution for my system wide contextual
menu:
in AppController.h, I define
IBOutlet NSWindow *theWindow; // just the application's window
NSTextView *editor;
in AppController.c:
- (void)awakeFromNib
{
[self makeFieldEditorContextual];
// other code
}
- (void)makeFieldEditorContextual
{
editor = (NSTextView *)[theWindow fieldEditor: YES forObject:self];
NSMenu *menu;
NSMenuItem *item;
int i;
NSString *path;
NSArray *charArray;
NSDictionary *defaultValues;
path = [[NSBundle mainBundle]
pathForResource:@"Chars" ofType:@"plist"];
defaultValues = [NSDictionary dictionaryWithContentsOfFile: path];
charArray = [defaultValues objectForKey:@"tags"];
menu = [[NSMenu alloc] initWithTitle:@"Menu"];
for (i=0; i<[charArray count]; ++i) {
item = [[NSMenuItem alloc] init];
[item setTitle: [charArray objectAtIndex: i]];
[item setTarget: self];
[item setAction:@selector(insert:)];
[menu addItem: item];
[item release];
}
[editor setMenu: menu];
[editor setAllowsUndo: YES];
[menu release];
}
- (IBAction)insert:(id)sender
{
[editor insertText:[sender title]];
}
- (NSMenu *)menuForEvent:(NSEvent *)event {
return [editor menu];
}
Arthur Clemens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.