Merge pull request #3 from jussiniinikoski/trunk

implement applicationShouldTerminateAfterLastWindowClosed
This commit is contained in:
Ryan McGrath 2021-03-01 09:51:55 -08:00 committed by GitHub
commit 400e763160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

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

View file

@ -226,6 +226,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. /// Fired when the application receives an `applicationOpenUntitledFile:` message.
extern fn open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL { extern fn open_untitled_file<T: AppDelegate>(this: &Object, _: Sel, _: id) -> BOOL {
match app::<T>(this).open_untitled_file() { match app::<T>(this).open_untitled_file() {
@ -308,6 +316,7 @@ pub(crate) fn register_app_delegate_class<T: AppDelegate + AppDelegate>() -> *co
// Terminating Applications // Terminating Applications
decl.add_method(sel!(applicationShouldTerminate:), should_terminate::<T> as extern fn(&Object, _, _) -> NSUInteger); 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!(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 // Hiding Applications
decl.add_method(sel!(applicationWillHide:), will_hide::<T> as extern fn(&Object, _, _)); decl.add_method(sel!(applicationWillHide:), will_hide::<T> as extern fn(&Object, _, _));

View file

@ -98,6 +98,10 @@ pub trait AppDelegate {
/// back. /// back.
fn should_terminate(&self) -> TerminateResponse { TerminateResponse::Now } 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. /// 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. /// `has_visible_windows` indicates whether the Application object found any visible windows in your application.