diff options
author | Arx Cruz <arxcruz@src.gnome.org> | 2011-06-28 17:09:04 -0300 |
---|---|---|
committer | Arx Cruz <arxcruz@src.gnome.org> | 2011-06-28 17:18:32 -0300 |
commit | 5872558feef3727e3ff1bb2bf395dfc6bd896f74 (patch) | |
tree | fa788e9bed3d1368b905c1d09b787c27739bf2ec /src | |
parent | Updated Russian translation (diff) | |
download | zenity-5872558feef3727e3ff1bb2bf395dfc6bd896f74.tar.gz zenity-5872558feef3727e3ff1bb2bf395dfc6bd896f74.tar.bz2 zenity-5872558feef3727e3ff1bb2bf395dfc6bd896f74.zip |
This change add a new functionality to text-info:
* Added a cancel button returning 1 if clicked
* Renamed the Close button to Ok, still returning 0 if clicked
* Added --ok-label=TEXT option to change the Ok button label
* Added --cancel-label=TEXT option to change the Cancel button label
* Added --checkbox=TEXT option to show an "I Agree and accept the terms" checkbox
If --checkbox is enabled, the Ok button will be disabled if the checkbox isn't checked.
Diffstat (limited to 'src')
-rw-r--r-- | src/option.c | 72 | ||||
-rw-r--r-- | src/text.c | 34 | ||||
-rw-r--r-- | src/zenity.h | 3 | ||||
-rw-r--r-- | src/zenity.ui | 37 |
4 files changed, 124 insertions, 22 deletions
diff --git a/src/option.c b/src/option.c index cd812091..954ba648 100644 --- a/src/option.c +++ b/src/option.c @@ -41,6 +41,8 @@ static gboolean zenity_general_editable; static gchar *zenity_general_uri; static gboolean zenity_general_dialog_no_wrap; static gint zenity_general_timeout_delay; +static gchar *zenity_general_ok_button; +static gchar *zenity_general_cancel_button; /* Calendar Dialog Options */ static gboolean zenity_calendar_active; @@ -92,12 +94,11 @@ static gboolean zenity_progress_no_cancel; /* 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; static gchar *zenity_text_font; +static gchar *zenity_text_checkbox; /* Warning Dialog Options */ static gboolean zenity_warning_active; @@ -672,7 +673,7 @@ static GOptionEntry question_options[] = { '\0', G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, - &zenity_question_ok_button, + &zenity_general_ok_button, N_("Sets the label of the Ok button"), N_("TEXT") }, @@ -681,7 +682,7 @@ static GOptionEntry question_options[] = { '\0', G_OPTION_FLAG_NOALIAS, G_OPTION_ARG_STRING, - &zenity_question_cancel_button, + &zenity_general_cancel_button, N_("Sets the label of the Cancel button"), N_("TEXT") }, @@ -736,6 +737,33 @@ 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', + G_OPTION_FLAG_NOALIAS, + G_OPTION_ARG_STRING, + &zenity_text_checkbox, + N_("Enable a I read and agree checkbox"), + N_("TEXT") + }, { NULL } @@ -1040,6 +1068,10 @@ zenity_option_free (void) { if (zenity_general_uri) g_free (zenity_general_uri); g_free (zenity_general_separator); + if (zenity_general_ok_button) + g_free (zenity_general_ok_button); + if (zenity_general_cancel_button) + g_free (zenity_general_cancel_button); if (zenity_calendar_date_format) g_free (zenity_calendar_date_format); @@ -1060,13 +1092,10 @@ 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); - if (zenity_text_font) g_free (zenity_text_font); + if (zenity_text_checkbox) + g_free (zenity_text_checkbox); if (zenity_colorsel_color) g_free (zenity_colorsel_color); @@ -1145,6 +1174,8 @@ zenity_general_pre_callback (GOptionContext *context, zenity_general_multiple = FALSE; zenity_general_editable = FALSE; zenity_general_uri = NULL; + zenity_general_ok_button = NULL; + zenity_general_cancel_button = NULL; zenity_general_dialog_no_wrap = FALSE; zenity_general_timeout_delay = -1; @@ -1281,7 +1312,7 @@ zenity_text_pre_callback (GOptionContext *context, { zenity_text_active = FALSE; zenity_text_font = NULL; - + zenity_text_checkbox = NULL; return TRUE; } @@ -1610,7 +1641,6 @@ zenity_progress_post_callback (GOptionContext *context, GError **error) { zenity_option_set_dialog_mode (zenity_progress_active, MODE_PROGRESS); - if (results->mode == MODE_PROGRESS) { results->progress_data->dialog_text = zenity_general_dialog_text; results->progress_data->pulsate = zenity_progress_pulsate; @@ -1649,14 +1679,12 @@ zenity_question_post_callback (GOptionContext *context, GError **error) { zenity_option_set_dialog_mode (zenity_question_active, MODE_QUESTION); - - 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->ok_label = zenity_question_ok_button; - results->msg_data->cancel_label = zenity_question_cancel_button; + results->msg_data->ok_label = zenity_general_ok_button; + results->msg_data->cancel_label = zenity_general_cancel_button; } return TRUE; @@ -1675,12 +1703,14 @@ 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; } else { - if (zenity_text_font) + if (zenity_text_font) zenity_option_error (zenity_option_get_name (text_options, &zenity_text_font), ERROR_SUPPORT); } - return TRUE; } @@ -2063,7 +2093,15 @@ 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 (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 (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); @@ -29,6 +29,7 @@ static ZenityTextData *zen_text_data; static void zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data); +static void zenity_text_toggle_button (GtkToggleButton *button, gpointer data); static gboolean zenity_text_handle_stdin (GIOChannel *channel, @@ -103,6 +104,10 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) { GtkBuilder *builder; GtkWidget *dialog; + GtkWidget *ok_button; + GtkWidget *checkbox; + GtkWidget *cancel_button; + GObject *text_view; GtkTextBuffer *text_buffer; @@ -118,7 +123,11 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) gtk_builder_connect_signals (builder, NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_dialog")); - + + ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_close_button")); + cancel_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_cancel_button")); + checkbox = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_checkbox")); + g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (zenity_text_dialog_response), data); @@ -150,6 +159,21 @@ 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 (text_data->cancel_label) + gtk_button_set_label (GTK_BUTTON(cancel_button), text_data->cancel_label); + + 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); + + g_signal_connect (G_OBJECT (checkbox), "toggled", + G_CALLBACK (zenity_text_toggle_button), ok_button); + } + if (data->width > -1 || data->height > -1) gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height); else @@ -167,6 +191,13 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) } static void +zenity_text_toggle_button (GtkToggleButton *button, gpointer data) +{ + GtkWidget *ok_button = (GtkWidget *)data; + gtk_widget_set_sensitive (GTK_WIDGET(ok_button), gtk_toggle_button_get_active(button)); +} + +static void zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) { ZenityData *zen_data = data; @@ -176,7 +207,6 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) if (zen_text_data->editable) { GtkTextIter start, end; gchar *text; - gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end); text = gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0); g_print ("%s", text); diff --git a/src/zenity.h b/src/zenity.h index e5c6f4cd..fd744b67 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -107,6 +107,9 @@ typedef struct { gboolean no_wrap; gchar *font; GtkTextBuffer *buffer; + gchar *ok_label; + gchar *cancel_label; + gchar *checkbox; } ZenityTextData; typedef struct { diff --git a/src/zenity.ui b/src/zenity.ui index 3187d0ba..07aa51a2 100644 --- a/src/zenity.ui +++ b/src/zenity.ui @@ -847,11 +847,10 @@ <property name="can_focus">False</property> <property name="layout_style">end</property> <child> - <object class="GtkButton" id="zenity_text_close_button"> - <property name="label">gtk-close</property> + <object class="GtkButton" id="zenity_text_cancel_button"> + <property name="label">gtk-cancel</property> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="can_default">True</property> <property name="receives_default">False</property> <property name="use_action_appearance">False</property> <property name="use_stock">True</property> @@ -862,6 +861,23 @@ <property name="position">0</property> </packing> </child> + <child> + <object class="GtkButton" id="zenity_text_close_button"> + <property name="label">gtk-ok</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + <property name="image_position">right</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> @@ -900,6 +916,20 @@ <property name="position">0</property> </packing> </child> + <child> + <object class="GtkCheckButton" id="zenity_text_checkbox"> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_action_appearance">False</property> + <property name="xalign">0</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> @@ -910,6 +940,7 @@ </object> </child> <action-widgets> + <action-widget response="-6">zenity_text_cancel_button</action-widget> <action-widget response="-7">zenity_text_close_button</action-widget> </action-widgets> </object> |