diff --git a/src/option.c b/src/option.c index cd81209..954ba64 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); diff --git a/src/text.c b/src/text.c index 9868675..fabc860 100644 --- a/src/text.c +++ b/src/text.c @@ -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 @@ -166,6 +190,13 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) gtk_main (); } +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) { @@ -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 e5c6f4c..fd744b6 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 3187d0b..07aa51a 100644 --- a/src/zenity.ui +++ b/src/zenity.ui @@ -847,11 +847,10 @@ False end - - gtk-close + + gtk-cancel True True - True False False True @@ -862,6 +861,23 @@ 0 + + + gtk-ok + True + True + True + True + False + True + right + + + False + False + 1 + + False @@ -900,6 +916,20 @@ 0 + + + True + False + False + 0 + True + + + False + False + 1 + + True @@ -910,6 +940,7 @@ + zenity_text_cancel_button zenity_text_close_button