diff options
Diffstat (limited to 'Slimber/Cocoa/Menulet.m')
-rw-r--r-- | Slimber/Cocoa/Menulet.m | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/Slimber/Cocoa/Menulet.m b/Slimber/Cocoa/Menulet.m index 2f0f465..613d05d 100644 --- a/Slimber/Cocoa/Menulet.m +++ b/Slimber/Cocoa/Menulet.m @@ -2,36 +2,44 @@ @implementation Menulet +- (id) init { + if ([super init]) { + statusMenu = [[NSMenu alloc] init]; + + statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength] retain]; + [statusItem setHighlightMode: YES]; + [statusItem setEnabled: YES]; + [statusItem setToolTip: @"Slimber"]; + [statusItem setMenu: statusMenu]; + + NSBundle* bundle = [NSBundle bundleForClass: [self class]]; + NSString* path = [bundle pathForResource: @"Offline" ofType:@"png"]; + menuIcon = [[NSImage alloc] initWithContentsOfFile: path]; + [statusItem setImage: menuIcon]; + + [self updateMenu]; + } + return self; +} + - (void) dealloc { [statusItem release]; [menuIcon release]; [super dealloc]; } -- (void) awakeFromNib { - statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength: NSVariableStatusItemLength] retain]; - [statusItem setHighlightMode: YES]; - [statusItem setEnabled: YES]; - [statusItem setToolTip: @"Slimber"]; - [statusItem setMenu: statusMenu]; - - NSBundle* bundle = [NSBundle bundleForClass: [self class]]; - NSString* path = [bundle pathForResource: @"Offline" ofType:@"png"]; - menuIcon = [[NSImage alloc] initWithContentsOfFile: path]; - [statusItem setImage: menuIcon]; - - NSMenuItem* statusMenuItem = [[NSMenuItem alloc] initWithTitle: @"Online Users" action: NULL keyEquivalent:@""]; +- (void) updateMenu { + NSMenuItem* statusMenuItem = [[NSMenuItem alloc] initWithTitle: @"Online Users" action: NULL keyEquivalent: @""]; [statusMenu addItem: statusMenuItem]; [statusMenu addItem: [NSMenuItem separatorItem]]; - NSMenuItem* loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are not logged in" action: NULL keyEquivalent:@""]; + + NSMenuItem* loggedInItem = [[NSMenuItem alloc] initWithTitle: @"You are not logged in" action: NULL keyEquivalent: @""]; [statusMenu addItem: loggedInItem]; -} + [statusMenu addItem: [NSMenuItem separatorItem]]; -- (IBAction) updateStatus: (id) sender { - [statusItem setTitle: [NSString stringWithString:@"Boo"]]; - NSMenuItem* statusMenuItem = [[NSMenuItem alloc] initWithTitle: @"Foo" action: @selector(updateStatus:) keyEquivalent:@""]; - [statusMenuItem setTitle:[NSString stringWithString:@"Boo"]]; - [statusMenu insertItem: statusMenuItem atIndex:1]; + NSMenuItem* exitMenuItem = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""]; + [exitMenuItem setTarget: [NSApplication sharedApplication]]; + [statusMenu addItem: exitMenuItem]; } @end |