1
votes

I'm working on an OS X app and am new to Swift and OS X development. I have a window that I want to be modal and at times will have a lot of content to display so I want to allow it to enter FullScreen mode. The window nib and the code below accomplish this but exiting FullScreen mode causes the window to disappear. If I go to another desktop and return, the window is back. Below is my app delegate code.

import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {
    let theApp: NSApplication = NSApplication.sharedApplication()
    var fooController: FooController?

    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        // Insert code here to initialize your application
    }

    @IBAction func sessionFoo(sender: AnyObject) {
        if fooController == nil {
            fooController = FooController(windowNibName: "FooWindow")
        }

        // This works when it returns from FullScreen but isn't modal
        // fooController!.showWindow(self)

        // This is modal but the window disappears when returning from FullScreen
        theApp.runModalForWindow(fooController!.window)
    }
}

In the Attributes Inspector for the window: The following are checked:

   Shadow
   Close
   Resize
   Restorable
   Deferred (for Memory)


Everything is "Inferred Behavior"
Full Screen is "Primary Window", I tried "Auxiliary Window" with no luck.
Memory is "Buffered".

This a secondary window for a Document Based app. What am I missing? Thanks.

1
I presume it is because making a window fullscreen ends the modal window.Brad Allred
No, the modal window isn't ending. In fullscreen, the modal window is present and behaves as desired. Exiting fullscreen causes the modal window to no longer be visible but the primary window still can't receive input just as when the modal window was present. After switching to a different OS X desktop and back, the modal window reappears and still has modal behavior.user2129643

1 Answers

0
votes

1.overrides NSWindowDelegate.windowDidExitFullScreen;

2.set the NSWindow.Delegate;

3.call NSWindow.makeKeyAndOrderFront or NSWindow.OrderFront in the windowDidExitFullScreen;

public class tbWindowDelegate : NSWindowDelegate
{   
    public EventHandler WindowFullScreenDidExit;

    public override void DidExitFullScreen(NSNotification notification)
    {
        if (WindowFullScreenDidExit != null)
            WindowFullScreenDidExit(notification, EventArgs.Empty);
    }
}


public class tbWindow : NSWindow
{       
    protected bool mRunModal = false;
    protected tbWindowDelegate mDelegate = null;

    public tbWindow() : base()
    {
        this.InitEvent();
    }

    private void InitEvent()
    {           
        this.mDelegate = new tbWindowDelegate();
        this.mDelegate.WindowFullScreenDidExit = this.OnWindowFullScreenDidExit;
        this.Delegate = this.mDelegate;
    }


    protected virtual void OnWindowFullScreenDidExit(object sender, EventArgs e)
    {
        if (this.mRunModal)
        {
            //this.MakeKeyAndOrderFront(this);
            this.OrderFront(this);
        }

    }   

}