• 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
adding contextual menu items to an NSTextView subclass menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

adding contextual menu items to an NSTextView subclass menu


  • Subject: adding contextual menu items to an NSTextView subclass menu
  • From: Michael Hanna <email@hidden>
  • Date: Mon, 14 Feb 2005 12:42:15 -0500

<x-tad-smaller>in my NSTextView subclass I have the following code, I'm trying to add and an enable a contextual menu item, but I'm having trouble. If the NSTextView is empty, the new separator and item appears disabled(good thing), but when I have something in its NSTextStorage, the item I'm adding is repeated(bad thing) and not enabled either. ValidateMenuItem is called, but it never seems to match @"Show Visual Cues File". I know I'm way off on the implementation, but not sure where. oOwningDocument is an IBOutlet to the NSDocument that it's a field declaration of.

regards,
Michael

+(NSMenu *)defaultMenu
{
NSMenu *theDefaultMenu = [</x-tad-smaller><x-tad-smaller>super</x-tad-smaller><x-tad-smaller> defaultMenu];
NSMenuItem *anItem = </x-tad-smaller><x-tad-smaller>nil</x-tad-smaller><x-tad-smaller>;


NSLog(</x-tad-smaller><x-tad-smaller>@"revealVisualCuesInFinder"</x-tad-smaller><x-tad-smaller>);
[theDefaultMenu addItem:[NSMenuItem separatorItem]];
anItem = [[[NSMenuItem alloc] initWithTitle:</x-tad-smaller><x-tad-smaller>@"Show Visual Cues File"</x-tad-smaller><x-tad-smaller> action:</x-tad-smaller><x-tad-smaller>@selector</x-tad-smaller><x-tad-smaller>(revealVisualCuesInFinderCM:) keyEquivalent:</x-tad-smaller><x-tad-smaller>@""</x-tad-smaller><x-tad-smaller>] autorelease];
[theDefaultMenu addItem:anItem];
[anItem setTarget:</x-tad-smaller><x-tad-smaller>self</x-tad-smaller><x-tad-smaller>];
</x-tad-smaller><x-tad-smaller>return</x-tad-smaller><x-tad-smaller> theDefaultMenu;
}

-(</x-tad-smaller><x-tad-smaller>id</x-tad-smaller><x-tad-smaller>)sender
{
NSLog(</x-tad-smaller><x-tad-smaller>@"revealVisualCuesInFinderCM"</x-tad-smaller><x-tad-smaller>);

}
- (</x-tad-smaller><x-tad-smaller>BOOL</x-tad-smaller><x-tad-smaller>)validateMenuItem:(NSMenuItem *)inItem
{
NSLog(</x-tad-smaller><x-tad-smaller>@"[inItem title] %@"</x-tad-smaller><x-tad-smaller>, [inItem title]);
</x-tad-smaller><x-tad-smaller>if</x-tad-smaller><x-tad-smaller> ([[inItem title] isEqualToString:</x-tad-smaller><x-tad-smaller>@"Show Visual Cues File"</x-tad-smaller><x-tad-smaller>])
{
NSLog(</x-tad-smaller><x-tad-smaller>@"found Show Visual Cues File]"</x-tad-smaller><x-tad-smaller>);
</x-tad-smaller><x-tad-smaller>if</x-tad-smaller><x-tad-smaller>(![oOwningDocument visualCueIsPresent])
</x-tad-smaller><x-tad-smaller>return</x-tad-smaller><x-tad-smaller> </x-tad-smaller><x-tad-smaller>NO</x-tad-smaller><x-tad-smaller>;


}
</x-tad-smaller><x-tad-smaller>return</x-tad-smaller><x-tad-smaller> </x-tad-smaller><x-tad-smaller>YES</x-tad-smaller><x-tad-smaller>;
}

2005-02-14 12:19:01.509 GuitarPrompter[758] [inItem title] Cut
2005-02-14 12:19:01.509 GuitarPrompter[758] [inItem title] Copy
2005-02-14 12:19:01.509 GuitarPrompter[758] [inItem title] Paste
2005-02-14 12:19:01.509 GuitarPrompter[758] [inItem title] Spelling...
2005-02-14 12:19:01.509 GuitarPrompter[758] [inItem title] Check Spelling
2005-02-14 12:19:01.510 GuitarPrompter[758] [inItem title] Check Spelling as You Type
2005-02-14 12:19:01.510 GuitarPrompter[758] [inItem title] Underline
2005-02-14 12:19:01.510 GuitarPrompter[758] [inItem title] Outline
2005-02-14 12:19:01.510 GuitarPrompter[758] [inItem title] Start Speaking
2005-02-14 12:19:01.511 GuitarPrompter[758] [inItem title] Stop Speaking
2005-02-14 12:19:01.511 GuitarPrompter[758] [inItem title] Right to Left
</x-tad-smaller>
 _______________________________________________
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

  • Follow-Ups:
    • Re: adding contextual menu items to an NSTextView subclass menu
      • From: Jeremy French <email@hidden>
    • Re: adding contextual menu items to an NSTextView subclass menu
      • From: daniel <email@hidden>
  • Prev by Date: Re: Motion Blur
  • Next by Date: Re: Newbie
  • Previous by thread: Re: request a webpage from cocoa
  • Next by thread: Re: adding contextual menu items to an NSTextView subclass menu
  • Index(es):
    • Date
    • Thread