From cf8d38162844e03afd452d4f20300e1d0cb9d151 Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Fri, 19 Nov 2004 10:39:01 +0000 Subject: [PATCH] 2004-11-19 [colin] 0.9.12cvs158.3 * src/textview.c Add a context menu on links (open, copy) --- ChangeLog-gtk2.claws | 5 ++++ PATCHSETS | 1 + configure.ac | 2 +- src/textview.c | 71 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 68 insertions(+), 11 deletions(-) diff --git a/ChangeLog-gtk2.claws b/ChangeLog-gtk2.claws index 8f062f995..0507af2ac 100644 --- a/ChangeLog-gtk2.claws +++ b/ChangeLog-gtk2.claws @@ -1,3 +1,8 @@ +2004-11-19 [colin] 0.9.12cvs158.3 + + * src/textview.c + Add a context menu on links (open, copy) + 2004-11-18 [paul] 0.9.12cvs158.2 * src/addrgather.c diff --git a/PATCHSETS b/PATCHSETS index a1c360a88..c21f912f0 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -248,3 +248,4 @@ ( cvs diff -u -r 1.105.2.12 -r 1.105.2.13 src/prefs_account.c; cvs diff -u -r 1.49.2.7 -r 1.49.2.8 src/prefs_account.h; cvs diff -u -r 1.150.2.16 -r 1.150.2.17 src/procmsg.c; ) > 0.9.12cvs156.1.patchset ( cvs diff -u -r 1.654.2.280 -r 1.654.2.281 configure.ac; cvs diff -u -r 1.382.2.68 -r 1.382.2.69 src/compose.c; cvs diff -u -r 1.274.2.24 -r 1.274.2.25 src/mainwindow.c; cvs diff -u -r 1.94.2.34 -r 1.94.2.35 src/messageview.c; cvs diff -u -r 1.204.2.22 -r 1.204.2.23 src/prefs_common.c; cvs diff -u -r 1.36.2.15 -r 1.36.2.16 src/common/utils.c; cvs diff -u -r 1.20.2.10 -r 1.20.2.11 src/common/utils.h; ) > 0.9.12cvs158.1.patchset ( cvs diff -u -r 1.5.10.5 -r 1.5.10.6 src/addrgather.c; cvs diff -u -r 1.3.2.5 -r 1.3.2.6 src/exphtmldlg.c; cvs diff -u -r 1.1.4.5 -r 1.1.4.6 src/expldifdlg.c; cvs diff -u -r 1.83.2.24 -r 1.83.2.25 src/mimeview.c; cvs diff -u -r 1.204.2.23 -r 1.204.2.24 src/prefs_common.c; cvs diff -u -r 1.7.2.8 -r 1.7.2.9 src/plugins/image_viewer/viewer.c; cvs diff -u -r 1.23.2.6 -r 1.23.2.7 src/plugins/spamassassin/spamassassin_gtk.c; ) > 0.9.12cvs158.2.patchset +( cvs diff -u -r 1.96.2.35 -r 1.96.2.36 src/textview.c; ) > 0.9.12cvs158.3.patchset diff --git a/configure.ac b/configure.ac index 0f4d26a6b..31608f12c 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ INTERFACE_AGE=0 BINARY_AGE=0 EXTRA_VERSION=158 EXTRA_RELEASE= -EXTRA_GTK2_VERSION=.2 +EXTRA_GTK2_VERSION=.3 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}${EXTRA_RELEASE}${EXTRA_GTK2_VERSION} diff --git a/src/textview.c b/src/textview.c index ba97f5076..1476bab0a 100644 --- a/src/textview.c +++ b/src/textview.c @@ -51,6 +51,7 @@ #include "account.h" #include "mimeview.h" #include "alertpanel.h" +#include "menu.h" struct _RemoteURI { @@ -185,12 +186,19 @@ static gboolean textview_uri_security_check (TextView *textview, RemoteURI *uri); static void textview_uri_list_remove_all (GSList *uri_list); +static void open_uri_cb (TextView *textview, + guint action, + void *data); +static void copy_uri_cb (TextView *textview, + guint action, + void *data); -static void populate_popup(GtkTextView *textview, GtkMenu *menu, - gpointer *dummy) +static GtkItemFactoryEntry textview_popup_entries[] = { - gtk_menu_detach(menu); -} + {N_("/_Open link"), NULL, open_uri_cb, 0, NULL}, + {N_("/_Copy link location"), NULL, copy_uri_cb, 0, NULL}, +}; + TextView *textview_create(void) { @@ -200,6 +208,9 @@ TextView *textview_create(void) GtkWidget *text; GtkTextBuffer *buffer; GtkClipboard *clipboard; + GtkItemFactory *popupfactory; + GtkWidget *popupmenu; + gint n_entries; PangoFontDescription *font_desc = NULL; debug_print("Creating text view...\n"); @@ -219,9 +230,6 @@ TextView *textview_create(void) gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE); - g_signal_connect(G_OBJECT(text), "populate-popup", - G_CALLBACK(populate_popup), NULL); - buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); @@ -266,6 +274,12 @@ TextView *textview_create(void) gtk_widget_show(vbox); + n_entries = sizeof(textview_popup_entries) / + sizeof(textview_popup_entries[0]); + popupmenu = menu_create_items(textview_popup_entries, n_entries, + "", &popupfactory, + textview); + textview->vbox = vbox; textview->scrolledwin = scrolledwin; textview->text = text; @@ -273,6 +287,8 @@ TextView *textview_create(void) textview->body_pos = 0; textview->show_all_headers = FALSE; textview->last_buttonpress = GDK_NOTHING; + textview->popup_menu = popupmenu; + textview->popup_factory = popupfactory; return textview; } @@ -2074,9 +2090,18 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj, } return TRUE; } else { - if (textview_uri_security_check(textview, uri) == TRUE) - open_uri(uri->uri, - prefs_common.uri_cmd); + if (bevent->button == 1 && + textview_uri_security_check(textview, uri) == TRUE) + open_uri(uri->uri, + prefs_common.uri_cmd); + else if (bevent->button == 3) { + g_object_set_data( + G_OBJECT(textview->popup_menu), + "menu_button", uri); + gtk_menu_popup(GTK_MENU(textview->popup_menu), + NULL, NULL, NULL, NULL, + bevent->button, bevent->time); + } return TRUE; } } @@ -2158,3 +2183,29 @@ static void textview_uri_list_remove_all(GSList *uri_list) g_slist_free(uri_list); } + +static void open_uri_cb (TextView *textview, guint action, void *data) +{ + RemoteURI *uri = g_object_get_data(G_OBJECT(textview->popup_menu), + "menu_button"); + if (uri == NULL) + return; + + if (textview_uri_security_check(textview, uri) == TRUE) + open_uri(uri->uri, + prefs_common.uri_cmd); + g_object_set_data(G_OBJECT(textview->popup_menu), "menu_button", + NULL); +} + +static void copy_uri_cb (TextView *textview, guint action, void *data) +{ + RemoteURI *uri = g_object_get_data(G_OBJECT(textview->popup_menu), + "menu_button"); + if (uri == NULL) + return; + + gtk_clipboard_set_text(gtk_clipboard_get(GDK_NONE), uri->uri, -1); + g_object_set_data(G_OBJECT(textview->popup_menu), "menu_button", + NULL); +} -- 2.25.1