Skip to content

Only create submenu if more than 1 file type is selected #19

@coldrifting

Description

@coldrifting

Hi, I'm liking the app, don't know why this isn't built into the OS already. I think it would be nice to show submenu items in the main menu if only 1 item is selected. I managed to get this to work on my mac on the new-version branch, but I'm not sure which branch is the most up to date. Heres the code I used. I've literally never used objective-c before so feel free to change anything if you end up doing this, ha.

if (submenu.numberOfItems > 1) {
    NSMenuItem *mainItem = [[NSMenuItem alloc] initWithTitle:@"New File" action:nil keyEquivalent:@""];
    NSImage *mainIcon = [NSImage imageNamed:@"add"];
    mainItem.image = mainIcon;
    mainItem.submenu = submenu;
    [menu addItem:mainItem];
}

if (submenu.numberOfItems == 1) {
    NSString *title = [@"New " stringByAppendingString:submenu.itemArray[0].title];
    NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:title action:submenu.itemArray[0].action keyEquivalent:@""];
    newItem.image = submenu.itemArray[0].image;
    [menu addItem:newItem];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions