From 5af62949c6110b17f9fd03675e89e31a49df6d2e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 3 Dec 2022 09:13:27 +0200 Subject: [PATCH 41/41] gtk4: Add action confirmation dialog See osdn #46164 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/dialogs.c | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/client/gui-gtk-4.0/dialogs.c b/client/gui-gtk-4.0/dialogs.c index e9206e392e..bb15b0f466 100644 --- a/client/gui-gtk-4.0/dialogs.c +++ b/client/gui-gtk-4.0/dialogs.c @@ -1598,12 +1598,47 @@ void popup_combat_info(int attacker_unit_id, int defender_unit_id, { } +/**********************************************************************//** + This is the response callback for the action confirmation dialog. +**************************************************************************/ +static void act_conf_response(GtkWidget *dialog, gint response, + gpointer data) +{ + gtk_window_destroy(GTK_WINDOW(dialog)); + + if (response == GTK_RESPONSE_YES) { + action_confirmation(data, TRUE); + } else { + action_confirmation(data, FALSE); + } +} + /**********************************************************************//** Common code wants confirmation for an action. **************************************************************************/ void request_action_confirmation(const char *expl, struct act_confirmation_data *data) { - /* TODO: Implement. Currently just pass everything as confirmed */ - action_confirmation(data, TRUE); + GtkWidget *dialog; + char buf[1024]; + + if (expl != NULL) { + fc_snprintf(buf, sizeof(buf), _("Are you sure you want to do %s?\n%s"), + action_id_name_translation(data->act), expl); + } else { + fc_snprintf(buf, sizeof(buf), _("Are you sure you want to do %s?"), + action_id_name_translation(data->act)); + } + + dialog = gtk_message_dialog_new(NULL, + 0, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_YES_NO, + "%s", buf); + setup_dialog(dialog, toplevel); + + g_signal_connect(dialog, "response", + G_CALLBACK(act_conf_response), data); + + gtk_window_present(GTK_WINDOW(dialog)); } -- 2.35.1