Fix for bug #611297 Now Zenity have --ok-label and --cancel-label in all dialogs. This patch doesn't break old zenity scripts.

This commit is contained in:
Arx Cruz 2011-07-26 14:00:28 -03:00
parent 7a34df3041
commit 6768a40e99
13 changed files with 183 additions and 76 deletions

View File

@ -39,6 +39,7 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
{
GtkBuilder *builder;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
zen_cal_data = cal_data;
@ -84,10 +85,24 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar);
zenity_util_show_dialog (dialog);
if(data->timeout_delay > 0) {
if (data->timeout_delay > 0) {
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
}
if (data->ok_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (data->cancel_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar_cancel_button"));
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
g_object_unref (builder);
gtk_main ();

View File

@ -35,6 +35,7 @@ void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
{
GtkWidget *dialog;
GtkWidget *colorsel;
GtkWidget *button;
GdkColor color;
zen_data = data;
@ -56,6 +57,22 @@ void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
&color);
}
if (data->ok_label) {
g_object_get (G_OBJECT (dialog), "ok-button", &button);
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
g_object_unref (G_OBJECT (button));
}
if (data->cancel_label) {
g_object_get (G_OBJECT (dialog), "cancel-button", &button);
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
g_object_unref (G_OBJECT (button));
}
gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (colorsel),
color_data->show_palette);

View File

@ -53,6 +53,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
{
GtkBuilder *builder = NULL;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
GSList *entries = NULL;
GSList *tmp;
@ -79,6 +80,20 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
if (data->width > -1 || data->height > -1)
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
if (data->ok_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_entry_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (data->cancel_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_entry_cancel_button"));
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
text = gtk_builder_get_object (builder, "zenity_entry_text");

View File

@ -36,6 +36,7 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
GtkWidget *dialog;
GtkWidget *table;
GtkWidget *text;
GtkWidget *button;
GSList *tmp;
@ -62,7 +63,21 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
if (data->width > -1 || data->height > -1)
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
if (data->ok_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (data->cancel_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_cancel_button"));
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
text = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_text"));
if (forms_data->dialog_text)

View File

@ -29,7 +29,7 @@
static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data);
static void
zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data)
zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data, ZenityData *data)
{
GtkWidget *cancel_button, *ok_button;
@ -38,14 +38,14 @@ zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data
gtk_widget_grab_focus (ok_button);
if (msg_data->cancel_label) {
gtk_button_set_label (GTK_BUTTON (cancel_button), msg_data->cancel_label);
if (data->cancel_label) {
gtk_button_set_label (GTK_BUTTON (cancel_button), 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), msg_data->ok_label);
if (data->ok_label) {
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (ok_button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
@ -56,6 +56,7 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
{
GtkBuilder *builder;
GtkWidget *dialog;
GtkWidget *ok_button;
GObject *text;
switch (msg_data->mode) {
@ -63,30 +64,35 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_dialog"));
text = gtk_builder_get_object (builder, "zenity_warning_text");
ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_ok_button"));
break;
case ZENITY_MSG_QUESTION:
builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_question_dialog"));
text = gtk_builder_get_object (builder, "zenity_question_text");
ok_button = NULL;
break;
case ZENITY_MSG_ERROR:
builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_dialog"));
text = gtk_builder_get_object (builder, "zenity_error_text");
ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_ok_button"));
break;
case ZENITY_MSG_INFO:
builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL);
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_dialog"));
text = gtk_builder_get_object (builder, "zenity_info_text");
ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_ok_button"));
break;
default:
builder = NULL;
dialog = NULL;
text = NULL;
ok_button = NULL;
g_assert_not_reached ();
break;
}
@ -104,6 +110,14 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
if (ok_button) {
if (data->ok_label) {
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (ok_button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
}
switch (msg_data->mode) {
case ZENITY_MSG_WARNING:
zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_WARNING);
@ -111,7 +125,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);
zenity_msg_construct_question_dialog (dialog, msg_data, data);
break;
case ZENITY_MSG_ERROR:

View File

@ -187,6 +187,24 @@ static GOptionEntry general_options[] = {
/* Timeout for closing the dialog */
N_("TIMEOUT")
},
{
"ok-label",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_ok_button,
N_("Sets the label of the Ok button"),
N_("TEXT")
},
{
"cancel-label",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_cancel_button,
N_("Sets the label of the Cancel button"),
N_("TEXT")
},
{
NULL
}
@ -689,24 +707,6 @@ static GOptionEntry question_options[] = {
N_("Set the dialog text"),
N_("TEXT")
},
{
"ok-label",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_ok_button,
N_("Sets the label of the Ok button"),
N_("TEXT")
},
{
"cancel-label",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_cancel_button,
N_("Sets the label of the Cancel button"),
N_("TEXT")
},
{
"no-wrap",
'\0',
@ -766,24 +766,6 @@ static GOptionEntry text_options[] = {
N_("Set the text font"),
N_("TEXT")
},
{
"ok-label",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_ok_button,
N_("Sets the label of the Ok button"),
N_("TEXT")
},
{
"cancel-label",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_cancel_button,
N_("Sets the label of the Cancel button"),
N_("TEXT")
},
{
"checkbox",
'\0',
@ -1467,7 +1449,9 @@ zenity_general_post_callback (GOptionContext *context,
results->data->window_icon = zenity_general_window_icon;
results->data->width = zenity_general_width;
results->data->height = zenity_general_height;
results->data->timeout_delay=zenity_general_timeout_delay;
results->data->timeout_delay = zenity_general_timeout_delay;
results->data->ok_label = zenity_general_ok_button;
results->data->cancel_label = zenity_general_cancel_button;
return TRUE;
}
@ -1497,6 +1481,7 @@ zenity_calendar_post_callback (GOptionContext *context,
results->calendar_data->day = zenity_calendar_day;
results->calendar_data->month = zenity_calendar_month;
results->calendar_data->year = zenity_calendar_year;
if (zenity_calendar_date_format)
results->calendar_data->date_format = zenity_calendar_date_format;
else
@ -1748,8 +1733,6 @@ zenity_question_post_callback (GOptionContext *context,
results->msg_data->mode = ZENITY_MSG_QUESTION;
results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
results->msg_data->no_markup = zenity_general_dialog_no_markup;
results->msg_data->ok_label = zenity_general_ok_button;
results->msg_data->cancel_label = zenity_general_cancel_button;
}
return TRUE;
@ -1768,8 +1751,6 @@ zenity_text_post_callback (GOptionContext *context,
results->text_data->editable = zenity_general_editable;
results->text_data->no_wrap = zenity_general_dialog_no_wrap;
results->text_data->font = zenity_text_font;
results->text_data->ok_label = zenity_general_ok_button;
results->text_data->cancel_label = zenity_general_cancel_button;
results->text_data->checkbox = zenity_text_checkbox;
#ifdef HAVE_WEBKITGTK
results->text_data->html = zenity_text_enable_html;
@ -2163,15 +2144,16 @@ zenity_option_parse (gint argc, gchar **argv)
if (zenity_general_uri)
if (results->mode != MODE_FILE && results->mode != MODE_TEXTINFO)
zenity_option_error (zenity_option_get_name (text_options, &zenity_general_uri), ERROR_SUPPORT);
if (zenity_general_ok_button)
if(results->mode != MODE_QUESTION && results->mode != MODE_TEXTINFO)
zenity_option_error (zenity_option_get_name (text_options, &zenity_general_ok_button), ERROR_SUPPORT);
if(results->mode == MODE_FILE)
zenity_option_error (zenity_option_get_name (general_options, &zenity_general_ok_button), ERROR_SUPPORT);
if (zenity_general_cancel_button)
if(results->mode != MODE_QUESTION && results->mode != MODE_TEXTINFO)
zenity_option_error (zenity_option_get_name (text_options, &zenity_general_cancel_button), ERROR_SUPPORT);
if(results->mode == MODE_FILE || results->mode == MODE_ERROR || results->mode == MODE_WARNING || results->mode == MODE_INFO)
zenity_option_error (zenity_option_get_name (general_options, &zenity_general_cancel_button), ERROR_SUPPORT);
if (zenity_general_dialog_no_wrap)
if (results->mode != MODE_INFO && results->mode != MODE_ERROR && results->mode != MODE_QUESTION && results->mode != MODE_WARNING && results->mode != MODE_TEXTINFO)
zenity_option_error (zenity_option_get_name (text_options, &zenity_general_dialog_no_wrap), ERROR_SUPPORT);

View File

@ -45,10 +45,10 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data
dialog = gtk_dialog_new ();
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL,
data->cancel_label != NULL ? data->cancel_label : GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_OK,
data->ok_label != NULL ? data->ok_label : GTK_STOCK_OK,
GTK_RESPONSE_OK);
image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION,

View File

@ -227,6 +227,7 @@ void
zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
{
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
GObject *progress_bar;
GObject *cancel_button,*ok_button;
@ -255,6 +256,20 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
if (data->width > -1 || data->height > -1)
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
if (data->ok_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (data->cancel_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_cancel_button"));
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
text = gtk_builder_get_object (builder, "zenity_progress_text");
if (progress_data->dialog_text)

View File

@ -36,6 +36,7 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
{
GtkBuilder *builder;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
builder = zenity_util_load_ui_file ("zenity_scale_dialog", "adjustment1", NULL);
@ -75,6 +76,20 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
if (data->width > -1 || data->height > -1)
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
if (data->ok_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (data->cancel_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_cancel_button"));
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
if (scale_data->dialog_text)
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (scale_data->dialog_text));

View File

@ -262,16 +262,22 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
if (text_data->editable)
zen_text_data->buffer = text_buffer;
if (text_data->ok_label)
gtk_button_set_label (GTK_BUTTON(ok_button), text_data->ok_label);
if (data->ok_label) {
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (ok_button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (text_data->cancel_label)
gtk_button_set_label (GTK_BUTTON(cancel_button), text_data->cancel_label);
if (data->cancel_label) {
gtk_button_set_label (GTK_BUTTON (cancel_button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (cancel_button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
if (text_data->checkbox) {
gtk_widget_set_visible (GTK_WIDGET(checkbox), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET(ok_button), FALSE);
gtk_button_set_label (GTK_BUTTON(checkbox), text_data->checkbox);
gtk_widget_set_visible (GTK_WIDGET (checkbox), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE);
gtk_button_set_label (GTK_BUTTON (checkbox), text_data->checkbox);
g_signal_connect (G_OBJECT (checkbox), "toggled",
G_CALLBACK (zenity_text_toggle_button), ok_button);

View File

@ -287,6 +287,7 @@ void
zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
{
GtkWidget *dialog;
GtkWidget *button;
GObject *tree_view;
GObject *text;
GtkTreeViewColumn *column;
@ -344,6 +345,20 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
if (data->ok_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button"));
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
}
if (data->cancel_label) {
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_cancel_button"));
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
}
text = gtk_builder_get_object (builder, "zenity_tree_text");
if (tree_data->dialog_text)

View File

@ -26,6 +26,8 @@ G_BEGIN_DECLS
typedef struct {
gchar *dialog_title;
gchar *window_icon;
gchar *ok_label;
gchar *cancel_label;
gint width;
gint height;
gint exit_code;
@ -61,8 +63,6 @@ typedef struct {
MsgMode mode;
gboolean no_wrap;
gboolean no_markup;
gchar *ok_label;
gchar *cancel_label;
} ZenityMsgData;
typedef struct {
@ -108,8 +108,6 @@ typedef struct {
gboolean no_wrap;
gchar *font;
GtkTextBuffer *buffer;
gchar *ok_label;
gchar *cancel_label;
gchar *checkbox;
#ifdef HAVE_WEBKITGTK
gboolean html;

View File

@ -365,7 +365,7 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancelbutton12">
<object class="GtkButton" id="zenity_forms_cancel_button">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@ -380,7 +380,7 @@
</packing>
</child>
<child>
<object class="GtkButton" id="okbutton12">
<object class="GtkButton" id="zenity_forms_ok_button">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@ -449,8 +449,8 @@
</object>
</child>
<action-widgets>
<action-widget response="-6">cancelbutton12</action-widget>
<action-widget response="-5">okbutton12</action-widget>
<action-widget response="-6">zenity_forms_cancel_button</action-widget>
<action-widget response="-5">zenity_forms_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="zenity_info_dialog">
@ -739,7 +739,7 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancelbutton1">
<object class="GtkButton" id="zenity_scale_cancel_button">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@ -755,7 +755,7 @@
</packing>
</child>
<child>
<object class="GtkButton" id="okbutton1">
<object class="GtkButton" id="zenity_scale_ok_button">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@ -823,8 +823,8 @@
</object>
</child>
<action-widgets>
<action-widget response="-6">cancelbutton1</action-widget>
<action-widget response="-5">okbutton1</action-widget>
<action-widget response="-6">zenity_scale_cancel_button</action-widget>
<action-widget response="-5">zenity_scale_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="zenity_text_dialog">