Allow question dialogs to use custom button label text (Fixes bug

2008-03-30  Lucas Rocha  <lucasr@gnome.org>

	Allow question dialogs to use custom button label text (Fixes 
	bug #335763). Patch from Cosimo Cecchi <anarki@lilik.it> and 
	Thomas Thurman <tthurman@gnome.org>.

	* 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
This commit is contained in:
Lucas Rocha 2008-03-29 22:13:50 +00:00 committed by Lucas Almeida Rocha
parent 23eb83f5bc
commit 2141cb9184
5 changed files with 74 additions and 29 deletions

View File

@ -1,3 +1,18 @@
2008-03-30 Lucas Rocha <lucasr@gnome.org>
Allow question dialogs to use custom button label text (Fixes
bug #335763). Patch from Cosimo Cecchi <anarki@lilik.it> and
Thomas Thurman <tthurman@gnome.org>.
* 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 <lucasr@gnome.org> 2008-03-17 Lucas Rocha <lucasr@gnome.org>
* src/option.c: added arg_description for --timeout option (Fixes * src/option.c: added arg_description for --timeout option (Fixes

View File

@ -29,6 +29,29 @@
static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data); 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 void
zenity_msg (ZenityData *data, ZenityMsgData *msg_data) zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
{ {
@ -92,6 +115,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
case ZENITY_MSG_QUESTION: case ZENITY_MSG_QUESTION:
zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_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; break;
case ZENITY_MSG_ERROR: case ZENITY_MSG_ERROR:

View File

@ -87,6 +87,8 @@ static gboolean zenity_progress_auto_kill;
/* Question Dialog Options */ /* Question Dialog Options */
static gboolean zenity_question_active; static gboolean zenity_question_active;
static gchar *zenity_question_ok_button;
static gchar *zenity_question_cancel_button;
/* Text Dialog Options */ /* Text Dialog Options */
static gboolean zenity_text_active; static gboolean zenity_text_active;
@ -608,6 +610,24 @@ static GOptionEntry question_options[] = {
N_("Set the dialog text"), N_("Set the dialog text"),
N_("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", "no-wrap",
'\0', '\0',
@ -837,6 +857,11 @@ zenity_option_free (void) {
if (zenity_list_hide_column) if (zenity_list_hide_column)
g_free (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); g_option_context_free (ctx);
} }
@ -1342,7 +1367,9 @@ zenity_question_post_callback (GOptionContext *context,
if (results->mode == MODE_QUESTION) { if (results->mode == MODE_QUESTION) {
results->msg_data->dialog_text = zenity_general_dialog_text; results->msg_data->dialog_text = zenity_general_dialog_text;
results->msg_data->mode = ZENITY_MSG_QUESTION; 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; return TRUE;

View File

@ -242,6 +242,7 @@
<child> <child>
<widget class="GtkLabel" id="zenity_warning_text"> <widget class="GtkLabel" id="zenity_warning_text">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Are you sure you want to proceed?</property> <property name="label" translatable="yes">Are you sure you want to proceed?</property>
<property name="use_underline">False</property> <property name="use_underline">False</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
@ -339,36 +340,9 @@
<property name="spacing">14</property> <property name="spacing">14</property>
<child internal-child="action_area"> <child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area3"> <widget class="GtkHButtonBox" id="zenity_question_button_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property> <property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="zenity_question_cancel_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="zenity_question_ok_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
@ -405,6 +379,7 @@
<child> <child>
<widget class="GtkLabel" id="zenity_question_text"> <widget class="GtkLabel" id="zenity_question_text">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Are you sure you want to proceed?</property> <property name="label" translatable="yes">Are you sure you want to proceed?</property>
<property name="use_underline">False</property> <property name="use_underline">False</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
@ -872,6 +847,7 @@
<child> <child>
<widget class="GtkLabel" id="zenity_error_text"> <widget class="GtkLabel" id="zenity_error_text">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">An error has occurred.</property> <property name="label" translatable="yes">An error has occurred.</property>
<property name="use_underline">False</property> <property name="use_underline">False</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
@ -1126,6 +1102,7 @@
<child> <child>
<widget class="GtkLabel" id="zenity_info_text"> <widget class="GtkLabel" id="zenity_info_text">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">All updates are complete.</property> <property name="label" translatable="yes">All updates are complete.</property>
<property name="use_underline">False</property> <property name="use_underline">False</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>

View File

@ -60,6 +60,8 @@ typedef struct {
gchar *dialog_text; gchar *dialog_text;
MsgMode mode; MsgMode mode;
gboolean no_wrap; gboolean no_wrap;
gchar *ok_label;
gchar *cancel_label;
} ZenityMsgData; } ZenityMsgData;
typedef struct { typedef struct {