From 10b578e6d26f6b493be91c0ecf0dfb9e4f8e7193 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Thu, 21 Nov 2019 14:45:09 +0100 Subject: [PATCH] Add help menu to macOS menu bar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most macOS Apps have a Help menu as the last menu item in the menu bar. They usually have a menu item with the keyboard shortcut +?, which shows some kind of help or documentation. I named the menu item "Visit kitty website" and let it open the kitty website as documentation. macOS also magically adds a search feature to the help menu. --- kitty/cocoa_window.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index e273ba6a4..db8873613 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -83,6 +83,11 @@ find_app_name(void) { set_cocoa_pending_action(NEW_OS_WINDOW, NULL); } +- (void)open_kitty_website_url:(id)sender { + (void)sender; + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://sw.kovidgoyal.net/kitty/"]]; +} + + (GlobalMenuTarget *) shared_instance { @@ -313,6 +318,18 @@ cocoa_create_global_menu(void) { [NSApp setWindowsMenu:windowMenu]; [windowMenu release]; + NSMenuItem* helpMenuItem = + [bar addItemWithTitle:@"Help" + action:NULL + keyEquivalent:@""]; + NSMenu* helpMenu = [[NSMenu alloc] initWithTitle:@"Help"]; + [helpMenuItem setSubmenu:helpMenu]; + [[helpMenu addItemWithTitle:[NSString stringWithFormat:@"Visit %@ website", app_name] + action:@selector(open_kitty_website_url:) + keyEquivalent:@"?"] + setTarget:global_menu_target]; + [helpMenu release]; + [bar release]; class_addMethod(