Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-show my main Cocoa application Window

Ok, as simple and silly as that may seem, this is my scenario :

  • The application window (there is just ONE main window) is minimized
  • The user clicks something on the dock menu
  • We want to bring that main window back

Simple?

Not quite.

I've tried accessing my main window via :

  • [[NSApplication sharedApplication] mainWindow]
  • [[NSApplication sharedApplication] windows]

and then sending a makeKeyAndOrderFront: message but it's simply NOT showing up.

I've even tried showing all windows (yep, it still sees as "windows" one-or-two (hidden) sheets I'm using...), but still nothing.

Could you suggest a way, I could finally show that window, WITHOUT having to set an outlet anywhere?

I don't know; I'm probably too tired to notice, but this thing is almost nerve-wrecking...

like image 974
Dr.Kameleon Avatar asked Dec 20 '22 23:12

Dr.Kameleon


1 Answers

You can un-minimize a window like so:

if([aWindow isMiniaturized])
{
   [aWindow deminiaturize:self];
}

However, the problem is that the window will lose main status when it is minimized, so you'll need some other way of identifying the window.

Why can't you just use an outlet?

You can make the app un-minimize all of its minimized windows like so:

for(NSWindow* win in [NSApp windows])
{
    if([win isMiniaturized])
    {
        [win deminiaturize:self];
    }
}

When the app launches, you could store a reference to the main window and register for the NSWindowDidMiniaturizeNotification. That will tell you when the main window minimizes, which might also help you.

like image 104
Rob Keniger Avatar answered Jan 05 '23 13:01

Rob Keniger