[gnome-system-monitor] proctable: handle selection smartly when opening context menu



commit e3a428581046f27e3875da7d59193d98415db047
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Wed Aug 14 11:08:45 2013 +0200

    proctable: handle selection smartly when opening context menu
    
    When the context menu is triggered by a mouse event, check the row
    under the cursor: if it is not already part of the selection, select it
    and deselect everything else.
    
    This is the most common behavior, used for instance by Nautilus etc.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705970

 src/proctable.cpp |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/src/proctable.cpp b/src/proctable.cpp
index aac39c4..aae0acb 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -99,15 +99,26 @@ static gboolean
 cb_tree_button_pressed (GtkWidget *widget, GdkEventButton *event, gpointer data)
 {
     GsmApplication *app = (GsmApplication *) data;
+    GtkTreePath *path;
 
-    if (gdk_event_triggers_context_menu ((GdkEvent *) event)) {
-        gtk_menu_popup (GTK_MENU (app->popup_menu),
-                        NULL, NULL, NULL, NULL,
-                        event->button, event->time);
-        return TRUE;
+    if (!gdk_event_triggers_context_menu ((GdkEvent *) event))
+        return FALSE;
+
+    if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (app->tree), event->x, event->y, &path, NULL, NULL, 
NULL))
+        return FALSE;
+
+    if (!gtk_tree_selection_path_is_selected (app->selection, path)) {
+        if (!(event->state & GDK_CONTROL_MASK))
+            gtk_tree_selection_unselect_all (app->selection);
+        gtk_tree_selection_select_path (app->selection, path);
     }
 
-    return FALSE;
+    gtk_tree_path_free (path);
+
+    gtk_menu_popup (GTK_MENU (app->popup_menu),
+                    NULL, NULL, NULL, NULL,
+                    event->button, event->time);
+    return TRUE;
 }
 
 static gboolean


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