I have a document-based application, with a main document window and several "satellite" NSPanel windows showing related info. They are not floating, they can (and do) become key, and seem to be at the same layer as the main window.
I try to implement a show/hide action like thus: If a panel is not visible - show it. If it is visible, but not front - make it front. If it is visible and front - hide it.
For that I need to know if an NSPanel is "frontmost". Sadly no NSWindow API exists for that. I tried to use windowNumbersWithOptions
to compare z-order of my Panels for that.
-(void) togglePanelVisibility:(PMXPanelController *)panelController {
NSPanel *panel = [panelController window];
if ([panel isVisible]) {
NSArray *windowNumbers = [NSWindow windowNumbersWithOptions:0];
if ([panel windowNumber] == [[windowNumbers firstObject] integerValue]) {
[panel orderOut:self];
}
else {
[panel makeKeyAndOrderFront:self];
}
} else
[panelController showWindow:self];
}
Alas, the array I receive only includes one number - for my main document window. I can see my panels in the "Window" menu, I can click them to bring them to front, I can close them and use them - but I can't get their number via windowNumbersWithOptions:
Ideas anyone?
Following the given suggestions, I finally came out with the following, which seems to work for me reasonably.