diff --git a/Battery Time Remaining/AppDelegate.h b/Battery Time Remaining/AppDelegate.h index 801d18b..6fe0e65 100644 --- a/Battery Time Remaining/AppDelegate.h +++ b/Battery Time Remaining/AppDelegate.h @@ -22,6 +22,7 @@ #define kBTRMenuEnergySaverSetting 9 #define kBTRMenuUpdater 10 #define kBTRMenuQuitKey 11 +#define kBTRMenuWhiteText 12 #endif diff --git a/Battery Time Remaining/AppDelegate.m b/Battery Time Remaining/AppDelegate.m index 64f6c28..dec7bef 100644 --- a/Battery Time Remaining/AppDelegate.m +++ b/Battery Time Remaining/AppDelegate.m @@ -39,6 +39,7 @@ @interface AppDelegate () BOOL isOptionKeyPressed; BOOL isCapacityWarning; BOOL showParenthesis; + BOOL whiteText; } - (void)cacheBatteryIcon; @@ -124,10 +125,18 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification showParenthesis = [[NSUserDefaults standardUserDefaults] boolForKey:@"parentheses"]; parenthesisSubmenuItem.state = (showParenthesis) ? NSOnState : NSOffState; + // Toggle Black & White Text + NSMenuItem *colorTextSubmenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"White Text Color", @"White Text Color") action:@selector(toggleTextColor:) keyEquivalent:@""]; + [colorTextSubmenuItem setTag:kBTRMenuWhiteText]; + colorTextSubmenuItem.target = self; + whiteText = [[NSUserDefaults standardUserDefaults] boolForKey:@"whiteText"]; + colorTextSubmenuItem.state = (whiteText) ? NSOnState : NSOffState; + // Build the setting submenu NSMenu *settingSubmenu = [[NSMenu alloc] initWithTitle:@"Setting Menu"]; [settingSubmenu addItem:advancedSubmenuItem]; [settingSubmenu addItem:parenthesisSubmenuItem]; + [settingSubmenu addItem:colorTextSubmenuItem]; // Settings menu item NSMenuItem *settingMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Settings menuitem") action:nil keyEquivalent:@""]; @@ -363,11 +372,18 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title [self.statusItem setAlternateImage:[ImageFilter invertColor:image]]; // Title - NSDictionary *attributedStyle = [NSDictionary dictionaryWithObjectsAndKeys: - // Font - [NSFont menuFontOfSize:12.0f], - NSFontAttributeName, - nil]; + NSMutableDictionary *attributedStyle = [NSMutableDictionary dictionaryWithObjectsAndKeys: + // Font + [NSFont menuFontOfSize:12.0f], + NSFontAttributeName, + nil]; + + if(whiteText) { + [attributedStyle setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName]; + } else { + [attributedStyle setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName]; + } + NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributedStyle]; self.statusItem.attributedTitle = attributedTitle; @@ -572,6 +588,27 @@ - (void)toggleParenthesis:(id)sender [self updateStatusItem]; } +- (void)toggleTextColor:(id)sender { + NSMenuItem *item = sender; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + if ([defaults boolForKey:@"whiteText"]) + { + item.state = NSOffState; + whiteText = NO; + [defaults setBool:NO forKey:@"whiteText"]; + } + else + { + item.state = NSOnState; + whiteText = YES; + [defaults setBool:YES forKey:@"whiteText"]; + } + [defaults synchronize]; + + [self updateStatusItem]; +} + - (void)notify:(NSString *)message { [self notify:@"Battery Time Remaining" message:message];