Professional Web Applications Themes

Enabling Menus: How? - Mac Programming

I am at a lost trying to add, then enable, a menu item in IB. I can create the menu and menu item, but the menu remains ghosted, even when I select "active" from the Inspector tool. Reading the doentation, the menu is supposed to be active, by default. What am I missing? Thanks....

  1. #1

    Default Enabling Menus: How?

    I am at a lost trying to add, then enable, a menu item in IB. I can
    create the menu and menu item, but the menu remains ghosted, even when
    I select "active" from the Inspector tool. Reading the doentation,
    the menu is supposed to be active, by default. What am I missing?
    Thanks.
    Ed Guest

  2. #2

    Default Re: Enabling Menus: How?

    In article <141220031449281926%rr.com>,
    Ed Sutherland <rr.com> wrote:
     

    Cocoa controls are enabled or disabled in a way that is rather different
    from the way that most frameworks do it. Each control has a target and
    an action. If the target is nil, then the target is the responder chain.
    A control's enable state is determened by whether its target responds to
    its action. For example, the Copy menu item sends the copy: message to
    the responder chain. If the first responder is a text field, it's
    enabled. If it's a window, it's disabled.

    Most of the time this default behavior is good enough. But if you want
    finer control, you can implement the NSMenuValidation protocol:

    http://developer.apple.com/doentation/Cocoa/Reference/ApplicationKit/O
    bjC_classic/Protocols/NSMenuValidation.html

    I'm not sure why the setEnabled: method exists, as I've never seen it
    actually work. Maybe somebody else can shed some light on that one.
    Michael Guest

  3. #3

    Default Re: Enabling Menus: How?

    In article <mail-CD3B81.21172214122003localhost>, Michael Ash
    <com> wrote:
     
    >
    > Cocoa controls are enabled or disabled in a way that is rather different
    > from the way that most frameworks do it. Each control has a target and
    > an action. If the target is nil, then the target is the responder chain.
    > A control's enable state is determened by whether its target responds to
    > its action. For example, the Copy menu item sends the copy: message to
    > the responder chain. If the first responder is a text field, it's
    > enabled. If it's a window, it's disabled.
    >
    > Most of the time this default behavior is good enough. But if you want
    > finer control, you can implement the NSMenuValidation protocol:
    >
    > http://developer.apple.com/doentation/Cocoa/Reference/ApplicationKit/O
    > bjC_classic/Protocols/NSMenuValidation.html
    >
    > I'm not sure why the setEnabled: method exists, as I've never seen it
    > actually work. Maybe somebody else can shed some light on that one.[/ref]

    Because there are actually three different levels of validation.

    The first level is fully automatic validation. Your explanation of
    this isn't quite complete: Cocoa first looks to see if there is a
    non-null target; if so it looks to see if that target responds to the
    action message, validating the menu item if it does, invalidating it if
    it doesn't. What is left out of the above is that if the target is
    null, then Cocoa will continue to search for an object that can
    respond, first in the responder chain then through a fairly complicated
    list. See the Programming Topic on menus, specifically the article on
    menu validation for details on the search (and all of the rest of this
    stuff).

    The second level is the implementation of

    - (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem

    from the NSMenuValidationProtocol as you discuss. This level is really
    an add-on to the first level: if Cocoa finds an object that responds
    (either in the menus target or, in the case of a null target, somewhere
    in the chain), before it simply validates the item, it will check IN
    THAT OBJECT, to see if validateMenuItem is implemented. If so, it
    takes its response from validateMenuItem, if not, it simply validates
    the item.

    There is a third level of validation that uses setEnabled:, i.e. fully
    manual validation. To use this validation, you have to call NSMenu's
    - - (void)setAutoenablesItems: with NO as a parameter (it is set to YES
    by default). If you do this, then you are responsible for manually
    setting the status of each menu item individually with setEnabled:

    Spence
    James Guest

  4. #4

    Default Re: Enabling Menus: How?

    Ed Sutherland <rr.com> wrote in message news:<141220031449281926%rr.com>... 

    You've already gotten good explanations for how it works.

    This has happened to me a couple of times, and in both times what
    was wrong is that I failed to give the action method a single
    argument for the sender. If the menu sends fooBar, then the
    action method needs to be

    - (IBAction)fooBar:(id)sender;
    Eric Guest

  5. #5

    Default Re: Enabling Menus: How?

    In article <141220031615080282%net>,
    James Spencer <net> wrote:
     
    >
    > Because there are actually three different levels of validation.[/ref]
    [snip explanation]

    Thanks James, that cleared up my remaining confusion.
    Michael Guest

Similar Threads

  1. Enabling CFS for IIS sites
    By Raffee in forum Coldfusion Server Administration
    Replies: 4
    Last Post: August 1st, 04:27 PM
  2. Enabling SSH on AIX and Solaris
    By amit in forum Linux / Unix Administration
    Replies: 3
    Last Post: December 30th, 03:54 PM
  3. [PHP-DEV] Enabling ext/xsl by default
    By Sebastian Bergmann in forum PHP Development
    Replies: 3
    Last Post: September 1st, 09:47 AM
  4. enabling DUN
    By Ken Wickes [MSFT] in forum Windows Networking
    Replies: 5
    Last Post: July 9th, 07:37 PM
  5. Enabling ssl on web?
    By Miranda, Joel Louie M in forum Debian
    Replies: 3
    Last Post: July 3rd, 08:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139