One Quickie


Enabling and Disabling menu items (NSMenu->General)
Under most circumstances, it happens automatically: a menu item will be disabled if there is no object in the responder chain that handles the menu's action. If you want to override this behavior or extend it further, override validateMenuItem: and do something like this:
- (BOOL) validateMenuItem: (id <NSMenuItem>) menuItem
{
    BOOL result = YES;

    if ([menuItem action] == @selector(deleteNote:)) {
        if ([notes count] == 1) {
            result = NO; // can't delete the last note
        }

    } else if ([menuItem action] == @selector(gotoNote:)) {
        if ([notes count] == 1) {
            result = NO; // can't go to a different not if only one
        }
    }

    return (result);

} // validateMenuItem



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com