Colorify cluster elements
authorOmari Stephens <xsdg@google.com>
Mon, 10 Jul 2017 07:36:47 +0000 (07:36 +0000)
committerOmari Stephens <xsdg@google.com>
Mon, 10 Jul 2017 08:00:55 +0000 (08:00 +0000)
src/filecluster.c
src/filecluster.h
src/view_file/view_file_list.c

index e8f6252..36e5b4f 100644 (file)
@@ -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
index 660f5eb..9351e1c 100644 (file)
 
 #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
index c65fd89..5e02c39 100644 (file)
@@ -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);