Skip to content

Instantly share code, notes, and snippets.

@andrewsardone
Created May 6, 2009 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsardone/107299 to your computer and use it in GitHub Desktop.
Save andrewsardone/107299 to your computer and use it in GitHub Desktop.
#import "AppController.h"
@implementation AppController
- (void)awakeFromNib {
NSMenu *menu = [self createMenu];
menuItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:24] retain];
[menuItem setImage:[NSImage imageNamed:@"41-picture-frame"]];
[menuItem setTarget:self];
[menuItem setAction:@selector(menuItemClick:)];
[menuItem setMenu:menu];
[menuItem setHighlightMode:YES];
}
- (void)menuItemClick:(id)sender{
if ([oMainWindow isVisible]) {
if ([oMainWindow isKeyWindow]) {
[oMainWindow performClose:self];
} else {
[NSApp activateIgnoringOtherApps:YES];
}
} else {
[NSApp activateIgnoringOtherApps:YES];
[oMainWindow makeKeyAndOrderFront:self];
}
}
- (NSMenu *)createMenu {
NSZone *menuZone = [NSMenu menuZone];
NSMenu *menu = [[NSMenu allocWithZone:menuZone] init];
NSMenuItem *menuItem = [menu addItemWithTitle:@"Quit" action:@selector(appTerminate:) keyEquivalent:@""];
[menuItem setTarget:self];
return menu;
}
- (void)appTerminate:(id)sender {
[NSApp terminate:sender];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment