[gnome-system-monitor] Add a context menu to the disks and processes table header right click to easily show/hide columns.



commit e5fcf7324f43c60553f4daff1fdee9b60eb999e8
Author: Robert Roth <robert roth off gmail com>
Date:   Mon Feb 11 00:37:47 2013 +0200

    Add a context menu to the disks and processes table header
    right click to easily show/hide columns.
    https://bugzilla.gnome.org/show_bug.cgi?id=142026

 src/callbacks.cpp   |   28 ++++++++++++++++++++++++++++
 src/callbacks.h     |    4 ++++
 src/disks.cpp       |    4 ++--
 src/procman-app.cpp |   47 ++++++++++++++++++++++++++++++++++++++++-------
 src/proctable.cpp   |    5 +----
 5 files changed, 75 insertions(+), 13 deletions(-)
---
diff --git a/src/callbacks.cpp b/src/callbacks.cpp
index 4313112..cbd326a 100644
--- a/src/callbacks.cpp
+++ b/src/callbacks.cpp
@@ -509,3 +509,31 @@ cb_column_resized(GtkWidget *widget, GParamSpec* param, gpointer data)
     }
     g_free (key);
 }
+
+
+static void
+cb_header_menu_position_function(GtkMenu* menu, gint *x, gint *y, gboolean *push_in, gpointer data)
+{
+    GdkEventButton* event = static_cast<GdkEventButton*>(data);
+    gint wx, wy, ww, wh;
+    gdk_window_get_geometry(event->window, &wx, &wy, &ww, &wh);
+    gdk_window_get_origin(event->window, &wx, &wy);
+    
+    *x = wx + event->x;
+    *y = wy + wh;
+    *push_in = TRUE;
+}
+
+gboolean
+cb_column_header_clicked (GtkTreeViewColumn* column, GdkEvent* event, gpointer data)
+{
+    GtkMenu *menu = static_cast<GtkMenu*>(data);
+    if (event->button.button == GDK_BUTTON_SECONDARY) {
+        gtk_menu_popup(GTK_MENU(menu), NULL, NULL, cb_header_menu_position_function, &(event->button), event->button.button, event->button.time);
+        return TRUE;
+    }
+
+    return FALSE;
+    
+}
+
diff --git a/src/callbacks.h b/src/callbacks.h
index bbb6463..3b80013 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -79,4 +79,8 @@ void            cb_kill_sigstop(GtkAction *action,
 void            cb_kill_sigcont(GtkAction *action,
                                 gpointer data);
 
+gboolean        cb_column_header_clicked (GtkTreeViewColumn* column, 
+                                          GdkEvent* event, 
+                                          gpointer data);
+
 #endif /* _PROCMAN_CALLBACKS_H_ */
diff --git a/src/disks.cpp b/src/disks.cpp
index 1735aff..939ca39 100644
--- a/src/disks.cpp
+++ b/src/disks.cpp
@@ -325,7 +325,7 @@ create_disk_view(ProcmanApp *app, GtkBuilder *builder)
                                GDK_TYPE_PIXBUF,     /* DISK_ICON */
                                G_TYPE_INT           /* DISK_USED_PERCENTAGE */
         );
-
+    
     disk_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
     g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL);
     app->disk_list = disk_tree;
@@ -353,6 +353,7 @@ create_disk_view(ProcmanApp *app, GtkBuilder *builder)
     gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
     gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
 
+
     /* sizes - used */
 
     for (i = DISK_DIR; i <= DISK_AVAIL; i++) {
@@ -366,7 +367,6 @@ create_disk_view(ProcmanApp *app, GtkBuilder *builder)
         gtk_tree_view_column_set_reorderable(col, TRUE);
         gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
         gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col);
