Mercurial > pidgin
changeset 18426:841670dd24e1
Utility function to start the pager with the contents of a textview.
The default pager is 'less', and the default key-combination to trigger it
is 'a-v'. These can be changed like:
[pager]
path=/some/other/pager
key=a-e
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 03 Jul 2007 11:17:35 +0000 |
parents | 84d318eadc62 |
children | be8c4eba38f6 |
files | finch/libgnt/gnttextview.c finch/libgnt/gnttextview.h |
diffstat | 2 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/finch/libgnt/gnttextview.c Tue Jul 03 11:09:19 2007 +0000 +++ b/finch/libgnt/gnttextview.c Tue Jul 03 11:17:35 2007 +0000 @@ -20,9 +20,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "gntstyle.h" #include "gnttextview.h" #include "gntutils.h" +#include <stdlib.h> #include <string.h> enum @@ -793,3 +795,43 @@ view->flags |= flag; } +static gboolean +check_for_pager_cb(GntWidget *widget, const char *key, GntTextView *view) +{ + static const char *combin = NULL; + char *argv[] = {NULL, NULL, NULL}; + static char path[1024]; + static int len = -1; + FILE *file; + + if (combin == NULL) { + combin = gnt_key_translate(gnt_style_get_from_name("pager", "key")); + if (combin == NULL) + combin = "\033" "v"; + len = g_snprintf(path, sizeof(path), "%s" G_DIR_SEPARATOR_S "gnt", g_get_tmp_dir()); + } else { + g_snprintf(path + len, sizeof(path) - len, "XXXXXX"); + } + + if (strcmp(key, combin)) { + return FALSE; + } + + file = fdopen(g_mkstemp(path), "wb"); + if (!file) + return FALSE; + + fprintf(file, "%s", view->string->str); + fclose(file); + argv[0] = gnt_style_get_from_name("pager", "path"); + argv[0] = argv[0] ? argv[0] : getenv("PAGER"); + argv[0] = argv[0] ? argv[0] : "less"; + argv[1] = path; + return gnt_giveup_console(NULL, argv, NULL, NULL, NULL, NULL); +} + +void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager) +{ + g_signal_connect(pager, "key_pressed", G_CALLBACK(check_for_pager_cb), view); +} +
--- a/finch/libgnt/gnttextview.h Tue Jul 03 11:09:19 2007 +0000 +++ b/finch/libgnt/gnttextview.h Tue Jul 03 11:17:35 2007 +0000 @@ -184,6 +184,13 @@ void gnt_text_view_attach_scroll_widget(GntTextView *view, GntWidget *widget); /** + * + * @param view + * @param widget + */ +void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager); + +/** * Set a GntTextViewFlag for the textview widget. * * @param view The textview widget