[epiphany/overview] ephy-active-store: handle removal of rows internally



commit 97194a3abe6b9a9f8a2ab7b56f609049d6651642
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Wed Jun 13 16:58:38 2012 +0300

    ephy-active-store: handle removal of rows internally
    
    When a row is removed by the model itself, we need to ensure that
    this is replicated in the notebook too.

 src/ephy-active-store.c |   45 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/src/ephy-active-store.c b/src/ephy-active-store.c
index b064e79..37d7275 100644
--- a/src/ephy-active-store.c
+++ b/src/ephy-active-store.c
@@ -29,6 +29,8 @@
 struct _EphyActiveStorePrivate
 {
   EphyNotebook *notebook;
+
+  gboolean removing_internally : 1;
 };
 
 enum
@@ -59,6 +61,23 @@ ephy_active_store_set_property (GObject *object,
 }
 
 static void
+on_row_deleted_cb (GtkTreeModel *model,
+                   GtkTreePath *path,
+                   gpointer user_data)
+{
+  EphyActiveStore *self;
+  int index;
+
+  self = EPHY_ACTIVE_STORE (model);
+  index = gtk_tree_path_get_indices (path) [0];
+
+  self->priv->removing_internally = TRUE;
+  gtk_notebook_remove_page (GTK_NOTEBOOK (self->priv->notebook),
+                            index);
+  self->priv->removing_internally = FALSE;
+}
+
+static void
 ephy_active_store_get_property (GObject *object,
                                 guint prop_id,
                                 GValue *value,
@@ -118,6 +137,9 @@ ephy_active_store_init (EphyActiveStore *self)
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
                                         EPHY_ACTIVE_STORE_TAB_POS,
                                         GTK_SORT_ASCENDING);
+
+  g_signal_connect_after (self, "row-deleted",
+                          G_CALLBACK (on_row_deleted_cb), NULL);
 }
 
 typedef void (* BindingFunc) (GtkTreeModel *model, GtkTreeIter *iter, GValue *value, gpointer data);
@@ -300,15 +322,20 @@ ephy_active_store_remove_from_embed (EphyActiveStore *store,
   HelperCtx *ctx;
 
   webview = ephy_embed_get_web_view (embed);
-  ctx = g_slice_new0 (HelperCtx);
-  ctx->cmp_uri = g_intern_string (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (webview)));
-  gtk_tree_model_foreach (GTK_TREE_MODEL (store),
-                          (GtkTreeModelForeachFunc) foreach_helper,
-                          ctx);
-  iter = ctx->iter;
-  g_slice_free (HelperCtx, ctx);
-
-  gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
+
+  if (store->priv->removing_internally == FALSE) {
+    ctx = g_slice_new0 (HelperCtx);
+    ctx->cmp_uri = g_intern_string (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (webview)));
+    gtk_tree_model_foreach (GTK_TREE_MODEL (store),
+                            (GtkTreeModelForeachFunc) foreach_helper,
+                            ctx);
+    iter = ctx->iter;
+    g_slice_free (HelperCtx, ctx);
+
+    g_signal_handlers_block_by_func (store, on_row_deleted_cb, NULL);
+    gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
+    g_signal_handlers_unblock_by_func (store, on_row_deleted_cb, NULL);
+  }
 
   bindings_drop (G_OBJECT (webview));
   bindings_drop (G_OBJECT (embed));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]