After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 119364 - list fires two selections if items added after list shown
list fires two selections if items added after list shown
Status: RESOLVED DUPLICATE of bug 94837
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
2.2.x
Other Windows
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2003-08-07 19:36 UTC by Grant Gayed
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: 2.1/2.2



Description Grant Gayed 2003-08-07 19:36:52 UTC
In the following snippet the list's items are added after the list is 
shown (they're added at "position 2"), so no item is initially selected.  
The problem is that selecting a list item then causes 2 selection events 
to fire instead of the expected 1 selection event.

Moving the item-creation lines from "position 2" to "position 1" makes the 
problem go away, presumably because the first item is initially selected 
for free.

#include <gtk/gtk.h>
void changed (int a, int b) {
  g_print("selection\n");
}
int main (int argc, char *argv[]) {
  GtkWidget *window, *sw, *box;
  GtkTreeViewColumn *column;
  GtkTreeIter iter1, iter2;
  GtkListStore *store;
  GtkWidget *tree;
  GtkCellRenderer *renderer;
  GtkTreeSelection *selection;

  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  box = gtk_hbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER(window), box);
  sw = gtk_scrolled_window_new (NULL, NULL);
  store = gtk_list_store_new (1, G_TYPE_STRING);
  tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
  g_object_unref (G_OBJECT (store));
  renderer = gtk_cell_renderer_text_new ();
  column = gtk_tree_view_column_new_with_attributes (
    0, renderer, "text", 0, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree));
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
  g_signal_connect (selection, "changed", G_CALLBACK(changed), NULL);
  gtk_box_pack_start (GTK_BOX(box), sw, TRUE, TRUE, 0);
  gtk_container_add ((GtkContainer *)sw, tree);

  /* position 1 */

  gtk_widget_show_all(window);

  /* position 2 */
  gtk_list_store_append (store, &iter1);
  gtk_list_store_set (store, &iter1, 0, "item 1", -1);
  gtk_list_store_append (store, &iter2);
  gtk_list_store_set (store, &iter2, 0, "item 2", -1);

  gtk_main();
  return 0;
}
Comment 1 Grant Gayed 2003-08-07 19:40:09 UTC
As a side note: the same problem also happens if TreeStore is used 
instead of ListStore.
Comment 2 Kristian Rietveld 2003-08-14 19:57:16 UTC

*** This bug has been marked as a duplicate of 94837 ***