Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added toggle to make the time's font color white. #64

Merged
merged 1 commit into from
Jul 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Battery Time Remaining/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define kBTRMenuEnergySaverSetting 9
#define kBTRMenuUpdater 10
#define kBTRMenuQuitKey 11
#define kBTRMenuWhiteText 12

#endif

Expand Down
47 changes: 42 additions & 5 deletions Battery Time Remaining/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ @interface AppDelegate ()
BOOL isOptionKeyPressed;
BOOL isCapacityWarning;
BOOL showParenthesis;
BOOL whiteText;
}

- (void)cacheBatteryIcon;
Expand Down Expand Up @@ -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:@""];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down