Merge branch 'trunk' of github.com:ryanmcgrath/cacao into trunk

* 'trunk' of github.com:ryanmcgrath/cacao:
  implemented applicationShouldTerminateAfterLastWindowClosed
This commit is contained in:
Ryan McGrath 2021-03-17 21:42:18 -07:00
commit 85eaedca2a
3 changed files with 16 additions and 0 deletions

View file

@ -48,6 +48,9 @@ impl AppDelegate for CalculatorApp {
self.window.set_content_view(&self.content);
self.window.show();
}
fn should_terminate_after_last_window_closed(&self) -> bool {
true
}
}
impl Dispatcher for CalculatorApp {

View file

@ -227,6 +227,14 @@ extern fn should_open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id
}
}
/// Fired when the application receives an `applicationShouldTerminateAfterLastWindowClosed:` message.
extern fn should_terminate_after_last_window_closed<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
match app::<T>(this).should_terminate_after_last_window_closed() {
true => YES,
false => NO
}
}
/// Fired when the application receives an `applicationOpenUntitledFile:` message.
extern fn open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
match app::<T>(this).open_untitled_file() {
@ -309,6 +317,7 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
// Terminating Applications
decl.add_method(sel!(applicationShouldTerminate:), should_terminate::<T> as extern fn(&Object, _, _) -> NSUInteger);
decl.add_method(sel!(applicationWillTerminate:), will_terminate::<T> as extern fn(&Object, _, _));
decl.add_method(sel!(applicationShouldTerminateAfterLastWindowClosed:), should_terminate_after_last_window_closed::<T> as extern fn(&Object, _, _) -> BOOL);
// Hiding Applications
decl.add_method(sel!(applicationWillHide:), will_hide::<T> as extern fn(&Object, _, _));

View file

@ -98,6 +98,10 @@ pub trait AppDelegate {
/// back.
fn should_terminate(&self) -> TerminateResponse { TerminateResponse::Now }
/// Called after closing the last open window. Return `true` here if you want
/// the application to terminate.
fn should_terminate_after_last_window_closed(&self) -> bool { false }
/// Sent by the application to the delegate prior to default behavior to reopen AppleEvents.
///
/// `has_visible_windows` indicates whether the Application object found any visible windows in your application.