-
         switch (i) {
             case DISK_TOTAL:
             case DISK_FREE:
diff --git a/src/procman-app.cpp b/src/procman-app.cpp
index 3cbbe4f..2aa1de4 100644
--- a/src/procman-app.cpp
+++ b/src/procman-app.cpp
@@ -12,6 +12,7 @@
 #include "settings-keys.h"
 #include "argv.h"
 #include "util.h"
+#include "cgroups.h"
 
 static void
 mount_changed(const Glib::RefPtr<Gio::Mount>&, ProcmanApp *app)
@@ -388,7 +389,8 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child
     GList *columns, *it;
     gint sort_col;
     GtkSortType order;
-
+    GtkWidget *header_menu;
+   
     g_assert(tree);
     g_assert(child_schema);
 
@@ -410,13 +412,18 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child
     if(!g_strcmp0(child_schema, "proctree") ||
        !g_strcmp0(child_schema, "disktreenew"))
     {
+        header_menu = gtk_menu_new();
+        
         for(it = columns; it; it = it->next)
         {
             GtkTreeViewColumn *column;
             gint width;
             gboolean visible;
             int id;
+            const gchar *title;
             gchar *key;
+            GtkWidget* column_item;
+            GtkWidget* button;
 
             column = static_cast<GtkTreeViewColumn*>(it->data);
             id = gtk_tree_view_column_get_sort_column_id (column);
@@ -432,13 +439,39 @@ procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *child
             column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree), id);
             if(!column) continue;
             gtk_tree_view_column_set_visible (column, visible);
-            if (visible) {
-                /* ensure column is really visible */
-                width = MAX(width, 10);
-                gtk_tree_view_column_set_fixed_width(column, width);
-            }
+            /* ensure column is really visible */
+            width = MAX(width, 50);
+            gtk_tree_view_column_set_fixed_width(column, width);
+
+            if ((id == COL_CGROUP) && (!cgroups_enabled()))
+                continue;
+
+            if ((id == COL_UNIT ||
+                id == COL_SESSION ||
+                id == COL_SEAT ||
+                id == COL_OWNER)
+#ifdef HAVE_SYSTEMD
+                && sd_booted() <= 0
+#endif
+                )
+                continue;
+            // set the states for the columns visibility menu available by header right click
+            title = gtk_tree_view_column_get_title (column);
+
+            if (!title)
+                title = _("Icon");
+            button = gtk_tree_view_column_get_button(column);
+            g_signal_connect(G_OBJECT(button), "button_press_event", G_CALLBACK(cb_column_header_clicked), header_menu);
+
+            key = g_strdup_printf ("col-%d-visible", id);
+            column_item = gtk_check_menu_item_new_with_label(title);
+            g_settings_bind(pt_settings, key, G_OBJECT(column_item), "active", G_SETTINGS_BIND_DEFAULT);
+            g_settings_bind(pt_settings, key, G_OBJECT(column), "visible", G_SETTINGS_BIND_DEFAULT);
+            g_free (key);
+
+            gtk_menu_shell_append(GTK_MENU_SHELL(header_menu), column_item);
         }
-        
+        gtk_widget_show_all(header_menu);
         GVariant     *value;
         GVariantIter iter;
         int          sortIndex;
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 3306034..b95654d 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -302,6 +302,7 @@ proctable_new (ProcmanApp * const app)
                                          "text", COL_NAME,
                                          NULL);
     gtk_tree_view_column_set_title (column, _(titles[0]));
+
     gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
     gtk_tree_view_column_set_resizable (column, TRUE);
     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
@@ -310,7 +311,6 @@ proctable_new (ProcmanApp * const app)
     gtk_tree_view_append_column (GTK_TREE_VIEW (proctree), column);
     gtk_tree_view_set_expander_column (GTK_TREE_VIEW (proctree), column);
 
-
     for (i = COL_USER; i <= COL_PRIORITY; i++) {
 
         GtkCellRenderer *cell;
@@ -325,7 +325,6 @@ proctable_new (ProcmanApp * const app)
         g_signal_connect(G_OBJECT(col), "notify::width", G_CALLBACK(cb_column_resized), settings);
         gtk_tree_view_column_set_reorderable(col, TRUE);
         gtk_tree_view_append_column(GTK_TREE_VIEW(proctree), col);
-
         // type
         switch (i) {
             case COL_MEMXSERVER:
@@ -428,12 +427,10 @@ proctable_new (ProcmanApp * const app)
                 break;
         }
     }
-
     app->tree = proctree;
     set_proctree_reorderable(app);
 
     procman_get_tree_state (app->settings, proctree, "proctree");
-
     /* Override column settings by hiding this column if it's meaningless: */
     if (!can_show_security_context_column ()) {
         GtkTreeViewColumn *column;


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