[empathy: 24/28] Reimplement scrollToRow
- From: Danielle Madeley <daniellem src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy: 24/28] Reimplement scrollToRow
- Date: Thu, 18 Aug 2011 00:36:48 +0000 (UTC)
commit 9d1f95bebe28683a23f56568539ee2c56655b80c
Author: Danielle Madeley <danielle madeley collabora co uk>
Date: Tue Aug 16 13:55:56 2011 +1000
Reimplement scrollToRow
N.B. This has not been properly tested, because I'm not actually sure how to
exhaust this codepath.
data/empathy-log-window.html | 25 +++++++++++++++++++++++
libempathy-gtk/empathy-log-window.c | 37 +++++++++++++++++++++-------------
2 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/data/empathy-log-window.html b/data/empathy-log-window.html
index 4decbce..5a94b7e 100644
--- a/data/empathy-log-window.html
+++ b/data/empathy-log-window.html
@@ -237,6 +237,31 @@ function hasChildRows (path, has_children)
else
toggle.style.display = 'none';
}
+
+function getOffset (node)
+{
+ var y = 0;
+
+ while (node != null && !isNaN(node.offsetTop))
+ {
+ y += node.offsetTop - node.scrollTop;
+ node = node.offsetParent;
+ }
+
+ return y;
+}
+
+function scrollToRow (path)
+{
+ var treeview = document.getElementById('treeview');
+ var node = treeview;
+
+ // walk the tree
+ for (var i = 0; i < path.length; i++)
+ node = getNodes(node)[path[i]];
+
+ window.scrollTo(0, getOffset(node));
+}
</script>
</head>
diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c
index ac05740..b4501af 100644
--- a/libempathy-gtk/empathy-log-window.c
+++ b/libempathy-gtk/empathy-log-window.c
@@ -3049,13 +3049,12 @@ log_window_got_messages_for_date_cb (GObject *manager,
gpointer user_data)
{
Ctx *ctx = user_data;
- // GtkTreeView *view;
- // GtkTreeModel *model;
- // GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
GList *events;
GList *l;
GError *error = NULL;
- // gint n;
+ gint n;
if (log_window == NULL)
{
@@ -3129,18 +3128,28 @@ log_window_got_messages_for_date_cb (GObject *manager,
}
g_list_free (events);
- // view = GTK_TREE_VIEW (log_window->priv->treeview_events);
- // model = gtk_tree_view_get_model (view);
- // n = gtk_tree_model_iter_n_children (model, NULL) - 1;
+ model = GTK_TREE_MODEL (log_window->priv->store_events);
+ n = gtk_tree_model_iter_n_children (model, NULL) - 1;
+
+ if (n >= 0 && gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
+ {
+ GtkTreePath *path;
+ char *str, *script;
+
+ path = gtk_tree_model_get_path (model, &iter);
+ str = gtk_tree_path_to_string (path);
- // if (n >= 0 && gtk_tree_model_iter_nth_child (model, &iter, NULL, n))
- // {
- // GtkTreePath *path;
+ script = g_strdup_printf ("javascript:scrollToRow([%s]);",
+ g_strdelimit (str, ":", ','));
- // path = gtk_tree_model_get_path (model, &iter);
- // gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0, 0);
- // gtk_tree_path_free (path);
- // }
+ webkit_web_view_execute_script (
+ WEBKIT_WEB_VIEW (log_window->priv->webview),
+ script);
+
+ gtk_tree_path_free (path);
+ g_free (str);
+ g_free (script);
+ }
out:
ctx_free (ctx);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]