diff options
author | monsta <[email protected]> | 2016-03-02 14:44:15 +0300 |
---|---|---|
committer | monsta <[email protected]> | 2016-03-02 14:49:11 +0300 |
commit | e44f2e847ddb5db5b6944f6c2f993981adbd3ad4 (patch) | |
tree | 871df644b8dbd6d4861d42421e1b03790ff3c490 /src/disks.cpp | |
parent | 2e5e07b81f18fa4b3cfa8dfdbb08d716d58845ce (diff) | |
download | mate-system-monitor-e44f2e847ddb5db5b6944f6c2f993981adbd3ad4.tar.bz2 mate-system-monitor-e44f2e847ddb5db5b6944f6c2f993981adbd3ad4.tar.xz |
disks: implement saving and loading width and visibility of columns
adapted from
https://git.gnome.org/browse/gnome-system-monitor/commit/?id=f589439a966151b2589bca21a4d6b40455eb201a
with necessary changes from https://github.com/mate-desktop/mate-system-monitor/commit/eebc190a5aeb6ebaf5c3a868b68434679adddc74
Diffstat (limited to 'src/disks.cpp')
-rw-r--r-- | src/disks.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/disks.cpp b/src/disks.cpp index 2431727..302098a 100644 --- a/src/disks.cpp +++ b/src/disks.cpp @@ -285,6 +285,44 @@ open_dir(GtkTreeView *tree_view, g_free(dir); } +static guint timeout_id = 0; +static GtkTreeViewColumn *current_column; + +static gboolean +save_column_width (gpointer data) +{ + gint width; + gchar *key; + int id; + GSettings *settings; + + settings = g_settings_get_child (G_SETTINGS (data), "disktreenew"); + id = gtk_tree_view_column_get_sort_column_id (current_column); + width = gtk_tree_view_column_get_width (current_column); + + key = g_strdup_printf ("col-%d-width", id); + g_settings_set_int(settings, key, width); + g_free (key); + + if (timeout_id) { + g_source_remove (timeout_id); + timeout_id = 0; + } + + return FALSE; +} + +static void +cb_disks_column_resized(GtkWidget *widget, GParamSpec *pspec, gpointer data) +{ + current_column = GTK_TREE_VIEW_COLUMN(widget); + + if (timeout_id) + g_source_remove (timeout_id); + + timeout_id = g_timeout_add (250, save_column_width, data); +} + GtkWidget * create_disk_view(ProcData *procdata) { @@ -355,6 +393,7 @@ create_disk_view(ProcData *procdata) gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_min_width (col, 30); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); + g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings); gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col); /* sizes - used */ @@ -369,6 +408,7 @@ create_disk_view(ProcData *procdata) gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_min_width (col, 30); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); + g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings); gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col); switch (i) { @@ -411,6 +451,7 @@ create_disk_view(ProcData *procdata) gtk_tree_view_column_set_resizable(col, TRUE); gtk_tree_view_column_set_min_width (col, 150); gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED); + g_signal_connect(G_OBJECT(col), "notify::fixed-width", G_CALLBACK(cb_disks_column_resized), procdata->settings); gtk_tree_view_append_column(GTK_TREE_VIEW(disk_tree), col); /* numeric sort */ |