Created
July 9, 2014 07:47
-
-
Save skela/87cf62944fbfc23cb83c to your computer and use it in GitHub Desktop.
Sample Code for "NSRightMouseDownMask Flag ignored for NSStatusItem sendActionOn"
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)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; | |
self.statusItem.target = self; | |
self.statusItem.action = @selector(clickStatusItem:); | |
[self.statusItem sendActionOn:(NSLeftMouseDownMask|NSRightMouseDownMask)]; | |
NSImage *img = [NSImage imageNamed:@"icon_empty"]; | |
[img setTemplate:YES]; | |
self.statusItem.image = img; | |
} | |
- (IBAction)clickStatusItem:(id)sender { | |
BOOL rightClick = (([[NSApp currentEvent] modifierFlags] & NSControlKeyMask) == NSControlKeyMask) || ([[NSApp currentEvent] type] == NSRightMouseDown); | |
if (rightClick) { | |
[self singleRightClickedStatusItem:sender]; | |
} else { | |
[self singleLeftClickedStatusItem:sender]; | |
} | |
} | |
-(IBAction)singleLeftClickedStatusItem:(id)sender { | |
NSLog(@"Left Clicked Status Item"); | |
} | |
-(IBAction)singleRightClickedStatusItem:(id)sender { | |
NSLog(@"Right Clicked Status Item"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment