- switch (nr_selected) {
- case 0: /* keep showing the last selected dive */
- return;
- case 1:
- /* just pick that dive as selected */
- amount_selected = 1;
- path = g_list_nth_data(selected_dives, 0);
- if (gtk_tree_model_get_iter(GTK_TREE_MODEL(dive_list.model), &iter, path)) {
- gtk_tree_model_get(GTK_TREE_MODEL(dive_list.model), &iter, DIVE_INDEX, &selected_dive, -1);
- /* make sure we're not on a summary entry */
- first_leaf (GTK_TREE_MODEL(dive_list.model), &iter, &selected_dive);
- selectiontracker[0] = selected_dive;
- repaint_dive();
+/* make sure that if we expand a summary row that is selected, the children show
+ up as selected, too */
+void row_expanded_cb(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTreePath *path, gpointer data)
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view));
+
+ if (gtk_tree_selection_path_is_selected(selection, path))
+ select_children(GTK_TREE_MODEL(dive_list.model), selection, iter, FALSE);
+}
+
+/* this is called _before_ the selection is changed, for every single entry;
+ * we simply have it call down the tree to make sure that summary items toggle
+ * their children */
+gboolean modify_selection_cb(GtkTreeSelection *selection, GtkTreeModel *model,
+ GtkTreePath *path, gboolean was_selected, gpointer userdata)
+{
+ GtkTreeIter iter;
+ int dive_idx;
+
+ /* if gtk thinks nothing is selected we should clear out our
+ tracker as well - otherwise hidden selected rows can stay
+ "stuck". The down side is that we now have a different bug:
+ If you select a dive, collapse the dive trip and ctrl-click
+ another dive trip, the initial dive is no longer selected.
+ Just don't do that, ok? */
+ if (gtk_tree_selection_count_selected_rows(selection) == 0)
+ clear_tracker();
+
+ if (gtk_tree_model_get_iter(model, &iter, path)) {
+ gtk_tree_model_get(model, &iter, DIVE_INDEX, &dive_idx, -1);
+ /* turns out we need to move the selectiontracker here */
+
+#if DEBUG_SELECTION_TRACKING
+ printf("modify_selection_cb with idx %d (according to gtk was %sselected)\n",
+ dive_idx, was_selected ? "" : "un");
+#endif
+ if (dive_idx >= 0) {
+ if (was_selected)
+ track_unselect(dive_idx);
+ else
+ track_select(dive_idx);
+ } else {
+ select_children(model, selection, &iter, was_selected);