Skip to content

Commit

Permalink
Fix message dialog sync on macOS as well. Re-order parent in panel_ffi.
Browse files Browse the repository at this point in the history
Update panel_ffi.rs

Attempt to fix issue with modal windows.
  • Loading branch information
dtzxporter committed Feb 8, 2024
1 parent 29fe1df commit bd70d6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/backend/macos/file_dialog/panel_ffi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::FileDialog;

use std::mem;
use std::path::Path;
use std::{ops::DerefMut, path::PathBuf};

Expand Down Expand Up @@ -29,9 +30,9 @@ fn make_nsstring(s: &str) -> Id<NSString> {

pub struct Panel {
pub(crate) panel: Id<Object>,
parent: Option<Id<NSWindow, Shared>>,
_focus_manager: FocusManager,
_policy_manager: PolicyManager,
parent: Option<Id<NSWindow, Shared>>,
}

impl AsModal for Panel {
Expand Down Expand Up @@ -65,11 +66,13 @@ impl Panel {

pub fn run_modal(&self) -> i32 {
if let Some(parent) = self.parent.clone() {
let completion: *const () = std::ptr::null();
let completion = { block::ConcreteBlock::new(|_: isize| {}) };

unsafe {
msg_send![self.panel, beginSheetModalForWindow: parent completionHandler: &completion]
}

mem::forget(completion);
}

unsafe { msg_send![self.panel, runModal] }
Expand Down
23 changes: 21 additions & 2 deletions src/backend/macos/message_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::mem;
use std::ops::DerefMut;

use crate::backend::DialogFutureType;
Expand All @@ -9,7 +10,7 @@ use super::{
AsModal,
};

use super::utils::{INSWindow, NSWindow};
use super::utils::{INSApplication, INSWindow, NSApplication, NSWindow};
use objc::runtime::Object;
use objc::{class, msg_send, sel, sel_impl};
use objc_foundation::{INSString, NSString};
Expand All @@ -35,6 +36,7 @@ enum NSAlertReturn {
pub struct NSAlert {
buttons: MessageButtons,
alert: Id<Object>,
parent: Option<Id<NSWindow>>,
_focus_manager: FocusManager,
_policy_manager: PolicyManager,
}
Expand Down Expand Up @@ -93,13 +95,30 @@ impl NSAlert {

Self {
alert: unsafe { Id::from_retained_ptr(alert) },
parent: opt.parent.map(|x| NSWindow::from_raw_window_handle(&x)),
buttons: opt.buttons,
_focus_manager,
_policy_manager,
}
}

pub fn run(self) -> MessageDialogResult {
pub fn run(mut self) -> MessageDialogResult {
if let Some(parent) = self.parent.take() {
let completion = {
block::ConcreteBlock::new(|result: isize| {
let _: () = unsafe {
msg_send![NSApplication::shared_application(), stopModalWithCode: result]
};
})
};

unsafe {
msg_send![self.alert, beginSheetModalForWindow: parent completionHandler: &completion]
}

mem::forget(completion);
}

let ret: i64 = unsafe { msg_send![self.alert, runModal] };
dialog_result(&self.buttons, ret)
}
Expand Down

0 comments on commit bd70d6d

Please sign in to comment.