2020-02-28 13:34:34 +11:00
|
|
|
//! A wrapper for `NSAlert`. Currently doesn't cover everything possible for this class, as it was
|
|
|
|
//! built primarily for debugging uses. Feel free to extend via pull requests or something.
|
|
|
|
|
|
|
|
use objc_id::Id;
|
|
|
|
use objc::runtime::Object;
|
|
|
|
use objc::{class, msg_send, sel, sel_impl};
|
|
|
|
|
2020-03-18 10:55:09 +11:00
|
|
|
use crate::foundation::{id, NSString};
|
|
|
|
|
2020-02-28 13:34:34 +11:00
|
|
|
/// Represents an `NSAlert`. Has no information other than the retained pointer to the Objective C
|
|
|
|
/// side, so... don't bother inspecting this.
|
2020-03-18 10:55:09 +11:00
|
|
|
pub struct Alert(Id<Object>);
|
2020-02-28 13:34:34 +11:00
|
|
|
|
|
|
|
impl Alert {
|
|
|
|
/// Creates a basic `NSAlert`, storing a pointer to it in the Objective C runtime.
|
|
|
|
/// You can show this alert by calling `show()`.
|
|
|
|
pub fn new(title: &str, message: &str) -> Self {
|
2020-03-18 10:55:09 +11:00
|
|
|
let title = NSString::new(title);
|
|
|
|
let message = NSString::new(message);
|
|
|
|
let x = NSString::new("OK");
|
|
|
|
|
|
|
|
Alert(unsafe {
|
|
|
|
let alert: id = msg_send![class!(NSAlert), new];
|
|
|
|
let _: () = msg_send![alert, setMessageText:title];
|
|
|
|
let _: () = msg_send![alert, setInformativeText:message];
|
|
|
|
let _: () = msg_send![alert, addButtonWithTitle:x];
|
|
|
|
Id::from_ptr(alert)
|
|
|
|
})
|
2020-02-28 13:34:34 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Shows this alert as a modal.
|
|
|
|
pub fn show(&self) {
|
|
|
|
unsafe {
|
2020-03-18 10:55:09 +11:00
|
|
|
let _: () = msg_send![&*self.0, runModal];
|
2020-02-28 13:34:34 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|