Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Preference in Window

  • Loading branch information...
commit 356379e910962b93e2a7869f80eb5967b96f87f2 1 parent 734cedd
Han Lin Yap authored
1  Battery Time Remaining/AppDelegate.h
@@ -31,6 +31,7 @@
31 31 - (NSImage *)getBatteryIconNamed:(NSString *)iconName;
32 32 - (NSImage *)getBatteryIconPercent:(NSInteger)percent;
33 33
  34 +@property (strong) NSWindow *window;
34 35 @property (strong) NSStatusItem *statusItem;
35 36 @property (nonatomic) NSInteger previousPercent;
36 37 @property (nonatomic) NSInteger currentPercent;
48 Battery Time Remaining/AppDelegate.m
@@ -48,10 +48,11 @@ - (NSImage *)loadBatteryIconNamed:(NSString *)iconName;
48 48
49 49 @implementation AppDelegate
50 50
51   -@synthesize statusItem, notifications, previousPercent;
  51 +@synthesize statusItem, notifications, previousPercent, window;
52 52
53 53 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
54 54 {
  55 + [self preferenceWindow];
55 56 self.advancedSupported = ([self getAdvancedBatteryInfo] != nil);
56 57 [self cacheBatteryIcon];
57 58 isCapacityWarning = NO;
@@ -481,6 +482,51 @@ - (void)cacheBatteryIcon {
481 482 nil];
482 483 }
483 484
  485 +- (void)preferenceWindow
  486 +{
  487 + int vW; // view Width
  488 + int vH; // view Height
  489 + int vLP; // view Left Padding
  490 + int vTP; // view Top Padding
  491 + int vAW; // view Auto Width (vW minus padding)
  492 + int vAH; // view Auto Height (vH minus padding)
  493 + int rH; // text row Height
  494 +
  495 + vW = vH = 300;
  496 + rH = 18;
  497 + vLP = vTP = 20;
  498 + vAW = vW - vLP * 2;
  499 + vAH = vH - vTP * 2;
  500 +
  501 + NSRect frame = NSMakeRect(0, 0, vW, vH);
  502 +
  503 + window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask | NSClosableWindowMask backing:NSBackingStoreBuffered defer:NO];
  504 +
  505 + [window setTitle:@"Battery Time Remaining Preferences"];
  506 +
  507 + NSView *view = [[NSView new] initWithFrame:frame];
  508 +
  509 + NSButton *btnAdvanced = [[NSButton alloc] initWithFrame:NSMakeRect(vLP, vAH - rH + vTP, vAW, rH)];
  510 + [btnAdvanced setButtonType:NSSwitchButton];
  511 + [btnAdvanced setTitle:NSLocalizedString(@"Advanced mode", @"Advanced mode setting")];
  512 + [btnAdvanced setTarget:[[self.statusItem.menu itemWithTag:kBTRMenuSetting].submenu itemWithTag:kBTRMenuAdvanced]];
  513 + [btnAdvanced setAction:@selector(toggleAdvanced:)];
  514 +
  515 + NSButton *btnParenthesis = [[NSButton alloc] initWithFrame:NSMakeRect(vLP, vAH - rH * 2 + vTP, vAW, rH)];
  516 + [btnParenthesis setButtonType:NSSwitchButton];
  517 + [btnParenthesis setTitle:NSLocalizedString(@"Display time with parentheses", @"Display time with parentheses setting")];
  518 + [btnParenthesis setTarget:[[self.statusItem.menu itemWithTag:kBTRMenuSetting].submenu itemWithTag:kBTRMenuParenthesis]];
  519 + [btnParenthesis setAction:@selector(toggleParenthesis:)];
  520 +
  521 + [view addSubview:btnAdvanced];
  522 + [view addSubview:btnParenthesis];
  523 + [window setContentView:view];
  524 + [window makeKeyAndOrderFront:nil];
  525 + [window center];
  526 +
  527 + // [icon] ([time]) [percent] [mAh]
  528 +}
  529 +
484 530 - (void)openEnergySaverPreference:(id)sender
485 531 {
486 532 [[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/EnergySaver.prefPane"];

0 comments on commit 356379e

Please sign in to comment.
Something went wrong with that request. Please try again.