Reputation: 1031
Im pretty sure the answer must be quite easy, but for some reason I can't get it to work!
I have a window, and this code:
[someWindow setHidesOnDeactivate:YES];
I have a status item, and the following code
- (void)openWindow{
if ([someWindow isVisible]) {
NSLog(@"CLOSING");
[lyricWindow close];
}else {
[someWindow makeKeyAndOrderFront:nil];
NSLog(@"SHOWING");
}
}
This worked when I closed the window and wanted to open it again. Now that I've implemented the hides of deactivate I am lost as to what I need to do! I've tried all sorts of things... I want the window to show again and the window to become active when I click the status item! I think thats my problem.
How can I make the window active when I click on a status item?
I get the following in the log:
CLOSING SHOWING CLOSING SHOWING
Closing is first regardless if the window is hidden or not, which is rather intriguing, because id guess isVisible
would return false
if the window has been hidden. Anyhow, I get no window. How can I unhide the window?
Thanks!
Upvotes: 3
Views: 2792
Reputation: 13589
I had this same problem where I couldn't get a window to re-show after it was hidden from deactivation. In my case, I was showing a NSPanel (subclass of NSWindow) when a NSStatusItem was pressed.
The following code finally got my NSPanel to re-show up:
[NSApp arrangeInFront:sender];
[myWindow makeKeyAndOrderFront:sender];
[NSApp activateIgnoringOtherApps:YES];
I'm pretty sure 'activateIgnoringOtherApps' is the key here. For me, it's not ideal because it takes focus away from the user's current application.
Upvotes: 10