From effb91f0df901d7254515cb011c2bc32878ebf52 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 20 Nov 2021 07:57:46 +0200 Subject: [PATCH 38/38] fcmp gtk: Allow opening new quit confirmation after destruction of previous See osdn #43073 Signed-off-by: Marko Lindqvist --- tools/fcmp/mpgui_gtk3.c | 32 +++++++++++++++++++++----------- tools/fcmp/mpgui_gtk4.c | 22 ++++++++++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tools/fcmp/mpgui_gtk3.c b/tools/fcmp/mpgui_gtk3.c index ee6eafdb7a..b4fea92298 100644 --- a/tools/fcmp/mpgui_gtk3.c +++ b/tools/fcmp/mpgui_gtk3.c @@ -41,6 +41,7 @@ static GtkWidget *progressbar; static GtkWidget *main_list; static GtkListStore *main_store; static GtkWidget *URL_input; +static GtkWidget *quit_dialog; static gboolean downloading = FALSE; struct fcmp_params fcmp = { @@ -85,6 +86,14 @@ static void quit_dialog_response(GtkWidget *dialog, gint response) } } +/**********************************************************************//** + Quit dialog has been destroyed +**************************************************************************/ +static void quit_dialog_destroyed(GtkWidget *dialog, void *data) +{ + quit_dialog = NULL; +} + /**********************************************************************//** Popups the quit dialog if download in progress **************************************************************************/ @@ -92,24 +101,23 @@ static gboolean quit_dialog_callback(void) { if (downloading) { /* Download in progress. Confirm quit from user. */ - static GtkWidget *dialog; - if (!dialog) { - dialog = gtk_message_dialog_new(NULL, - 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_YES_NO, + if (quit_dialog == NULL) { + quit_dialog = gtk_message_dialog_new(NULL, + 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_YES_NO, _("Modpack installation in progress.\nAre you sure you want to quit?")); - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE); + gtk_window_set_position(GTK_WINDOW(quit_dialog), GTK_WIN_POS_MOUSE); - g_signal_connect(dialog, "response", + g_signal_connect(quit_dialog, "response", G_CALLBACK(quit_dialog_response), NULL); - g_signal_connect(dialog, "destroy", - G_CALLBACK(gtk_widget_destroyed), &dialog); + g_signal_connect(quit_dialog, "destroy", + G_CALLBACK(quit_dialog_destroyed), NULL); } - gtk_window_present(GTK_WINDOW(dialog)); + gtk_window_present(GTK_WINDOW(quit_dialog)); } else { /* User loses no work by quitting, so let's not annoy him/her @@ -587,6 +595,8 @@ int main(int argc, char *argv[]) load_install_info_lists(&fcmp); + quit_dialog = NULL; + /* Process GTK arguments */ gtk_init(&ui_options, &argv); diff --git a/tools/fcmp/mpgui_gtk4.c b/tools/fcmp/mpgui_gtk4.c index de627a06fb..38d4747046 100644 --- a/tools/fcmp/mpgui_gtk4.c +++ b/tools/fcmp/mpgui_gtk4.c @@ -41,6 +41,7 @@ static GtkWidget *progressbar; static GtkWidget *main_list; static GtkListStore *main_store; static GtkWidget *URL_input; +static GtkWidget *quit_dialog; static gboolean downloading = FALSE; struct fcmp_params fcmp = { @@ -92,7 +93,7 @@ static void quit_dialog_response(GtkWidget *dialog, gint response) **************************************************************************/ static void quit_dialog_destroyed(GtkWidget *dialog, void *data) { - dialog = NULL; + quit_dialog = NULL; } /**********************************************************************//** @@ -102,22 +103,21 @@ static gboolean quit_dialog_callback(void) { if (downloading) { /* Download in progress. Confirm quit from user. */ - static GtkWidget *dialog; - if (!dialog) { - dialog = gtk_message_dialog_new(NULL, - 0, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_YES_NO, + if (quit_dialog == NULL) { + quit_dialog = gtk_message_dialog_new(NULL, + 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_YES_NO, _("Modpack installation in progress.\nAre you sure you want to quit?")); - g_signal_connect(dialog, "response", + g_signal_connect(quit_dialog, "response", G_CALLBACK(quit_dialog_response), NULL); - g_signal_connect(dialog, "destroy", + g_signal_connect(quit_dialog, "destroy", G_CALLBACK(quit_dialog_destroyed), NULL); } - gtk_window_present(GTK_WINDOW(dialog)); + gtk_window_present(GTK_WINDOW(quit_dialog)); } else { /* User loses no work by quitting, so let's not annoy him/her @@ -568,6 +568,8 @@ static void activate_gui(GtkApplication *app, gpointer data) { GtkWidget *toplevel; + quit_dialog = NULL; + toplevel = gtk_application_window_new(app); gtk_widget_realize(toplevel); -- 2.33.0