In MAC OS X 10.7, Apple introduced a new class called NSPopover and you can even drag away that popover view to become an independent NSWindow. However, I want to prevent user interaction to the main window until the detached window is closed. How can I safely do this?
Actually, a more common (and even more stupid) question should be, how to prevent any user interaction until current front window returns? I am noob to tread programming also.
I kind of found the solution myself. It looks working fine now.
To do this, after the detached window ordered to front and become key window, the following code will make it a modal window (where currModalSession is an iVar defined by myself).
- (void)windowDidBecomeKey:(NSNotification *)notification {
if (notification.object == detachedWindow) {
if (!detachedWindow.isModalPanel) {
currModalSession = [NSApp beginModalSessionForWindow:detachedWindow];
[NSApp runModalSession:currModalSession];
}
}
}
Also, you have to end each Modal Session you have opened. So the following code does the job:
- (void)windowWillClose:(NSNotification *)notification {
if (notification.object == detachedWindow) {
if (currModalSession) {
[NSApp endModalSession:currModalSession];
}
}
}
Note: you have to use Modal Session here rather than runModalForWindow for two reasons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With