[PATCH] Re: [Q]



Patch(es) attached to implement the following, which I believe
represents the consensus:

        /* pop up the context menu:
         * - if the clicked-on message is already selected, don't change
         *   the selection;
         * - if it isn't, select it (cancelling any previous selection)
         * - create and show the menu only if some message is selected,
         *   at the end of all this */

Note that if there's nothing to work on, the menu isn't shown at all
(which is easy), rather than being shown greyed out (which seems to be
harder, unless I'm missing something).  I believe that's a reasonable
(in)action, and arguably preferable.

Both patches are against current cvs.  The first makes minimal changes;
the second reorganizes button_event_press_cb to read more like:

...
if (button == 1)
    ...
else if (button == 3)
    ...

Comments and suggestions welcome, as always!
diff -dNru --exclude-from=excl balsa-cvs/src/balsa-index.c balsa-context/src/balsa-index.c
--- balsa-cvs/src/balsa-index.c	Tue Nov  6 07:47:54 2001
+++ balsa-context/src/balsa-index.c	Sun Nov 11 15:27:54 2001
@@ -1249,30 +1249,46 @@
 button_event_press_cb(GtkWidget * ctree, GdkEventButton * event, gpointer data)
 {
     gint row, column;
-    gint on_message;
-    LibBalsaMessage *message;
+    LibBalsaMessage *message = NULL;
     BalsaIndex *bindex;
     GtkCList* clist = GTK_CLIST (ctree);
 
     g_return_if_fail(event);
+    if (clist->rows <= 0)
+        return;
 
     bindex = BALSA_INDEX(data);
+    if (gtk_clist_get_selection_info(clist, event->x, event->y,
+                                     &row, &column))
+        message = gtk_clist_get_row_data(clist, row);
+    
     if (event->button == 3) {
+        /* pop up the context menu:
+         * - if the clicked-on message is already selected, don't change
+         *   the selection;
+         * - if it isn't, select it (cancelling any previous selection)
+         * - create and show the menu only if some message is selected,
+         *   at the end of all this */
+
         balsa_index_idle_remove(bindex);
 
-	gtk_menu_popup(GTK_MENU(create_menu(bindex)),
-		       NULL, NULL, NULL, NULL,
-		       event->button, event->time);
-        return;
-    } 
+        if (message) {
+            /* select this message, if it's not already selected */
+            GtkCTreeNode *node =
+                gtk_ctree_find_by_row_data(GTK_CTREE(ctree), NULL,
+                                           message);
+            if (!g_list_find(clist->selection, node))
+                balsa_index_select_row(bindex, row);
+        }
 
-    on_message = gtk_clist_get_selection_info(clist, event->x, event->y, 
-                                              &row, &column);
+        if (clist->selection)
+            gtk_menu_popup(GTK_MENU(create_menu(bindex)),
+                           NULL, NULL, NULL, NULL,
+                           event->button, event->time);
+        return;
+    }
 
-    g_return_if_fail(on_message == 0 || on_message == 1);
-    /* Keep the cast: I have got a strange crash here */
-    if (on_message && 
-	(message = (LibBalsaMessage*)gtk_clist_get_row_data(clist, row))) {
+    if (message) {
 	if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) {
             /* double click on a message means open a message window,
              * unless we're in the draftbox, in which case it means open
diff -dNru --exclude-from=excl balsa-cvs/src/balsa-index.c balsa-context/src/balsa-index.c
--- balsa-cvs/src/balsa-index.c	Tue Nov  6 07:47:54 2001
+++ balsa-context/src/balsa-index.c	Sun Nov 11 15:35:25 2001
@@ -1246,54 +1246,66 @@
 /* CLIST callbacks */
 
 static void
-button_event_press_cb(GtkWidget * ctree, GdkEventButton * event, gpointer data)
+button_event_press_cb(GtkWidget * ctree, GdkEventButton * event,
+                      gpointer data)
 {
     gint row, column;
-    gint on_message;
-    LibBalsaMessage *message;
+    LibBalsaMessage *message = NULL;
     BalsaIndex *bindex;
-    GtkCList* clist = GTK_CLIST (ctree);
+    GtkCList *clist = GTK_CLIST(ctree);
 
     g_return_if_fail(event);
+    if (clist->rows <= 0)
+        return;
 
     bindex = BALSA_INDEX(data);
-    if (event->button == 3) {
-        balsa_index_idle_remove(bindex);
+    if (gtk_clist_get_selection_info(clist, event->x, event->y,
+                                     &row, &column))
+        message = gtk_clist_get_row_data(clist, row);
 
-	gtk_menu_popup(GTK_MENU(create_menu(bindex)),
-		       NULL, NULL, NULL, NULL,
-		       event->button, event->time);
-        return;
-    } 
+    if (event->button == 1 && event->type == GDK_2BUTTON_PRESS && message) {
+        /* double click on a message means open a message window,
+         * unless we're in the draftbox, in which case it means open
+         * a sendmsg window */
+        if (bindex->mailbox_node->mailbox == balsa_app.draftbox) {
+            /* the simplest way to get a sendmsg window would be:
+             * balsa_message_continue(widget, (gpointer) bindex);
+             * but it doesn't work--the selection info seems to
+             * become invisible
+             *
+             * instead we'll just use the guts of
+             * balsa_message_continue: */
+            BalsaSendmsg *sm =
+                sendmsg_window_new(GTK_WIDGET(balsa_app.main_window),
+                                   message, SEND_CONTINUE);
+            gtk_signal_connect(GTK_OBJECT(sm->window), "destroy",
+                               GTK_SIGNAL_FUNC
+                               (sendmsg_window_destroy_cb), NULL);
+        } else
+            message_window_new(message);
+    } else if (event->button == 3) {
+        /* pop up the context menu:
+         * - if the clicked-on message is already selected, don't change
+         *   the selection;
+         * - if it isn't, select it (cancelling any previous selection)
+         * - create and show the menu only if some message is selected,
+         *   at the end of all this */
 
-    on_message = gtk_clist_get_selection_info(clist, event->x, event->y, 
-                                              &row, &column);
+        balsa_index_idle_remove(bindex);
 
-    g_return_if_fail(on_message == 0 || on_message == 1);
-    /* Keep the cast: I have got a strange crash here */
-    if (on_message && 
-	(message = (LibBalsaMessage*)gtk_clist_get_row_data(clist, row))) {
-	if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) {
-            /* double click on a message means open a message window,
-             * unless we're in the draftbox, in which case it means open
-             * a sendmsg window */
-            if (bindex->mailbox_node->mailbox == balsa_app.draftbox) {
-                /* the simplest way to get a sendmsg window would be:
-                 * balsa_message_continue(widget, (gpointer) bindex);
-                 * but it doesn't work--the selection info seems to
-                 * become invisible
-                 *
-                 * instead we'll just use the guts of
-                 * balsa_message_continue: */
-                BalsaSendmsg *sm =
-                    sendmsg_window_new(GTK_WIDGET(balsa_app.main_window), 
-                                       message, SEND_CONTINUE);
-                gtk_signal_connect(GTK_OBJECT(sm->window), "destroy",
-                                   GTK_SIGNAL_FUNC
-                                   (sendmsg_window_destroy_cb), NULL);
-            } else
-                message_window_new (message);
+        if (message) {
+            /* select this message, if it's not already selected */
+            GtkCTreeNode *node =
+                gtk_ctree_find_by_row_data(GTK_CTREE(ctree), NULL,
+                                           message);
+            if (!g_list_find(clist->selection, node))
+                balsa_index_select_row(bindex, row);
         }
+
+        if (clist->selection)
+            gtk_menu_popup(GTK_MENU(create_menu(bindex)),
+                           NULL, NULL, NULL, NULL,
+                           event->button, event->time);
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]