From e26257006f120979bacc189b40205a413705725a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 21 Apr 2015 00:46:30 -0400 Subject: [PATCH] Converted the OS X menu code to the changes in the past few commits and made a few other small changes. --- darwin/menu.m | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/darwin/menu.m b/darwin/menu.m index 74fdf135..582de6c4 100644 --- a/darwin/menu.m +++ b/darwin/menu.m @@ -11,33 +11,30 @@ void appendMenuItem(NSMenu *menu, const uiMenuItem *item, struct menuConfig *men { NSMenuItem *mitem; - if (item->Name == uiMenuItemQuit) { - // TODO verify type - menuConfig->hasQuit = YES; - return; - } - if (item->Name == uiMenuItemPreferences) { - // TODO verify type - menuConfig->hasPreferences = YES; - return; - } - if (item->Name == uiMenuItemAbout) { - // TODO verify type - menuConfig->hasAbout = YES; - return; - } - if (item->Name == uiMenuItemSeparator) { - // TODO verify type - [menu addItem:[NSMenuItem separatorItem]]; - return; - } switch (item->Type) { case uiMenuItemTypeCommand: case uiMenuItemTypeCheckbox: mitem = [[NSMenuItem alloc] initWithTitle:toNSString(item->Name) action:NULL keyEquivalent:@""]; [menu addItem:mitem]; return; + case uiMenuItemTypeQuit: + // TODO verify name + menuConfig->hasQuit = YES; + return; + case uiMenuItemTypePreferences: + // TODO verify name + menuConfig->hasPreferences = YES; + return; + case uiMenuItemTypeAbout: + // TODO verify name + menuConfig->hasAbout = YES; + return; + case uiMenuItemTypeSeparator: + // TODO verify name + [menu addItem:[NSMenuItem separatorItem]]; + return; } + // TODO complain } NSMenuItem *makeMenu(const char *name, const uiMenuItem *items, struct menuConfig *menuConfig) @@ -48,7 +45,7 @@ NSMenuItem *makeMenu(const char *name, const uiMenuItem *items, struct menuConfi menubarItem = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:NULL keyEquivalent:@""]; menu = [[NSMenu alloc] initWithTitle:toNSString(name)]; - for (i = items; i->Name != NULL; i++) + for (i = items; i->Type != 0; i++) appendMenuItem(menu, i, menuConfig); [menubarItem setSubmenu:menu]; return menubarItem; @@ -57,11 +54,19 @@ NSMenuItem *makeMenu(const char *name, const uiMenuItem *items, struct menuConfi NSMenu *makeMenubar(void) { NSMenu *menubar; + NSMenuItem *applicationMenuItem; + NSMenu *applicationMenu; struct menuConfig menuConfig; const uiMenu *m; menubar = [[NSMenu alloc] initWithTitle:@""]; + // TODO give the application name? + applicationMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""]; + applicationMenu = [[NSMenu alloc] initWithTitle:@""]; + [applicationMenuItem setSubmenu:applicationMenu]; + [menubar addItem:applicationMenuItem]; + memset(&menuConfig, 0, sizeof (struct menuConfig)); for (m = options.Menu; m->Name != NULL; m++) [menubar addItem:makeMenu(m->Name, m->Items, &menuConfig)];