From 007706e337f456daf667f2222f9fc79c3c1245b4 Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Wed, 9 Feb 2005 13:15:30 +0000 Subject: [PATCH] 2005-02-09 [colin] 1.0.1cvs1.3 * src/textview.c * src/textview.h Add contextual menu on emails --- ChangeLog-gtk2.claws | 6 ++ PATCHSETS | 1 + configure.ac | 2 +- src/textview.c | 127 +++++++++++++++++++++++++++++++------------ src/textview.h | 6 +- 5 files changed, 103 insertions(+), 39 deletions(-) diff --git a/ChangeLog-gtk2.claws b/ChangeLog-gtk2.claws index 017abd780..f7a439655 100644 --- a/ChangeLog-gtk2.claws +++ b/ChangeLog-gtk2.claws @@ -1,3 +1,9 @@ +2005-02-09 [colin] 1.0.1cvs1.3 + + * src/textview.c + * src/textview.h + Add contextual menu on emails + 2005-02-09 [colin] 1.0.1cvs1.2 * src/codeconv.c diff --git a/PATCHSETS b/PATCHSETS index 950146edc..7d69429ed 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -365,3 +365,4 @@ ( cvs diff -u -r 1.2504.2.46 -r 1.2504.2.47 ChangeLog.claws; cvs diff -u -r 1.50.2.5 -r 1.50.2.6 po/pt_BR.po; ) > 1.0.1.1.patchset ( cvs diff -u -r 1.94.2.42 -r 1.94.2.43 src/messageview.c; cvs diff -u -r 1.83.2.27 -r 1.83.2.28 src/mimeview.c; cvs diff -u -r 1.20.2.2 -r 1.20.2.3 src/mimeview.h; ) > 1.0.1cvs1.1.patchset ( cvs diff -u -r 1.65.2.21 -r 1.65.2.22 src/codeconv.c; ) > 1.0.1cvs1.2.patchset +( cvs diff -u -r 1.96.2.42 -r 1.96.2.43 src/textview.c; cvs diff -u -r 1.12.2.3 -r 1.12.2.4 src/textview.h; ) > 1.0.1cvs1.3.patchset diff --git a/configure.ac b/configure.ac index d5ba74c31..02729c0bb 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,7 @@ INTERFACE_AGE=0 BINARY_AGE=0 EXTRA_VERSION=1 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 a50dd104f..bda46c714 100644 --- a/src/textview.c +++ b/src/textview.c @@ -192,13 +192,25 @@ static void open_uri_cb (TextView *textview, static void copy_uri_cb (TextView *textview, guint action, void *data); - -static GtkItemFactoryEntry textview_popup_entries[] = +static void add_uri_to_addrbook_cb (TextView *textview, + guint action, + void *data); +static void mail_to_uri_cb (TextView *textview, + guint action, + void *data); + +static GtkItemFactoryEntry textview_link_popup_entries[] = { {N_("/_Open link"), NULL, open_uri_cb, 0, NULL}, {N_("/_Copy link location"), NULL, copy_uri_cb, 0, NULL}, }; +static GtkItemFactoryEntry textview_mail_popup_entries[] = +{ + {N_("/_Add to addressbook"), NULL, add_uri_to_addrbook_cb, 0, NULL}, + {N_("/_Email"), NULL, mail_to_uri_cb, 0, NULL}, +}; + TextView *textview_create(void) { @@ -208,8 +220,8 @@ TextView *textview_create(void) GtkWidget *text; GtkTextBuffer *buffer; GtkClipboard *clipboard; - GtkItemFactory *popupfactory; - GtkWidget *popupmenu; + GtkItemFactory *link_popupfactory, *mail_popupfactory; + GtkWidget *link_popupmenu, *mail_popupmenu; gint n_entries; debug_print("Creating text view...\n"); @@ -268,21 +280,29 @@ 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, + n_entries = sizeof(textview_link_popup_entries) / + sizeof(textview_link_popup_entries[0]); + link_popupmenu = menu_create_items(textview_link_popup_entries, n_entries, + "", &link_popupfactory, textview); - textview->vbox = vbox; - textview->scrolledwin = scrolledwin; - textview->text = text; - textview->uri_list = NULL; - textview->body_pos = 0; - textview->show_all_headers = FALSE; - textview->last_buttonpress = GDK_NOTHING; - textview->popup_menu = popupmenu; - textview->popup_factory = popupfactory; + n_entries = sizeof(textview_mail_popup_entries) / + sizeof(textview_mail_popup_entries[0]); + mail_popupmenu = menu_create_items(textview_mail_popup_entries, n_entries, + "", &mail_popupfactory, + textview); + + textview->vbox = vbox; + textview->scrolledwin = scrolledwin; + textview->text = text; + textview->uri_list = NULL; + textview->body_pos = 0; + textview->show_all_headers = FALSE; + textview->last_buttonpress = GDK_NOTHING; + textview->link_popup_menu = link_popupmenu; + textview->link_popup_factory = link_popupfactory; + textview->mail_popup_menu = mail_popupmenu; + textview->mail_popup_factory = mail_popupfactory; return textview; } @@ -2040,19 +2060,12 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj, bevent->button == 2 || bevent->button == 3) { if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) { if (bevent->button == 3) { - gchar *fromname, *fromaddress; - - /* extract url */ - fromaddress = g_strdup(uri->uri + 7); - /* Hiroyuki: please put this function in utils.c! */ - fromname = procheader_get_fromname(fromaddress); - extract_address(fromaddress); - g_message("adding from textview %s <%s>", fromname, fromaddress); - /* Add to address book - Match */ - addressbook_add_contact( fromname, fromaddress, NULL ); - - g_free(fromaddress); - g_free(fromname); + g_object_set_data( + G_OBJECT(textview->mail_popup_menu), + "menu_button", uri); + gtk_menu_popup(GTK_MENU(textview->mail_popup_menu), + NULL, NULL, NULL, NULL, + bevent->button, bevent->time); } else { PrefsAccount *account = NULL; @@ -2074,9 +2087,9 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj, prefs_common.uri_cmd); else if (bevent->button == 3) { g_object_set_data( - G_OBJECT(textview->popup_menu), + G_OBJECT(textview->link_popup_menu), "menu_button", uri); - gtk_menu_popup(GTK_MENU(textview->popup_menu), + gtk_menu_popup(GTK_MENU(textview->link_popup_menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); } @@ -2165,7 +2178,7 @@ static void textview_uri_list_remove_all(GSList *uri_list) static void open_uri_cb (TextView *textview, guint action, void *data) { - RemoteURI *uri = g_object_get_data(G_OBJECT(textview->popup_menu), + RemoteURI *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu), "menu_button"); if (uri == NULL) return; @@ -2173,18 +2186,60 @@ static void open_uri_cb (TextView *textview, guint action, void *data) 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", + g_object_set_data(G_OBJECT(textview->link_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), + RemoteURI *uri = g_object_get_data(G_OBJECT(textview->link_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", + g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button", NULL); } + +static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data) +{ + gchar *fromname, *fromaddress; + RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu), + "menu_button"); + if (uri == NULL) + return; + + /* extract url */ + fromaddress = g_strdup(uri->uri + 7); + /* Hiroyuki: please put this function in utils.c! */ + fromname = procheader_get_fromname(fromaddress); + extract_address(fromaddress); + g_message("adding from textview %s <%s>", fromname, fromaddress); + /* Add to address book - Match */ + addressbook_add_contact( fromname, fromaddress, NULL ); + + g_free(fromaddress); + g_free(fromname); +} + +static void mail_to_uri_cb (TextView *textview, guint action, void *data) +{ + PrefsAccount *account = NULL; + RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu), + "menu_button"); + if (uri == NULL) + return; + + if (textview->messageview && textview->messageview->msginfo && + textview->messageview->msginfo->folder) { + FolderItem *folder_item; + + folder_item = textview->messageview->msginfo->folder; + if (folder_item->prefs && folder_item->prefs->enable_default_account) + account = account_find_from_id(folder_item->prefs->default_account); + } + compose_new(account, uri->uri + 7, NULL); +} + + diff --git a/src/textview.h b/src/textview.h index 9d10be52e..22af79dbc 100644 --- a/src/textview.h +++ b/src/textview.h @@ -40,8 +40,10 @@ struct _TextView GtkWidget *scrolledwin; GtkWidget *text; - GtkWidget *popup_menu; - GtkItemFactory *popup_factory; + GtkWidget *link_popup_menu; + GtkItemFactory *link_popup_factory; + GtkWidget *mail_popup_menu; + GtkItemFactory *mail_popup_factory; gboolean default_text; gboolean is_in_signature; -- 2.25.1