[devhelp] Do not expand first book on focus in (GNOME bug 603040)
- From: Frederic Peters <fpeters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [devhelp] Do not expand first book on focus in (GNOME bug 603040)
- Date: Thu, 26 Nov 2009 13:54:34 +0000 (UTC)
commit effcc0fd9a693e91f63b20fef4b6777cd3b9dd1d
Author: Frédéric Péters <fpeters 0d be>
Date: Thu Nov 26 14:48:50 2009 +0100
Do not expand first book on focus in (GNOME bug 603040)
The book tree view gets focus when an expander is pressed, and this causes
the first item to be selected (this is GTK+ bug 492206) and expanded. This
tries to work around that behaviour by always selecting the first book, and
manually tracking the selection.
src/dh-book-tree.c | 31 +++++++++++++++++++++++++++++--
1 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
index 3207948..482d162 100644
--- a/src/dh-book-tree.c
+++ b/src/dh-book-tree.c
@@ -38,6 +38,7 @@ typedef struct {
typedef struct {
GtkTreeStore *store;
GNode *link_tree;
+ DhLink *selected_link;
} DhBookTreePriv;
static void dh_book_tree_class_init (DhBookTreeClass *klass);
@@ -111,7 +112,7 @@ dh_book_tree_init (DhBookTree *tree)
G_TYPE_STRING,
G_TYPE_POINTER,
PANGO_TYPE_WEIGHT);
-
+ priv->selected_link = NULL;
gtk_tree_view_set_model (GTK_TREE_VIEW (tree),
GTK_TREE_MODEL (priv->store));
@@ -219,7 +220,10 @@ book_tree_selection_changed_cb (GtkTreeSelection *selection,
&iter,
COL_LINK, &link,
-1);
- g_signal_emit (tree, signals[LINK_SELECTED], 0, link);
+ if (link != priv->selected_link) {
+ g_signal_emit (tree, signals[LINK_SELECTED], 0, link);
+ }
+ priv->selected_link = link;
}
}
@@ -228,6 +232,9 @@ dh_book_tree_new (GNode *books)
{
DhBookTree *tree;
DhBookTreePriv *priv;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ DhLink *link;
tree = g_object_new (DH_TYPE_BOOK_TREE, NULL);
priv = GET_PRIVATE (tree);
@@ -235,6 +242,26 @@ dh_book_tree_new (GNode *books)
priv->link_tree = books;
book_tree_populate_tree (tree);
+ /* Mark the first item as selected, or it would get automatically
+ * selected when the treeview will get focus; but that's not even
+ * enough as a selection changed would still be emitted when there
+ * is no change, hence the manual tracking of selection in
+ * selected_link.
+ * https://bugzilla.gnome.org/show_bug.cgi?id=492206
+ */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
+ g_signal_handlers_block_by_func (selection,
+ book_tree_selection_changed_cb,
+ tree);
+ gtk_tree_model_get_iter_first ( GTK_TREE_MODEL (priv->store), &iter);
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->store),
+ &iter, COL_LINK, &link, -1);
+ priv->selected_link = link;
+ gtk_tree_selection_select_iter (selection, &iter);
+ g_signal_handlers_unblock_by_func (selection,
+ book_tree_selection_changed_cb,
+ tree);
+
return GTK_WIDGET (tree);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]