From e011599ea525f52f73cfadce2ead4033bc806c9b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 20 Nov 2021 08:06:02 +0200 Subject: [PATCH 12/12] fcmp gtk: Allow opening new quit confirmation after destruction of previous See osdn #43073 Signed-off-by: Marko Lindqvist --- tools/mpgui_gtk2.c | 34 ++++++++++++++++++++++------------ tools/mpgui_gtk3.c | 34 ++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/tools/mpgui_gtk2.c b/tools/mpgui_gtk2.c index 3e03613613..0c8e7c4d88 100644 --- a/tools/mpgui_gtk2.c +++ b/tools/mpgui_gtk2.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 = { @@ -86,30 +87,37 @@ static void quit_dialog_response(GtkWidget *dialog, gint response) } /**************************************************************** - Popups the quit dialog if + 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 ****************************************************************/ 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 @@ -581,6 +589,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/mpgui_gtk3.c b/tools/mpgui_gtk3.c index a4c0e88b54..ac96d7ec50 100644 --- a/tools/mpgui_gtk3.c +++ b/tools/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 = { @@ -86,30 +87,37 @@ static void quit_dialog_response(GtkWidget *dialog, gint response) } /**************************************************************** - Popups the quit dialog if + 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 ****************************************************************/ 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); -- 2.33.0