From 4a18277a3ad20630dd54feff9195ec70439a6c64 Mon Sep 17 00:00:00 2001 From: Robert McGovern Date: Mon, 31 May 2021 22:42:01 +0100 Subject: [PATCH] Cleaned up code for status bar and status bar menu --- QuietUnrarAppDelegate.m | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/QuietUnrarAppDelegate.m b/QuietUnrarAppDelegate.m index be3699f..9799036 100644 --- a/QuietUnrarAppDelegate.m +++ b/QuietUnrarAppDelegate.m @@ -219,30 +219,30 @@ BOOL appRunning = NO; - (void) showStatusBarItem: (BOOL) show { if (show) { -// if (statusBarItem == nil) { - statusBarItem = [NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength]; - statusBarItem.button.title = @"🎫"; //RMCG - - // optional create a menu for the button - NSMenu * statusBarMenu = [[NSMenu alloc] init]; - [statusBarMenu setTitle:@"QuietUnrar Menu"]; - - NSMenuItem * preferencesMenuItem = [[NSMenuItem alloc] initWithTitle:@"Show Preferences" action:@selector(showPreferencesWindow) keyEquivalent:@""]; - [statusBarMenu addItem:preferencesMenuItem]; - - NSMenuItem * showDockItem = [[NSMenuItem alloc] initWithTitle:@"Show Dock" action:@selector(showPreferencesWindow) keyEquivalent:@""]; - [statusBarMenu addItem:showDockItem]; - - NSMenuItem * quitMenuItem = [[NSMenuItem alloc] initWithTitle:@"Quit QuietUnrar" action:@selector(quit) keyEquivalent:@""]; - [statusBarMenu addItem:quitMenuItem]; - - [statusBarItem setMenu:statusBarMenu]; -// } + statusBarItem = [NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength]; + statusBarItem.button.title = @"🎫"; //RMCG change to something more appropriate + [statusBarItem setMenu:[self makeStatusBarMenu]]; } else { [NSStatusBar.systemStatusBar removeStatusItem:statusBarItem]; } } +- (NSMenu *) makeStatusBarMenu { + NSMenu * statusBarMenu = [[NSMenu alloc] init]; + [statusBarMenu setTitle:@"QuietUnrar Menu"]; + + NSMenuItem * preferencesMenuItem = [[NSMenuItem alloc] initWithTitle:@"Show Preferences" action:@selector(showPreferencesWindow) keyEquivalent:@""]; + [statusBarMenu addItem:preferencesMenuItem]; + +// NSMenuItem * showDockItem = [[NSMenuItem alloc] initWithTitle:@"Show Dock " action:@selector(showPreferencesWindow) keyEquivalent:@""]; +// [statusBarMenu addItem:showDockItem]; +// + NSMenuItem * quitMenuItem = [[NSMenuItem alloc] initWithTitle:@"Quit QuietUnrar" action:@selector(quit) keyEquivalent:@""]; + [statusBarMenu addItem:quitMenuItem]; + + return statusBarMenu; +} + - (void) showPreferencesWindow { if (preferencesWindowController == nil) { preferencesWindowController = [[TDNPreferencesWindowController alloc] init];