开发者

Show NSStatusItem menu only if App is active

开发者 https://www.devze.com 2023-03-27 15:44 出处:网络
I\'m using this method to show the NSStatusItem menu only if application is Active. -(void)menuWillOpen:(NSMenu*)menu{

I'm using this method to show the NSStatusItem menu only if application is Active.

-(void)menuWillOpen:(NSMenu*)menu{  
    if(![NSApp isActive]){
        [menu cancelTracking];
    }
    [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
    [window makeKeyAndOrderFront:self]; 
}

开发者_开发问答It perfectly works, but cancelTracking seems to block the blue highlight of the NSStatusItem. So when i click on status menu item it doesn't show the submenu and it presents the main window, but the icon is not highlighted. Is there a way to make it happen ?


I suggest creating a custom view if you need more precise control over when the status item highlights itself. Then you can use mouseDown: etc. This is a good example of putting your custom view in a status item.

0

精彩评论

暂无评论...
验证码 换一张
取 消