From 5872558feef3727e3ff1bb2bf395dfc6bd896f74 Mon Sep 17 00:00:00 2001 From: Arx Cruz Date: Tue, 28 Jun 2011 17:09:04 -0300 Subject: 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. --- src/text.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/text.c') diff --git a/src/text.c b/src/text.c index 98686750..fabc860a 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); -- cgit