On Sun, 4 Nov 2018 19:04:20 +0100, Mike Wey wrote:

On 01-11-18 22:58, Mike Wey wrote:

1) GtkTreeModelFilterVisibleFunc is available in gtk.c.types, only it's
the plain C one, so it's not easy to use. I'll post an more detailed
answer when i have a bit more time.

GtkTreeModelFilterVisibleFunc is a simple C callback, so in the callback
you will need to convert these to D objects.

filter.setVisibleFunc(&FilterTree, null, cast(GDestroyNotify)null);

public static extern(C) int FilterTree(GtkTreeModel* m, GtkTreeIter* i, 
void* data)
{
	TreeModel model = new TreeModel(m);
	TreeIter  iter  = new TreeIter(i);

	string name = model.getValue(iter, 0).getString();
	if (name == "BT")
		return true;
	else
		return false;
}

2) You can convert a TreePath to an iter using the getIter function.

3) The foreach_ function allows you to iterate over all the values in
the model.

The foreach_ function has the same issue as the VisibleFunc:

model.foreach_(&ForEachFunc, null);

public static extern(c) in tForEachFunc(GtkTreeModel* m, GtkTreePath* p, 
GtkTreeIter* i, void* data)
{
	TreeModel model = new TreeModel(m);
	TreePath  path  = new TreePath(p);
	TreeIter  iter  = new TreeIter(i);

	...
}

Thank you. Would you mind telling me which module does this foreach_ belong to?

Also, regarding the filter, the compiler complains that the nested function is unable to access the enclosing function, probably because the nested function is static. How can I send a string to fn? I still don't understand how fn itself works too. It seems that fn expects 3 arguments yet when I call filter.setVisibleFunc(&fn, null, cast(GDestroyNotify) null);, I don't see any arguments provided to it.