private void RunModal() { // webview only works on main runloop, not nested, so set up manual modal runloop var window = Window; IntPtr session = NSApplication.SharedApplication.BeginModalSession(window); NSRunResponse result = NSRunResponse.Continues; while (result == NSRunResponse.Continues) { using (var pool = new NSAutoreleasePool()) { var nextEvent = NSApplication.SharedApplication.NextEvent( NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoopMode.Default, true); // discard events that are for other windows, else they remain somewhat interactive if (nextEvent.Window != null && nextEvent.Window != window) { continue; } NSApplication.SharedApplication.SendEvent(nextEvent); // Run the window modally until there are no events to process result = (NSRunResponse)(long)NSApplication.SharedApplication.RunModalSession(session); // Give the main loop some time NSRunLoop.Current.LimitDateForMode(NSRunLoopMode.Default); } } NSApplication.SharedApplication.EndModalSession(session); }
//webview only works on main runloop, not nested, so set up manual modal runloop void RunModal() { var window = this; IntPtr session = NSApplication.SharedApplication.BeginModalSession(window); NSRunResponse result = NSRunResponse.Continues; while (result == NSRunResponse.Continues) { using (var pool = new NSAutoreleasePool()) { var nextEvent = NSApplication.SharedApplication.NextEvent(NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoop.NSDefaultRunLoopMode, true); //allow only events for this window and for the app //discard events that are for other windows, else they remain somewhat interactive if (nextEvent.Window != null && nextEvent.Window != window && nextEvent.Type != NSEventType.AppKitDefined) { continue; } NSApplication.SharedApplication.SendEvent(nextEvent); // Run the window modally until there are no events to process result = (NSRunResponse)(long)NSApplication.SharedApplication.RunModalSession(session); // Give the main loop some time NSRunLoop.Current.LimitDateForMode(NSRunLoopMode.Default); } } NSApplication.SharedApplication.EndModalSession(session); }
/// <summary> /// Ends a modal dialog. /// </summary> /// <param name="window">The dialog to end.</param> /// <param name="response">The result to report for the dialog ending.</param> public static void EndDialog(this NSWindow window, NSRunResponse response) { window.WillClose -= HandleWillClose; SingleInstanceApplication.Current.StopModalWithCode((int)response); if (window.IsSheet) { SingleInstanceApplication.Current.EndSheet(window); } window.Close(); window.Dispose(); }