2005-02-09 [colin] 1.0.1cvs1.3
authorColin Leroy <colin@colino.net>
Wed, 9 Feb 2005 13:15:30 +0000 (13:15 +0000)
committerColin Leroy <colin@colino.net>
Wed, 9 Feb 2005 13:15:30 +0000 (13:15 +0000)
* src/textview.c
* src/textview.h
Add contextual menu on emails

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/textview.c
src/textview.h

index 017abd78023f3bfd6aa83753abde82000332cdca..f7a439655cc7c3c03be1c1065962013b0b5455e1 100644 (file)
@@ -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
index 950146edc2dbd98fd01a46a71498599617f070f3..7d69429ed3501c1cd69b409f028c4bf526e6f299 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( 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
index d5ba74c31f442bba6ff7fe1df8d45f7db31fc742..02729c0bb6ea7687bb5ba8def103fe3dd617ed39 100644 (file)
@@ -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}
index a50dd104f7a633ec1f6687ef6d5a8ca01b63907b..bda46c7147e7ff20376fe9fd587f23f971c449b0 100644 (file)
@@ -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,
-                                     "<UriPopupMenu>", &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,
+                                     "<UriPopupMenu>", &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,
+                                     "<UriPopupMenu>", &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);
+}
+
+
index 9d10be52ed3ec90db36e9268e831cc2d9f7ef66c..22af79dbce175970acbb245a8a7888c29ed17f36 100644 (file)
@@ -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;