Skip to content

Transparently init app menu when not present #509

@mszoek

Description

@mszoek

Menus are normally defined in the app's nib file. For a nibless app, the menus can be created from code, but the Application menu (the bold one with the app's name and the quit option) should always be created automatically if one is not provided.

Move something like this into NSMenu's init or NSApp's setMainMenu:

        // Hack up an application menu since we don't load a nib
        NSMenu *appMenu = [[NSMenu alloc] initApplicationMenu:@"Client Demo"];
        NSMenuItem *appMenuItem = [NSMenuItem new];
        [appMenuItem setTitle:@"Client Demo"];
        [appMenuItem setSubmenu:appMenu];
        [menu insertItem:appMenuItem atIndex:0];
        [NSApp setMainMenu:menu];

Metadata

Metadata

Assignees

No one assigned

    Labels

    AppKitRelated to AppKit.framework or CocoaFrameworkAffecting a framework bundle or tools that build them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions