Hi all,

I have a question about list items and selection mode. 
I create a GtkList,

  list = gtk_list_new();

set the selection mode to GTK_SELECTION_BROWSE,

  gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_BROWSE);

stuff it inside a GtkScrolledWindow, and add some items it,

  items = NULL;
  for (i=0; list_items[i] != NULL; i++)
      list_item = gtk_list_item_new_with_label(list_items[i]);
      items = g_list_append(items, list_item);
  gtk_list_prepend_items(GTK_LIST(list), items);

And just to make sure (not that it should be necessary) I force-select
the first item,

  gtk_list_select_child(GTK_LIST(list), GTK_WIDGET(items->data));

This looks fine, the first item in the list appears selected.
Now, I also have a button, and its "clicked" callback deletes the
first item in the list,

  GList *items = gtk_container_children(GTK_CONTAINER(list));
  GtkWidget *item;

  if (items)
      item = GTK_WIDGET(items->data);
      /* Could also use gtk_widget_destroy() here, no? */
      gtk_container_remove(GTK_CONTAINER(list), item);

This deletes the first list item, but the next item does not
get selected.  This seems to violate the specified behavior

I noticed that the docs say, 

  "Exactly one element is always selected (this can be false
   after you have changed the selection mode)."

which is why I explicitly set the first item earlier.

Note that it does behave properly if I click any list item at
least once, but I want the list to always have a selected
item without requiring that the user clicks the list once.

Can anyone suggest a fix?  I have a workaroud, which is to call
gtk_list_child_position() just before removing the list item, 
remove the item,  then select the one at the saved position (or 
one less if it was the last item), but I'd like the 
GTK_SELECTION_BROWSE behavior to take care of this for me.

In case this is my own fault (not unlikely), the source is at

My Gtk version,

  $ gtk-config --version


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