From 8873c47ed16aa9babd88312672a72ea56dcca471 Mon Sep 17 00:00:00 2001 From: Suman Manjunath Date: Fri, 11 Apr 2008 18:52:39 +0000 Subject: Fix for bug #517134 : Extend the 'Insert' menu (in editors) to show a "Recent Documents" submenu (to quickly add them as attachments). M configure.in M ChangeLog M composer/evolution-composer.ui M composer/ChangeLog M composer/e-composer-actions.c M composer/e-composer-private.c M widgets/misc/ChangeLog M widgets/misc/e-attachment-bar.c M widgets/misc/e-attachment-bar.h M calendar/gui/dialogs/comp-editor.c M calendar/ChangeLog M ui/ChangeLog M ui/evolution-editor.xml svn path=/trunk/; revision=35354 --- widgets/misc/ChangeLog | 12 +++ widgets/misc/e-attachment-bar.c | 159 +++++++++++++++++++++++++++++++++++++++- widgets/misc/e-attachment-bar.h | 11 +++ 3 files changed, 181 insertions(+), 1 deletion(-) (limited to 'widgets/misc') diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index e5e59a03e0..20bd302337 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,15 @@ +2008-04-11 Suman Manjunath + + ** Fix for bug #517134 + + * e-attachment-bar.c: (destroy), (init): Related changes. + (e_attachment_bar_bonobo_ui_populate_with_recent): New API to populate + a bonoboUI menu with "Recent Documents". + (action_recent_cb), (e_attachment_bar_recent_action_new): New API to + obtain a new, pre-configured GtkRecentAction (which can be used as a + "Recent Documents" menu) + * e-attachment-bar.h: APIs' signatures + 2008-04-02 Matthew Barnes * Makefile.am: diff --git a/widgets/misc/e-attachment-bar.c b/widgets/misc/e-attachment-bar.c index 33bff284f7..2e31810f32 100644 --- a/widgets/misc/e-attachment-bar.c +++ b/widgets/misc/e-attachment-bar.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -71,6 +72,9 @@ static GnomeIconListClass *parent_class = NULL; struct _EAttachmentBarPrivate { GtkWidget *attach; /* attachment file dialogue, if active */ + /* Recent documents. Use this widget directly when bonoboui is obsoleted */ + GtkWidget *recent; + gboolean batch_unref; GPtrArray *attachments; char *path; @@ -551,7 +555,6 @@ e_attachment_bar_get_selector(EAttachmentBar *bar) return &bar->priv->attach; } - /** * e_attachment_bar_get_selected: * @bar: an #EAttachmentBar object @@ -694,6 +697,9 @@ destroy (GtkObject *object) if (priv->attach) gtk_widget_destroy (priv->attach); + if (priv->recent) + gtk_widget_destroy (priv->recent); + if (priv->path) g_free (priv->path); @@ -969,6 +975,15 @@ init (EAttachmentBar *bar) priv->attach = NULL; priv->batch_unref = FALSE; priv->attachments = g_ptr_array_new (); + + priv->recent = gtk_recent_chooser_menu_new (); + gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (priv->recent), TRUE); + gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (priv->recent), GTK_RECENT_SORT_MRU); + gtk_recent_chooser_set_show_not_found (GTK_RECENT_CHOOSER (priv->recent), FALSE); + gtk_recent_chooser_set_show_private (GTK_RECENT_CHOOSER (priv->recent), FALSE); + gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (priv->recent), TRUE); + gtk_recent_chooser_set_show_tips (GTK_RECENT_CHOOSER (priv->recent), TRUE); + priv->path = NULL; bar->priv = priv; @@ -1228,3 +1243,145 @@ e_attachment_bar_attach_mime_part (EAttachmentBar *bar, CamelMimePart *part) add_from_mime_part (bar, part); } + +/* FIXME: Remove this API if nobody uses it */ +void +e_attachment_bar_bonobo_ui_populate_with_recent (BonoboUIComponent *uic, const char *path, + EAttachmentBar *bar, + BonoboUIVerbFn verb_cb, gpointer user_data) +{ + struct _EAttachmentBarPrivate *priv; + GList *items, *l; + gint limit, i; + GString *menuitems; + char *encoded_label, *label; + + g_return_if_fail (E_IS_ATTACHMENT_BAR (bar)); + + priv = bar->priv; + limit = gtk_recent_chooser_get_limit (GTK_RECENT_CHOOSER (priv->recent)); + items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (priv->recent)); + + menuitems = g_string_new ("\n"); + + for (l = g_list_first (items), i = 1; l && i <= limit; l = l->next, ++i) { + GtkRecentInfo *info = ((GtkRecentInfo *)(l->data)); + const gchar *info_dn = gtk_recent_info_get_display_name (info); + char *display_name, *u; + + /* escape _'s in the display name so that it doesn't become an underline in a GtkLabel */ + if ((u = strchr (info_dn, '_'))) { + int extra = 1; + char *d; + const char *s; + + while ((u = strchr (u + 1, '_'))) + extra++; + + d = display_name = g_alloca (strlen (info_dn) + extra + 1); + s = info_dn; + while (*s != '\0') { + if (*s == '_') + *d++ = '_'; + *d++ = *s++; + } + *d = '\0'; + } else + display_name = info_dn; + + /* Add menu item */ + label = g_strdup (display_name); + encoded_label = bonobo_ui_util_encode_str (label); + g_string_append_printf (menuitems, + " \n", + i, encoded_label); + g_free (encoded_label); + g_free (label); + } + + g_string_append (menuitems, "\n"); + + bonobo_ui_component_set (uic, path, menuitems->str, NULL); + + g_string_free (menuitems, TRUE); + + /* Add uri prop */ + for (l = g_list_first (items), i = 1; l && i <= limit; l = l->next, ++i) { + GtkRecentInfo *info = ((GtkRecentInfo *)(l->data)); + const gchar *info_uri = gtk_recent_info_get_uri (info); + label = g_strdup_printf ("/commands/Recent-%d", i); + bonobo_ui_component_set_prop (uic, label, "uri", info_uri, NULL); + g_free (label); + } + + /* Add verb */ + for (l = g_list_first (items), i = 1; l && i <= limit; l = l->next, ++i) { + label = g_strdup_printf ("Recent-%d", i); + bonobo_ui_component_add_verb (uic, label, verb_cb, user_data); + g_free (label); + } + + for (l = g_list_first (items); l; l = l->next) + gtk_recent_info_unref ((GtkRecentInfo *)(l->data)); + g_list_free (items); +} + +static void +action_recent_cb (GtkAction *action, + EAttachmentBar *attachment_bar) +{ + GtkRecentChooser *chooser; + GFile *file; + gchar *uri; + + chooser = GTK_RECENT_CHOOSER (action); + + /* Wish: gtk_recent_chooser_get_current_file() */ + uri = gtk_recent_chooser_get_current_uri (chooser); + file = g_file_new_for_uri (uri); + g_free (uri); + + if (g_file_is_native (file)) + e_attachment_bar_attach ( + E_ATTACHMENT_BAR (attachment_bar), + g_file_get_path (file), "attachment"); + else + e_attachment_bar_attach_remote_file ( + E_ATTACHMENT_BAR (attachment_bar), + g_file_get_uri (file), "attachment"); + + g_object_unref (file); +} + +GtkAction * +e_attachment_bar_recent_action_new (EAttachmentBar *bar, + const gchar *action_name, + const gchar *action_label) +{ + GtkAction *action; + GtkRecentChooser *chooser; + + g_return_val_if_fail (E_IS_ATTACHMENT_BAR (bar), NULL); + + action = gtk_recent_action_new ( + action_name, action_label, NULL, NULL); + gtk_recent_action_set_show_numbers (GTK_RECENT_ACTION (action), TRUE); + + chooser = GTK_RECENT_CHOOSER (action); + gtk_recent_chooser_set_show_icons (chooser, TRUE); + gtk_recent_chooser_set_show_not_found (chooser, FALSE); + gtk_recent_chooser_set_show_private (chooser, FALSE); + gtk_recent_chooser_set_show_tips (chooser, TRUE); + gtk_recent_chooser_set_sort_type (chooser, GTK_RECENT_SORT_MRU); + + g_signal_connect ( + action, "item-activated", + G_CALLBACK (action_recent_cb), bar); + + return action; +} + diff --git a/widgets/misc/e-attachment-bar.h b/widgets/misc/e-attachment-bar.h index 84b1331b3b..ec9e9cc6e4 100644 --- a/widgets/misc/e-attachment-bar.h +++ b/widgets/misc/e-attachment-bar.h @@ -27,6 +27,9 @@ #include +#include +#include + #include #include "e-attachment.h" @@ -83,6 +86,14 @@ GSList *e_attachment_bar_get_selected (EAttachmentBar *bar); void e_attachment_bar_set_width(EAttachmentBar *bar, int bar_width); GSList * e_attachment_bar_get_all_attachments (EAttachmentBar *bar); void e_attachment_bar_create_attachment_cache (EAttachment *attachment); +void +e_attachment_bar_bonobo_ui_populate_with_recent (BonoboUIComponent *uic, const char *path, + EAttachmentBar *bar, + BonoboUIVerbFn verb_cb, gpointer user_data); +GtkAction * +e_attachment_bar_recent_action_new (EAttachmentBar *bar, + const gchar *action_name, + const gchar *action_label); #ifdef __cplusplus } -- cgit v1.2.3