summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArx Cruz <arxcruz@gnome.org>2013-11-23 20:32:51 -0200
committerArx Cruz <arxcruz@gnome.org>2013-11-23 20:32:51 -0200
commit4681d74c02e49c2f3af1da5ce9457807dbcf3f9e (patch)
treef1f5bf94d3acc7329d6f07085690e4062f72a0f5 /src
parentBug #534935 Need hability to specify default answer in --question dialog (diff)
downloadzenity-4681d74c02e49c2f3af1da5ce9457807dbcf3f9e.tar.gz
zenity-4681d74c02e49c2f3af1da5ce9457807dbcf3f9e.tar.bz2
zenity-4681d74c02e49c2f3af1da5ce9457807dbcf3f9e.zip
Bug #600533 zenity --text-info should have an auto scroll option
This is a request to add a auto-scroll option. For now it's only works when text-info is getting the text from stdin. Example usage: cat file.txt | zenity --text-info --auto-scroll
Diffstat (limited to 'src')
-rw-r--r--src/option.c13
-rw-r--r--src/text.c19
-rw-r--r--src/zenity.h1
3 files changed, 28 insertions, 5 deletions
diff --git a/src/option.c b/src/option.c
index 46112d04..fb25f37c 100644
--- a/src/option.c
+++ b/src/option.c
@@ -106,6 +106,8 @@ static gboolean zenity_question_default_cancel;
static gboolean zenity_text_active;
static gchar *zenity_text_font;
static gchar *zenity_text_checkbox;
+static gboolean zenity_text_auto_scroll;
+
#ifdef HAVE_WEBKITGTK
static gboolean zenity_text_enable_html;
static gchar *zenity_text_url;
@@ -878,6 +880,15 @@ static GOptionEntry text_options[] = {
N_("URL")
},
#endif
+ {
+ "auto-scroll",
+ '\0',
+ G_OPTION_FLAG_NOALIAS,
+ G_OPTION_ARG_NONE,
+ &zenity_text_auto_scroll,
+ N_("Auto scroll the text to the end. Only when text is captured from stdin"),
+ NULL
+ },
{
NULL
}
@@ -1531,6 +1542,7 @@ zenity_text_pre_callback (GOptionContext *context,
zenity_text_active = FALSE;
zenity_text_font = NULL;
zenity_text_checkbox = NULL;
+ zenity_text_auto_scroll = FALSE;
#ifdef HAVE_WEBKITGTK
zenity_text_enable_html = FALSE;
zenity_text_url = NULL;
@@ -1944,6 +1956,7 @@ zenity_text_post_callback (GOptionContext *context,
results->text_data->no_wrap = zenity_general_dialog_no_wrap;
results->text_data->font = zenity_text_font;
results->text_data->checkbox = zenity_text_checkbox;
+ results->text_data->auto_scroll = zenity_text_auto_scroll;
#ifdef HAVE_WEBKITGTK
results->text_data->html = zenity_text_enable_html;
results->text_data->url = zenity_text_url;
diff --git a/src/text.c b/src/text.c
index 056ad28b..fda60dcd 100644
--- a/src/text.c
+++ b/src/text.c
@@ -134,11 +134,13 @@ zenity_text_handle_stdin (GIOChannel *channel,
gpointer data)
{
static GtkTextBuffer *buffer;
+ static GtkTextView *text_view;
gchar buf[1024];
gsize len;
- buffer = GTK_TEXT_BUFFER (data);
+ text_view = GTK_TEXT_VIEW (data);
+ buffer = gtk_text_view_get_buffer (text_view);
if ((condition & G_IO_IN) || (condition & (G_IO_IN | G_IO_HUP))) {
GError *error = NULL;
@@ -179,6 +181,12 @@ zenity_text_handle_stdin (GIOChannel *channel,
} else {
gtk_text_buffer_insert (buffer, &end, buf, len);
}
+ if (zen_text_data->auto_scroll) {
+ GtkTextMark *mark = NULL;
+ mark = gtk_text_buffer_get_insert (buffer);
+ if (mark != NULL)
+ gtk_text_view_scroll_to_mark (text_view, mark, 0.0, FALSE, 0, 0);
+ }
}
}
@@ -186,14 +194,14 @@ zenity_text_handle_stdin (GIOChannel *channel,
}
static void
-zenity_text_fill_entries_from_stdin (GtkTextBuffer *text_buffer)
+zenity_text_fill_entries_from_stdin (GtkTextView *text_view)
{
GIOChannel *channel;
channel = g_io_channel_unix_new (0);
g_io_channel_set_encoding (channel, NULL, NULL);
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_text_handle_stdin, text_buffer);
+ g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_text_handle_stdin, text_view);
}
void
@@ -233,7 +241,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
g_signal_connect (G_OBJECT (dialog), "response",
G_CALLBACK (zenity_text_dialog_response), data);
-
+
if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
@@ -257,7 +265,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
if (text_data->uri)
zenity_util_fill_file_buffer (text_buffer, text_data->uri);
else
- zenity_text_fill_entries_from_stdin (GTK_TEXT_BUFFER (text_buffer));
+ zenity_text_fill_entries_from_stdin (GTK_TEXT_VIEW(text_view));
if (text_data->editable)
zen_text_data->buffer = text_buffer;
@@ -326,6 +334,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
gtk_widget_show (GTK_WIDGET (web_kit));
}
#endif
+
zenity_util_show_dialog (dialog, data->attach);
g_object_unref (builder);
diff --git a/src/zenity.h b/src/zenity.h
index 52c29df5..6e1b6875 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -110,6 +110,7 @@ typedef struct {
gchar *uri;
gboolean editable;
gboolean no_wrap;
+ gboolean auto_scroll;
gchar *font;
GtkTextBuffer *buffer;
gchar *checkbox;
bgstack15