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
  • Loading branch information
dtzxporter committed Feb 8, 2024
1 parent 49c04ff commit e91b08a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/backend/macos/file_dialog/panel_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,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
15 changes: 14 additions & 1 deletion 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 Down Expand Up @@ -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,24 @@ 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(|_: u32| {}) };

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 e91b08a

Please sign in to comment.