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
This commit is contained in:
parent
b0fc720fe4
commit
4681d74c02
13
src/option.c
13
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;
|
||||
|
17
src/text.c
17
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
|
||||
@ -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);
|
||||
|
@ -110,6 +110,7 @@ typedef struct {
|
||||
gchar *uri;
|
||||
gboolean editable;
|
||||
gboolean no_wrap;
|
||||
gboolean auto_scroll;
|
||||
gchar *font;
|
||||
GtkTextBuffer *buffer;
|
||||
gchar *checkbox;
|
||||
|
Reference in New Issue
Block a user