• 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
Re: NSTextField and contextual menu (solved)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTextField and contextual menu (solved)
      • From: Ondra Cada <email@hidden>
References: 
 >Re: NSTextField and contextual menu (again) (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: showing a checkbox and a pulldown-menu in a NSTableView
  • Next by Date: Property List Services and XML
  • Previous by thread: Re: NSTextField and contextual menu (again)
  • Next by thread: Re: NSTextField and contextual menu (solved)
  • Index(es):
    • Date
    • Thread