Re: TreeView/ListStore reordering by DND



On Sat, 2014-03-01 at 02:08 +0100, Stefan Salewski wrote:
On Sat, 2014-03-01 at 00:42 +0000, Lance Capser (lmcapser) wrote:
The "row_inserted" and "row_deleted" signals in the GtkTreeModel are
each called with the GtkTreePath of the row in question:


That is true.

But for my test with a list with only two rows I got numbers from 0 to 2
from gtk_tree_path_get_indices () when moving rows with the mouse. It
may be OK getting index two for insertion, because inserting occurs
before deletion. But currently I am not able to map the indices to the
correct row numbers, seems to be more or less arbitrary. And the iter
seems to be empty (no data) for the "row_inserted" signal handler?

(Currently I am testing with the Ruby bindings for GTK3, which generally
work very well. I will continue testing with some C code soon...)


OK -- I took a Zetcode demo for starting.

Here is my complete C code:

http://www.ssalewski.de/tmp/test.c

I inserted these lines:

void on_row_inserted(GtkTreeModel *tree_model, GtkTreePath *path,
GtkTreeIter *iter, gpointer user_data)
{
  char *value;
  printf("row_inserted\n");
  gtk_tree_model_get(tree_model, iter, LIST_ITEM, &value, -1);
  g_printf("value = %s\n", value);
  gint *i = gtk_tree_path_get_indices(path);
  g_printf("row ins = %d\n", i[0]);
}

void on_row_deleted(GtkTreeModel *tree_model, GtkTreePath *path, gpointer user_data)
{
  printf("row_deleted\n");
  gint *i = gtk_tree_path_get_indices(path);
  g_printf("row del = %d\n", i[0]);
}

First question:
When I exchange rows by drag and drop, I get

value = (null)

similar to my test from Ruby yesterday. Is this intended, or is my code
wrong (I have not much practice with using GTK from plain C...)

Second question: I get row numbers when I exchange rows -- is there an
easy way to map that numbers to the exchanged rows? Some glue logic
seems to be necessary, i.e. for inserting: When I move upwards, the
number is the final row number, but when I move downwards it is row + 1?

Best regards

Stefan Salewski




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