diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2004-09-20 13:59:55 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-09-20 13:59:55 +0800 |
commit | ef6a3af717132e0750f226fa8a0ee0f3c98e19f0 (patch) | |
tree | f4ed25f7a247a8ccb855a8d940777e7a3d21a3e3 /composer/e-msg-composer-attachment-bar.c | |
parent | 96111b1f1487ca3fe454b340a73ba927cc6bfb83 (diff) | |
download | gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.tar.gz gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.tar.zst gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.zip |
Merged notzed-eplugin-2-branch to head.
svn path=/trunk/; revision=27300
Diffstat (limited to 'composer/e-msg-composer-attachment-bar.c')
-rw-r--r-- | composer/e-msg-composer-attachment-bar.c | 247 |
1 files changed, 98 insertions, 149 deletions
diff --git a/composer/e-msg-composer-attachment-bar.c b/composer/e-msg-composer-attachment-bar.c index ea953c83b3..5bc912baed 100644 --- a/composer/e-msg-composer-attachment-bar.c +++ b/composer/e-msg-composer-attachment-bar.c @@ -31,11 +31,8 @@ #include <gconf/gconf.h> #include <gconf/gconf-client.h> #include <gdk/gdkkeysyms.h> -#include <libgnome/gnome-util.h> -#include <libgnomeui/gnome-app.h> -#include <libgnomeui/gnome-app-helper.h> -#include <libgnomeui/gnome-popup-menu.h> #include <libgnomevfs/gnome-vfs-mime-handlers.h> +#include <libgnome/gnome-i18n.h> #include "e-msg-composer.h" #include "e-msg-composer-select-file.h" @@ -55,6 +52,7 @@ #include "e-util/e-gui-utils.h" #include "e-util/e-icon-factory.h" #include "widgets/misc/e-error.h" +#include "mail/em-popup.h" #define ICON_WIDTH 64 #define ICON_SEPARATORS " /-_" @@ -70,9 +68,6 @@ static GnomeIconListClass *parent_class = NULL; struct _EMsgComposerAttachmentBarPrivate { GList *attachments; guint num_attachments; - - GtkWidget *context_menu; - GtkWidget *icon_context_menu; }; @@ -375,20 +370,20 @@ static void edit_selected (EMsgComposerAttachmentBar *bar) { GnomeIconList *icon_list; - EMsgComposerAttachment *attachment; - GList *selection; + GList *selection, *attach; int num; icon_list = GNOME_ICON_LIST (bar); selection = gnome_icon_list_get_selection (icon_list); - num = GPOINTER_TO_INT (selection->data); - attachment = g_list_nth (bar->priv->attachments, num)->data; - - e_msg_composer_attachment_edit (attachment, GTK_WIDGET (bar)); + if (selection) { + num = GPOINTER_TO_INT (selection->data); + attach = g_list_nth (bar->priv->attachments, num); + if (attach) + e_msg_composer_attachment_edit ((EMsgComposerAttachment *)attach->data, GTK_WIDGET (bar)); + } } - /* "Attach" dialog. */ static void @@ -417,109 +412,115 @@ add_from_user (EMsgComposerAttachmentBar *bar) /* Callbacks. */ static void -add_cb (GtkWidget *widget, gpointer data, GtkWidget *for_widget) +emcab_add(EPopup *ep, EPopupItem *item, void *data) { - g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (data)); - - add_from_user (E_MSG_COMPOSER_ATTACHMENT_BAR (data)); + EMsgComposerAttachmentBar *bar = data; + + add_from_user(bar); } static void -properties_cb (GtkWidget *widget, gpointer data, GtkWidget *for_widget) +emcab_properties(EPopup *ep, EPopupItem *item, void *data) { - EMsgComposerAttachmentBar *bar; - - g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (data)); + EMsgComposerAttachmentBar *bar = data; - bar = E_MSG_COMPOSER_ATTACHMENT_BAR (data); - edit_selected (data); + edit_selected(bar); } static void -remove_cb (GtkWidget *widget, gpointer data, GtkWidget *for_widget) +emcab_remove(EPopup *ep, EPopupItem *item, void *data) { - EMsgComposerAttachmentBar *bar; - - g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (data)); - - bar = E_MSG_COMPOSER_ATTACHMENT_BAR (data); - remove_selected (bar); -} + EMsgComposerAttachmentBar *bar = data; + remove_selected(bar); +} /* Popup menu handling. */ - -static GnomeUIInfo icon_context_menu_info[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_Remove"), - N_("Remove selected items from the attachment list"), - remove_cb, - GTK_STOCK_REMOVE), - GNOMEUIINFO_MENU_PROPERTIES_ITEM (properties_cb, NULL), - GNOMEUIINFO_END +static EPopupItem emcab_popups[] = { + { E_POPUP_ITEM, "10.attach", N_("_Remove"), emcab_remove, NULL, GTK_STOCK_REMOVE, EM_POPUP_ATTACHMENTS_MANY }, + { E_POPUP_ITEM, "20.attach", N_("_Properties"), emcab_properties, NULL, GTK_STOCK_PROPERTIES, EM_POPUP_ATTACHMENTS_ONE }, + { E_POPUP_BAR, "30.attach.00", NULL, NULL, NULL, NULL, EM_POPUP_ATTACHMENTS_MANY|EM_POPUP_ATTACHMENTS_ONE }, + { E_POPUP_ITEM, "30.attach.01", N_("_Add attachment..."), emcab_add, NULL, GTK_STOCK_ADD, 0 }, }; -#define ICON_CONTEXT_MENU_PROPERTIES (1) - -static GtkWidget * -get_icon_context_menu (EMsgComposerAttachmentBar *bar) +static void +emcab_popup_position(GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer user_data) { - EMsgComposerAttachmentBarPrivate *priv; + EMsgComposerAttachmentBar *bar = user_data; + GnomeIconList *icon_list = user_data; + GList *selection; + GnomeCanvasPixbuf *image; - priv = bar->priv; - if (priv->icon_context_menu == NULL) - priv->icon_context_menu = gnome_popup_menu_new (icon_context_menu_info); + gdk_window_get_origin (((GtkWidget*) bar)->window, x, y); - return priv->icon_context_menu; + selection = gnome_icon_list_get_selection (icon_list); + if (selection == NULL) + return; + + image = gnome_icon_list_get_icon_pixbuf_item (icon_list, (gint)selection->data); + if (image == NULL) + return; + + /* Put menu to the center of icon. */ + *x += (int)(image->item.x1 + image->item.x2) / 2; + *y += (int)(image->item.y1 + image->item.y2) / 2; } static void -popup_icon_context_menu (EMsgComposerAttachmentBar *bar, - gint num, - GdkEventButton *event) +emcab_popups_free(EPopup *ep, GSList *l, void *data) { - GtkWidget *menu; - GnomeIconList *icon_list; - GList *selection; + g_slist_free(l); +} - menu = get_icon_context_menu (bar); - icon_list = GNOME_ICON_LIST (bar); - selection = gnome_icon_list_get_selection (icon_list); +/* if id != -1, then use it as an index for target of the popup */ +static void +emcab_popup(EMsgComposerAttachmentBar *bar, GdkEventButton *event, int id) +{ + GList *p; + GSList *attachments = NULL, *menus = NULL; + int i; + EMPopup *emp; + EMPopupTargetAttachments *t; + GtkMenu *menu; + EMsgComposerAttachment *attachment; - gtk_widget_set_sensitive (icon_context_menu_info[ICON_CONTEXT_MENU_PROPERTIES].widget, g_list_length (selection) == 1); + /* We need to check if there are duplicated index in the return list of + gnome_icon_list_get_selection() because of gnome bugzilla bug #122356. + FIXME in the future. */ - gnome_popup_menu_do_popup (menu, NULL, NULL, event, bar, NULL); -} + if (id == -1 + || (attachment = g_list_nth_data(bar->priv->attachments, id)) == NULL) { + p = gnome_icon_list_get_selection((GnomeIconList *)bar); + for ( ; p != NULL; p = p->next) { + int num = GPOINTER_TO_INT(p->data); + EMsgComposerAttachment *attachment = g_list_nth_data(bar->priv->attachments, num); + + if (attachment && g_slist_find(attachments, attachment) == NULL) { + g_object_ref(attachment); + attachments = g_slist_prepend(attachments, attachment); + } + } + attachments = g_slist_reverse(attachments); + } else { + g_object_ref(attachment); + attachments = g_slist_prepend(attachments, attachment); + } -static GnomeUIInfo context_menu_info[] = { - GNOMEUIINFO_ITEM (N_("Add attachment..."), - N_("Attach a file to the message"), - add_cb, NULL), - GNOMEUIINFO_END -}; + for (i=0;i<sizeof(emcab_popups)/sizeof(emcab_popups[0]);i++) + menus = g_slist_prepend(menus, &emcab_popups[i]); -static GtkWidget * -get_context_menu (EMsgComposerAttachmentBar *bar) -{ - EMsgComposerAttachmentBarPrivate *priv; - - priv = bar->priv; - if (priv->context_menu == NULL) - priv->context_menu = gnome_popup_menu_new (context_menu_info); - - return priv->context_menu; -} + emp = em_popup_new("com.novell.evolution.mail.composer.attachmentBar"); + e_popup_add_items((EPopup *)emp, menus, emcab_popups_free, bar); + t = em_popup_target_new_attachments(emp, attachments); + t->target.widget = (GtkWidget *)bar; + menu = e_popup_create_menu_once((EPopup *)emp, (EPopupTarget *)t, t->target.mask, t->target.mask); -static void -popup_context_menu (EMsgComposerAttachmentBar *bar, - GdkEventButton *event) -{ - GtkWidget *menu; - - menu = get_context_menu (bar); - gnome_popup_menu_do_popup (menu, NULL, NULL, event, bar, NULL); + if (event == NULL) + gtk_menu_popup(menu, NULL, NULL, emcab_popup_position, bar, 0, gtk_get_current_event_time()); + else + gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button, event->time); } - /* GtkObject methods. */ static void @@ -539,91 +540,42 @@ destroy (GtkObject *object) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } - /* GtkWidget methods. */ - -static void -popup_menu_placement_callback (GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer user_data) -{ - EMsgComposerAttachmentBar *bar; - GnomeIconList *icon_list; - GList *selection; - GnomeCanvasPixbuf *image; - - bar = E_MSG_COMPOSER_ATTACHMENT_BAR (user_data); - icon_list = GNOME_ICON_LIST (user_data); - - gdk_window_get_origin (((GtkWidget*) bar)->window, x, y); - - selection = gnome_icon_list_get_selection (icon_list); - if (selection == NULL) - return; - - image = gnome_icon_list_get_icon_pixbuf_item (icon_list, (gint)selection->data); - if (image == NULL) - return; - - /* Put menu to the center of icon. */ - *x += (int)(image->item.x1 + image->item.x2) / 2; - *y += (int)(image->item.y1 + image->item.y2) / 2; -} - static gboolean popup_menu_event (GtkWidget *widget) { - EMsgComposerAttachmentBar *bar = E_MSG_COMPOSER_ATTACHMENT_BAR (widget); - GnomeIconList *icon_list = GNOME_ICON_LIST (widget); - GList *selection = gnome_icon_list_get_selection (icon_list); - GtkWidget *menu; - - if (selection == NULL) - menu = get_context_menu (bar); - else - menu = get_icon_context_menu (bar); - - gnome_popup_menu_do_popup (menu, popup_menu_placement_callback, - widget, NULL, widget, NULL); - + emcab_popup((EMsgComposerAttachmentBar *)widget, NULL, -1); return TRUE; } static int -button_press_event (GtkWidget *widget, - GdkEventButton *event) +button_press_event (GtkWidget *widget, GdkEventButton *event) { - EMsgComposerAttachmentBar *bar; - GnomeIconList *icon_list; + EMsgComposerAttachmentBar *bar = (EMsgComposerAttachmentBar *)widget; + GnomeIconList *icon_list = GNOME_ICON_LIST(widget); int icon_number; - bar = E_MSG_COMPOSER_ATTACHMENT_BAR (widget); - icon_list = GNOME_ICON_LIST (widget); - if (event->button != 3) return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event); icon_number = gnome_icon_list_get_icon_at (icon_list, event->x, event->y); - if (icon_number >= 0) { + gnome_icon_list_unselect_all(icon_list); gnome_icon_list_select_icon (icon_list, icon_number); - popup_icon_context_menu (bar, icon_number, event); - } else { - popup_context_menu (bar, event); } + + emcab_popup(bar, event, icon_number); return TRUE; } static gint -key_press_event (GtkWidget *widget, GdkEventKey *event) +key_press_event(GtkWidget *widget, GdkEventKey *event) { - EMsgComposerAttachmentBar *bar; - GnomeIconList *icon_list; - - bar = E_MSG_COMPOSER_ATTACHMENT_BAR (widget); - icon_list = GNOME_ICON_LIST (bar); - + EMsgComposerAttachmentBar *bar = E_MSG_COMPOSER_ATTACHMENT_BAR(widget); + if (event->keyval == GDK_Delete) { remove_selected (bar); return TRUE; @@ -675,9 +627,6 @@ init (EMsgComposerAttachmentBar *bar) priv = g_new (EMsgComposerAttachmentBarPrivate, 1); priv->attachments = NULL; - priv->context_menu = NULL; - priv->icon_context_menu = NULL; - priv->num_attachments = 0; bar->priv = priv; |