From e0ad96c18c2eaafac5d70ac4342db5a1b0bac448 Mon Sep 17 00:00:00 2001 From: Omari Stephens Date: Sun, 9 Jul 2017 21:25:23 +0000 Subject: [PATCH] Adds cluster support to view_file_list. Note: behavior with sidecars is untested. --- src/filecluster.c | 10 +++-- src/view_file/view_file_list.c | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/filecluster.c b/src/filecluster.c index 2b7ebccb..e8f6252c 100644 --- a/src/filecluster.c +++ b/src/filecluster.c @@ -124,22 +124,24 @@ gboolean fileclusterlist_has_head(FileClusterList *fcl, FileData *fd) { FileCluster *fc = g_hash_table_lookup(fcl->clusters, fd); if (!fc) return FALSE; - return fc->head->data == fd; + return filecluster_fd_equal(fc->head->data, fd); } gboolean fileclusterlist_has_child(FileClusterList *fcl, FileData *fd) { FileCluster *fc = g_hash_table_lookup(fcl->clusters, fd); if (!fc) return FALSE; - return fc->head->data != fd; + return !filecluster_fd_equal(fc->head->data, fd); } static gboolean fileclusterlist_should_hide(FileClusterList *fcl, FileData *fd) { FileCluster *fc = g_hash_table_lookup(fcl->clusters, fd); if (!fc) return FALSE; - if (fc->show_children) return FALSE; // TODO(xsdg): new function "should_show" - return fc->head->data != 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); } // TODO(xsdg): pick a better name for this function diff --git a/src/view_file/view_file_list.c b/src/view_file/view_file_list.c index 86cb6123..c65fd899 100644 --- a/src/view_file/view_file_list.c +++ b/src/view_file/view_file_list.c @@ -498,6 +498,77 @@ gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat ViewFile *vf = data; GtkTreePath *tpath; + // DO NOT SUBMIT + // TODO(xsdg): these key combos should be handled by the standard, configurable mechanism. + + if (event->keyval == GDK_KEY_Insert || event->keyval == GDK_KEY_F2) + { + // First off, get the selected FDs + GList *selected_fds = NULL; + { + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview)); + if (event->keyval == GDK_KEY_Insert) + { + if (gtk_tree_selection_count_selected_rows(selection) < 2) + { + g_warning("Need at least two items selected to create a cluster."); + return TRUE; + } + } + else + { + if (gtk_tree_selection_count_selected_rows(selection) < 1) + { + g_warning("Must have a node selected to flip show_children."); + return TRUE; + } + } + + // List of GtkTreePath + GList *selected_rows = gtk_tree_selection_get_selected_rows(selection, NULL); + GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)); + GtkTreeIter iter; + for (GList *work = selected_rows; work; work = work->next) + { + FileData *fd; + GtkTreePath *select_path = work->data; + gtk_tree_model_get_iter(store, &iter, select_path); + gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); + selected_fds = g_list_prepend(selected_fds, file_data_ref(fd)); + } + + selected_fds = g_list_reverse(selected_fds); + g_list_free_full(selected_rows, (GDestroyNotify)gtk_tree_path_free); + } + + if (event->keyval == GDK_KEY_Insert) + { + g_warning("Starting a cluster!"); + FileCluster *fc = fileclusterlist_create_cluster(vf->cluster_list, selected_fds); + if (fc) + { + // TODO(xsdg): mark as in a cluster somehow? + vf_refresh(vf); + } + } + else if (event->keyval == GDK_KEY_F2) + { + FileData *fd = selected_fds->data; + if (fd) + { + g_warning("Flipping show_children!"); + FileCluster *fc = g_hash_table_lookup(vf->cluster_list->clusters, fd); + if (fc) + { + filecluster_toggle_show_children(fc); + vf_refresh(vf); + } + } + } + + return TRUE; // Handled event; stop propagating. + } + if (event->keyval != GDK_KEY_Menu) return FALSE; gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &tpath, NULL); -- 2.20.1