From 2141cb9184c20be91e469b2bd4e4bb22e57faba3 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Sat, 29 Mar 2008 22:13:50 +0000 Subject: Allow question dialogs to use custom button label text (Fixes bug 2008-03-30 Lucas Rocha Allow question dialogs to use custom button label text (Fixes bug #335763). Patch from Cosimo Cecchi and Thomas Thurman . * src/msg.c (zenity_msg_construct_question_dialog), (zenity_msg): dynamically add dialog buttons with provided labels. * src/option.c (zenity_option_free): free input labels. (zenity_question_post_callback): set button labels provided by the respective command line options. * src/zenity.glade: remove pre-defined dialog button from question dialog. * src/zenity.h: added ok_label and cancel_label to ZenityMsgData. svn path=/trunk/; revision=1346 --- ChangeLog | 15 +++++++++++++++ src/msg.c | 24 ++++++++++++++++++++++++ src/option.c | 29 ++++++++++++++++++++++++++++- src/zenity.glade | 33 +++++---------------------------- src/zenity.h | 2 ++ 5 files changed, 74 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29745394..bc648daf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-03-30 Lucas Rocha + + Allow question dialogs to use custom button label text (Fixes + bug #335763). Patch from Cosimo Cecchi and + Thomas Thurman . + + * src/msg.c (zenity_msg_construct_question_dialog), (zenity_msg): + dynamically add dialog buttons with provided labels. + * src/option.c (zenity_option_free): free input labels. + (zenity_question_post_callback): set button labels provided by the + respective command line options. + * src/zenity.glade: remove pre-defined dialog button from question + dialog. + * src/zenity.h: added ok_label and cancel_label to ZenityMsgData. + 2008-03-17 Lucas Rocha * src/option.c: added arg_description for --timeout option (Fixes diff --git a/src/msg.c b/src/msg.c index cbe6e3af..90e51642 100644 --- a/src/msg.c +++ b/src/msg.c @@ -29,6 +29,29 @@ static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data); +static void +zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data) +{ + GtkWidget *cancel_button, *ok_button; + + cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); + + gtk_widget_grab_focus (ok_button); + + if (msg_data->cancel_label) { + gtk_button_set_label (GTK_BUTTON (cancel_button), g_strdup (msg_data->cancel_label)); + gtk_button_set_image (GTK_BUTTON (cancel_button), + gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON)); + } + + if (msg_data->ok_label) { + gtk_button_set_label (GTK_BUTTON (ok_button), g_strdup (msg_data->ok_label)); + gtk_button_set_image (GTK_BUTTON (ok_button), + gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON)); + } +} + void zenity_msg (ZenityData *data, ZenityMsgData *msg_data) { @@ -92,6 +115,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) case ZENITY_MSG_QUESTION: zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_QUESTION); + zenity_msg_construct_question_dialog (dialog, msg_data); break; case ZENITY_MSG_ERROR: diff --git a/src/option.c b/src/option.c index babe4e9c..b56d5f09 100644 --- a/src/option.c +++ b/src/option.c @@ -87,6 +87,8 @@ static gboolean zenity_progress_auto_kill; /* Question Dialog Options */ static gboolean zenity_question_active; +static gchar *zenity_question_ok_button; +static gchar *zenity_question_cancel_button; /* Text Dialog Options */ static gboolean zenity_text_active; @@ -608,6 +610,24 @@ static GOptionEntry question_options[] = { N_("Set the dialog text"), N_("TEXT") }, + { + "ok-label", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_question_ok_button, + N_("Sets the label of the Ok button"), + N_("TEXT") + }, + { + "cancel-label", + '\0', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_question_cancel_button, + N_("Sets the label of the Cancel button"), + N_("TEXT") + }, { "no-wrap", '\0', @@ -837,6 +857,11 @@ zenity_option_free (void) { if (zenity_list_hide_column) g_free (zenity_list_hide_column); + if (zenity_question_ok_button) + g_free (zenity_question_ok_button); + if (zenity_question_cancel_button) + g_free (zenity_question_cancel_button); + g_option_context_free (ctx); } @@ -1342,7 +1367,9 @@ zenity_question_post_callback (GOptionContext *context, if (results->mode == MODE_QUESTION) { results->msg_data->dialog_text = zenity_general_dialog_text; results->msg_data->mode = ZENITY_MSG_QUESTION; - results->msg_data->no_wrap = zenity_general_dialog_no_wrap; + results->msg_data->no_wrap = zenity_general_dialog_no_wrap; + results->msg_data->ok_label = zenity_question_ok_button; + results->msg_data->cancel_label = zenity_question_cancel_button; } return TRUE; diff --git a/src/zenity.glade b/src/zenity.glade index c496dcc7..ffda0e8b 100644 --- a/src/zenity.glade +++ b/src/zenity.glade @@ -242,6 +242,7 @@ True + True Are you sure you want to proceed? False True @@ -339,36 +340,9 @@ 14 - + True GTK_BUTTONBOX_END - - - - True - True - True - gtk-cancel - True - GTK_RELIEF_NORMAL - True - -6 - - - - - - True - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - True - -5 - - 0 @@ -405,6 +379,7 @@ True + True Are you sure you want to proceed? False True @@ -872,6 +847,7 @@ True + True An error has occurred. False True @@ -1126,6 +1102,7 @@ True + True All updates are complete. False True diff --git a/src/zenity.h b/src/zenity.h index ac6c4f8e..8865cd9b 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -60,6 +60,8 @@ typedef struct { gchar *dialog_text; MsgMode mode; gboolean no_wrap; + gchar *ok_label; + gchar *cancel_label; } ZenityMsgData; typedef struct { -- cgit