I'm new to objective-c programming and I'm trying to make a status bar application right now.
I only know how to set a dropdown menu to show when click on the status bar item.
However, what I want is to show a panel
when left clicked and show the menu
when right clicked, just like the way Bartender 2
acts.
I've referred this demo but I could hardly figure out what it does.
I use xib
to build my UI. I have three .xib
files: MainMenu
, Preferences
and MainPanel
.
AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property NSStatusItem *statusItem;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "Menu.h" //Menu is a ViewController for Menu.xib
@interface AppDelegate ()
//@property (weak) IBOutlet NSWindow *window; //I don't know what is this for
@end
@implementation AppDelegate
@synthesize statusItem;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
//I initiate my statusItem here
-(void)awakeFromNib{
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
self.statusItem.title = @"T";
// you can also set an image
//self.statusBar.image =
self.statusItem.highlightMode = YES;
//I tried to use these code to set the left click action
[statusItem setTarget:self];
[statusItem setAction:@selector(showMenu:)];
}
-(void)showMenu{
Menu* menuVC = [[Menu alloc] initWithNibName:@"Menu" bundle:nil];
//Don't know what to do next...
}
@end
I tried to use
[menuVC showWindow];
but it is not right.