views:

60

answers:

1

Here's my code:

if ([window isVisible]) {
   [NSApp activateIgnoringOtherApps:YES];
   [window orderOut:nil]; 
   return;
} 
[NSApp activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:nil];
return;

but if the user clicks/changes the current window and then clicks on menu bar it will close the window. How do I stop that?

+1  A: 

Instead of testing whether the window is ordered in (isVisible), test whether it is the active window ([NSApp mainWindow] or [NSApp keyWindow]details) and whether your application is active ([NSApp isActive]).

Peter Hosey