diff options
-rw-r--r-- | widgets/misc/ChangeLog | 10 | ||||
-rw-r--r-- | widgets/misc/e-source-selector.c | 66 |
2 files changed, 75 insertions, 1 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index a98b1975d6..073f5dd902 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,13 @@ +2004-01-20 JP Rosevear <jpr@ximian.com> + + * e-source-selector.c (test_collapse_row_callback): check if the + collapsing node has its child selected, if so take a row reference + to remember the selection + (row_expanded_callback): check if the expanding node has the saved + primary selection under it and re-select if so + (init): listen for signals + (impl_dispose): free the primary selection + 2004-01-19 JP Rosevear <jpr@ximian.com> * e-source-selector.c (create_rebuild_data): create the data diff --git a/widgets/misc/e-source-selector.c b/widgets/misc/e-source-selector.c index 68ae062682..3a46d5d217 100644 --- a/widgets/misc/e-source-selector.c +++ b/widgets/misc/e-source-selector.c @@ -45,7 +45,8 @@ struct _ESourceSelectorPrivate { GtkTreeStore *tree_store; GHashTable *selected_sources; - + GtkTreeRowReference *saved_primary_selection; + int rebuild_model_idle_id; gboolean toggled_last; @@ -467,6 +468,61 @@ selection_changed_callback (GtkTreeSelection *selection, } static gboolean +test_collapse_row_callback (GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *path, gpointer data) +{ + ESourceSelector *selector = data; + ESourceSelectorPrivate *priv; + GtkTreeIter child_iter; + + priv = selector->priv; + + if (priv->saved_primary_selection) + return FALSE; + + if (!gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (selector)), NULL, &child_iter)) + return FALSE; + + if (gtk_tree_store_is_ancestor (priv->tree_store, iter, &child_iter)) { + GtkTreePath *child_path; + + child_path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->tree_store), &child_iter); + selector->priv->saved_primary_selection = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->tree_store), child_path); + gtk_tree_path_free (child_path); + } + + return FALSE; +} + +static gboolean +row_expanded_callback (GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *path, gpointer data) +{ + ESourceSelector *selector = data; + ESourceSelectorPrivate *priv; + GtkTreePath *child_path; + GtkTreeIter child_iter; + + priv = selector->priv; + + if (!priv->saved_primary_selection) + return FALSE; + + child_path = gtk_tree_row_reference_get_path (priv->saved_primary_selection); + gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->tree_store), &child_iter, child_path); + + if (gtk_tree_store_is_ancestor (priv->tree_store, iter, &child_iter)) { + GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (selector)); + gtk_tree_selection_select_iter (selection, &child_iter); + + gtk_tree_row_reference_free (priv->saved_primary_selection); + priv->saved_primary_selection = NULL; + } + + gtk_tree_path_free (child_path); + + return FALSE; +} + +static gboolean selector_button_press_event (GtkWidget *widget, GdkEventButton *event, ESourceSelector *selector) { ESourceSelectorPrivate *priv = selector->priv; @@ -518,6 +574,11 @@ impl_dispose (GObject *object) priv->selected_sources = NULL; } + if (priv->saved_primary_selection != NULL) { + gtk_tree_row_reference_free (priv->saved_primary_selection); + priv->saved_primary_selection = NULL; + } + if (priv->rebuild_model_idle_id != 0) { g_source_remove (priv->rebuild_model_idle_id); priv->rebuild_model_idle_id = 0; @@ -626,6 +687,9 @@ init (ESourceSelector *selector) g_signal_connect_object (selection, "changed", G_CALLBACK (selection_changed_callback), G_OBJECT (selector), 0); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (selector), FALSE); + + g_signal_connect (G_OBJECT (selector), "test-collapse-row", G_CALLBACK (test_collapse_row_callback), selector); + g_signal_connect (G_OBJECT (selector), "row-expanded", G_CALLBACK (row_expanded_callback), selector); } |