PATCH: add MRU to index context menu
- From: "M . Thielker" <balsa t-data com>
- To: Balsa List <balsa-list gnome org>
- Subject: PATCH: add MRU to index context menu
- Date: Thu, 16 Aug 2001 20:38:23 +0200
Hi,
this little patch will add the same MRU functionality to the index's
context menu as well. To unify terminology, the menu title in the message
window is now named "Move", as is the context menu option (formerly
"Transfer").
This patch must be applied on top of balsa-filing.patch.
Melanie
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/src/balsa-index.c ./src/balsa-index.c
--- ../balsa-cvs/src/balsa-index.c Thu Aug 16 19:22:17 2001
+++ ./src/balsa-index.c Thu Aug 16 20:32:47 2001
@@ -58,6 +58,16 @@
#define DO_CLIST_WORKAROUND(s)
#endif
+struct FolderMRUEntry
+{
+ gchar *name;
+ gchar *url;
+ LibBalsaMailbox *mailbox;
+ BalsaIndex *bindex;
+};
+
+static GList *mru_list=NULL;
+
/* gtk widget */
static void balsa_index_class_init(BalsaIndexClass * klass);
static void balsa_index_init(BalsaIndex * bindex);
@@ -75,6 +85,7 @@
/* statics */
static void balsa_index_set_col_images(BalsaIndex *, GtkCTreeNode*,
LibBalsaMessage *);
+static void populate_mru(GtkWidget *menu, BalsaIndex *bindex);
/* mailbox callbacks */
static void balsa_index_del (BalsaIndex * bindex, LibBalsaMessage * message);
@@ -104,6 +115,9 @@
static void resize_column_event_cb(GtkCList * clist, gint column,
gint width, gpointer data);
+/* Callbacks */
+static gint mru_search_cb(GNode *node, struct FolderMRUEntry *entry);
+static void mru_select_cb(GtkWidget *widget, struct FolderMRUEntry *entry);
/* formerly balsa-index-page stuff */
enum {
@@ -1882,10 +1896,11 @@
static GtkWidget *
create_menu(BalsaIndex * bindex)
{
- GtkWidget *menu, *menuitem, *submenu, *smenuitem;
+ GtkWidget *menu, *menuitem, *submenu, *smenuitem, *mrumenu, *mruitem;
GtkWidget *bmbl, *scroll;
GtkRequisition req;
LibBalsaMailbox* mailbox;
+ GList *tmp;
BALSA_DEBUG();
@@ -1942,9 +1957,29 @@
gtk_menu_append(GTK_MENU(menu), menuitem);
- menuitem = gtk_menu_item_new_with_label(_("Transfer"));
+ for(tmp=mru_list;tmp != NULL;tmp=g_list_next(tmp))
+ g_free(tmp->data);
+ g_list_free(mru_list);
+ mru_list=NULL;
+
+ menuitem = gtk_menu_item_new_with_label(_("Move"));
gtk_widget_set_sensitive(menuitem, !mailbox->readonly);
+ gtk_menu_append(GTK_MENU(menu), menuitem);
+ gtk_widget_show(menuitem);
+
+ mrumenu = gtk_menu_new();
+ gtk_widget_show(mrumenu);
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), mrumenu);
+
+ populate_mru(mrumenu, bindex);
+
+ mruitem = gtk_menu_item_new_with_label(_("Folder"));
+ gtk_widget_show(mruitem);
+
+ gtk_menu_append(GTK_MENU(mrumenu), mruitem);
+
submenu = gtk_menu_new();
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(mruitem), submenu);
smenuitem = gtk_menu_item_new();
gtk_signal_connect (GTK_OBJECT(smenuitem), "button_release_event",
@@ -1978,9 +2013,6 @@
gtk_widget_show(scroll);
gtk_widget_show(smenuitem);
- gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
- gtk_menu_append(GTK_MENU(menu), menuitem);
- gtk_widget_show(menuitem);
return menu;
}
@@ -2268,5 +2300,122 @@
j++;
}
}
+}
+
+static gint
+mru_search_cb(GNode *gnode, struct FolderMRUEntry *entry)
+{
+ BalsaMailboxNode *node;
+
+ node=gnode->data;
+ if(!node || !BALSA_IS_MAILBOX_NODE(node))
+ return(FALSE);
+
+ if(!node->mailbox)
+ return(FALSE);
+
+ if(!strcmp(LIBBALSA_MAILBOX(node->mailbox)->url, entry->url)) {
+ entry->url=LIBBALSA_MAILBOX(node->mailbox)->url;
+ entry->name=LIBBALSA_MAILBOX(node->mailbox)->name;
+ entry->mailbox=LIBBALSA_MAILBOX(node->mailbox);
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+static void
+populate_mru(GtkWidget *menu, BalsaIndex *bindex)
+{
+ struct FolderMRUEntry *mru_entry;
+ GList *mru, *tmp;
+ GtkWidget *item;
+
+ for(mru=balsa_app.folder_mru;mru != NULL;mru=g_list_next(mru)) {
+ while(mru) {
+ mru_entry=g_malloc(sizeof(struct FolderMRUEntry));
+ if(!mru_entry)
+ return;
+
+ mru_entry->url=mru->data;
+ mru_entry->mailbox=NULL;
+ mru_entry->bindex=bindex;
+ g_node_traverse(balsa_app.mailbox_nodes, G_IN_ORDER, G_TRAVERSE_ALL,
+ -1, (gint (*)(GNode *, gpointer))mru_search_cb, mru_entry);
+ if(mru_entry->mailbox == NULL) {
+ g_free(mru_entry);
+ tmp=g_list_next(mru);
+ g_free(mru->data);
+ balsa_app.folder_mru=g_list_remove(balsa_app.folder_mru,
+ mru->data);
+ mru=tmp;
+ continue;
+ }
+ break;
+ }
+
+ if(!mru)
+ break;
+
+ mru_list=g_list_append(mru_list, mru_entry);
+ item=gtk_menu_item_new_with_label(mru_entry->name);
+ gtk_widget_show(item);
+ gtk_menu_append(GTK_MENU(menu), item);
+ gtk_signal_connect(GTK_OBJECT(item), "activate",
+ GTK_SIGNAL_FUNC(mru_select_cb), mru_entry);
+ }
+}
+
+static void
+mru_select_cb(GtkWidget *widget, struct FolderMRUEntry *entry)
+{
+ GtkCList* clist;
+ BalsaIndex* bindex = NULL;
+ GList *list, *messages;
+ LibBalsaMessage* message;
+ gboolean select_next = TRUE;
+ gint message_count = 0;
+
+ g_return_if_fail(entry != NULL);
+
+ bindex = entry->bindex;
+ clist = GTK_CLIST(bindex->ctree);
+
+ /*Transferring to same mailbox? */
+ if (bindex->mailbox_node->mailbox == entry->mailbox)
+ return;
+
+ /* select the previous message if we're at the bottom of the index */
+ if (clist->rows - 1 == balsa_index_get_largest_selected(clist))
+ select_next = FALSE;
+
+
+ messages=NULL;
+ for (list = clist->selection; list;list = list->next) {
+ message = gtk_ctree_node_get_row_data(GTK_CTREE(bindex->ctree),
+ list->data);
+ messages=g_list_append(messages, message);
+ ++message_count;
+ }
+
+ if(messages!=NULL) {
+ libbalsa_messages_move(messages, entry->mailbox);
+ g_list_free(messages);
+ }
+
+ /* select another message depending on where we are in the list */
+ if (clist->rows > message_count) {
+ if (select_next)
+ balsa_index_select_next(bindex);
+ else
+ balsa_index_select_previous(bindex);
+ }
+
+
+ libbalsa_mailbox_sync_backend(bindex->mailbox_node->mailbox);
+
+ balsa_remove_from_folder_mru(entry->mailbox->url);
+ balsa_add_to_folder_mru(entry->mailbox->url);
+ gtk_object_set_data(GTK_OBJECT(bindex), "transferredp", (gpointer) 1);
}
diff -b -B -r -u -P --exclude-from=ignore ../balsa-cvs/src/message-window.c ./src/message-window.c
--- ../balsa-cvs/src/message-window.c Thu Aug 16 19:22:17 2001
+++ ./src/message-window.c Thu Aug 16 20:03:12 2001
@@ -162,7 +162,7 @@
GNOMEUIINFO_MENU_EDIT_TREE(edit_menu),
GNOMEUIINFO_MENU_VIEW_TREE(view_menu),
#define MAIN_MENU_MOVE_POS 3
- GNOMEUIINFO_SUBTREE("Move _To", move_menu),
+ GNOMEUIINFO_SUBTREE("M_ove To", move_menu),
GNOMEUIINFO_SUBTREE("_Message", message_menu),
GNOMEUIINFO_END
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]