apprt/gtk: integrate app needsConfirmQuit

This commit is contained in:
Mitchell Hashimoto
2023-09-11 15:47:37 -07:00
parent 999d17c49d
commit 868b66ce74

View File

@ -228,6 +228,12 @@ pub const App = struct {
} }
c.g_list_free(list); c.g_list_free(list);
// If the app says we don't need to confirm, then we can quit now.
if (!self.core_app.needsConfirmQuit()) {
self.quitNow();
return;
}
// If we have windows, then we want to confirm that we want to exit. // If we have windows, then we want to confirm that we want to exit.
const alert = c.gtk_message_dialog_new( const alert = c.gtk_message_dialog_new(
null, null,
@ -259,20 +265,8 @@ pub const App = struct {
c.gtk_widget_show(alert); c.gtk_widget_show(alert);
} }
fn gtkQuitConfirmation( fn quitNow(self: *App) void {
alert: *c.GtkMessageDialog, _ = self;
response: c.gint,
ud: ?*anyopaque,
) callconv(.C) void {
_ = ud;
// Close the alert window
c.gtk_window_destroy(@ptrCast(alert));
// If we didn't confirm then we're done
if (response != c.GTK_RESPONSE_YES) return;
// Force close all open windows
const list = c.gtk_window_list_toplevels(); const list = c.gtk_window_list_toplevels();
defer c.g_list_free(list); defer c.g_list_free(list);
c.g_list_foreach(list, struct { c.g_list_foreach(list, struct {
@ -285,6 +279,23 @@ pub const App = struct {
}.callback, null); }.callback, null);
} }
fn gtkQuitConfirmation(
alert: *c.GtkMessageDialog,
response: c.gint,
ud: ?*anyopaque,
) callconv(.C) void {
const self: *App = @ptrCast(@alignCast(ud orelse return));
// Close the alert window
c.gtk_window_destroy(@ptrCast(alert));
// If we didn't confirm then we're done
if (response != c.GTK_RESPONSE_YES) return;
// Force close all open windows
self.quitNow();
}
/// This is called by the "activate" signal. This is sent on program /// This is called by the "activate" signal. This is sent on program
/// startup and also when a secondary instance launches and requests /// startup and also when a secondary instance launches and requests
/// a new window. /// a new window.