MatterGoal
MatterGoal

Reputation: 16430

Show NSStatusItem menu only if App is active

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 ?

Upvotes: 1

Views: 439

Answers (1)

Enchilada
Enchilada

Reputation: 3919

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.

Upvotes: 1

Related Questions