From 78974969df4549558a3eed99aa00363575ca6247 Mon Sep 17 00:00:00 2001 From: Omari Stephens Date: Mon, 10 Jul 2017 07:36:47 +0000 Subject: [PATCH] Colorify cluster elements --- src/filecluster.c | 18 ++++++++++++--- src/filecluster.h | 11 +++++++-- src/view_file/view_file_list.c | 42 +++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/filecluster.c b/src/filecluster.c index e8f6252c..36e5b4f5 100644 --- a/src/filecluster.c +++ b/src/filecluster.c @@ -120,18 +120,30 @@ FileCluster *fileclusterlist_create_cluster(FileClusterList *fcl, GList *fd_item return new_fc; } +gboolean filecluster_has_head(FileCluster *fc, FileData *fd) +{ + if (!fd) return FALSE; + return filecluster_fd_equal(fc->head->data, fd); +} + +gboolean filecluster_has_child(FileCluster *fc, FileData *fd) +{ + if (!fd) return FALSE; + return !filecluster_fd_equal(fc->head->data, fd); +} + gboolean fileclusterlist_has_head(FileClusterList *fcl, FileData *fd) { FileCluster *fc = g_hash_table_lookup(fcl->clusters, fd); if (!fc) return FALSE; - return filecluster_fd_equal(fc->head->data, fd); + return filecluster_has_head(fc, fd); } gboolean fileclusterlist_has_child(FileClusterList *fcl, FileData *fd) { FileCluster *fc = g_hash_table_lookup(fcl->clusters, fd); if (!fc) return FALSE; - return !filecluster_fd_equal(fc->head->data, fd); + return filecluster_has_child(fc, fd); } static gboolean fileclusterlist_should_hide(FileClusterList *fcl, FileData *fd) @@ -141,7 +153,7 @@ static gboolean fileclusterlist_should_hide(FileClusterList *fcl, FileData *fd) // Only difference vs. fileclusterlist_has_child. Basically, if the node is a child, but // we're showing children, then don't hide. if (fc->show_children) return FALSE; - return !filecluster_fd_equal(fc->head->data, fd); + return filecluster_has_child(fc, fd); } // TODO(xsdg): pick a better name for this function diff --git a/src/filecluster.h b/src/filecluster.h index 660f5ebc..9351e1c3 100644 --- a/src/filecluster.h +++ b/src/filecluster.h @@ -21,12 +21,19 @@ #include "main.h" -FileClusterList *fileclusterlist_new(); +// FileCluster methods. FileCluster *filecluster_new(); // internal? -void fileclusterlist_free(FileClusterList *fcl); void filecluster_free(FileCluster *fc); gboolean filecluster_toggle_show_children(FileCluster *fc); +gboolean filecluster_has_head(FileCluster *fc, FileData *fd); +gboolean filecluster_has_child(FileCluster *fc, FileData *fd); + + +// FileClusterList methods. + +FileClusterList *fileclusterlist_new(); +void fileclusterlist_free(FileClusterList *fcl); // Creates a cluster with items that must already be in the cluster list. Will fail (and make no // changes) if any of the specified items isn't in the list, or if any of the items is already diff --git a/src/view_file/view_file_list.c b/src/view_file/view_file_list.c index c65fd899..5e02c398 100644 --- a/src/view_file/view_file_list.c +++ b/src/view_file/view_file_list.c @@ -981,9 +981,14 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr else { if (parent_iter) - match = filelist_sort_compare_filedata_full(fd, old_fd, SORT_NAME, TRUE); /* always sort sidecars by name */ + { + /* always sort sidecars by name */ + match = filelist_sort_compare_filedata_full(fd, old_fd, SORT_NAME, TRUE); + } else + { match = filelist_sort_compare_filedata_full(fd, old_fd, vf->sort_method, vf->sort_ascend); + } if (match == 0) g_warning("multiple fd for the same path"); } @@ -1802,8 +1807,43 @@ static void vflist_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRend { ViewFile *vf = data; gboolean set; + FileData *fd; gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1); + gtk_tree_model_get(tree_model, iter, FILE_COLUMN_POINTER, &fd, -1); + // TODO(xsdg): optimize! + if (fd) + { + FileCluster *fc = g_hash_table_lookup(vf->cluster_list->clusters, fd); + if (fc) + { + if (filecluster_has_head(fc, fd)) + { + GdkColor *color_bg = g_new0(GdkColor, 1); + color_bg->blue = 0x4000; + color_bg->green = 0x4000; + color_bg->red = 0xFFFF; + + g_object_set(G_OBJECT(cell), + "cell-background-gdk", color_bg, + "cell-background-set", TRUE, NULL); + return; + } + else if (filecluster_has_child(fc, fd)) + { + GdkColor *color_bg = g_new0(GdkColor, 1); + color_bg->blue = 0x8000; + color_bg->green = 0x8000; + color_bg->red = 0xFFFF; + + g_object_set(G_OBJECT(cell), + "cell-background-gdk", color_bg, + "cell-background-set", TRUE, NULL); + return; + } + } + } + g_object_set(G_OBJECT(cell), "cell-background-gdk", vflist_listview_color_shifted(vf->listview), "cell-background-set", set, NULL); -- 2.20.1