Created
November 2, 2009 17:01
-
-
Save iafonov/224275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)createStatusItem | |
{ | |
statusItem = [[[NSStatusBar systemStatusBar] | |
statusItemWithLength:NSVariableStatusItemLength] | |
retain]; | |
[statusItem setHighlightMode:YES]; | |
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; | |
NSString *path = [bundle pathForResource:@"icon" ofType:@"png"]; | |
menuIcon= [[NSImage alloc] initWithContentsOfFile:path]; | |
[statusItem setTitle:[NSString stringWithString:@""]]; | |
[statusItem setImage:menuIcon]; | |
[statusItem setEnabled:YES]; | |
[statusItem setAction:@selector(popMenu:)]; | |
[statusItem setTarget:self]; | |
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; | |
[nc addObserver:self selector:@selector(applicationDidActivate:) name:NSApplicationDidBecomeActiveNotification object:app]; | |
} | |
-(IBAction)showMenu:(id)sender | |
{ | |
NSLog(@"showMenu"); | |
[statusItem popUpStatusItemMenu:loggedInMenu]; | |
} | |
-(IBAction)applicationDidActivate:(id)sender | |
{ | |
[self showMenu:self]; | |
} | |
-(IBAction)popMenu:(id)sender | |
{ | |
NSLog(@"popMenu"); | |
if ([app isActive]) { | |
[self showMenu:self]; | |
} else { | |
[app activateIgnoringOtherApps:YES]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment