gir.core icon indicating copy to clipboard operation
gir.core copied to clipboard

can't create a Gtk.ListStore or Gtk.TreeStore

Open ghost opened this issue 10 months ago • 3 comments

It's not possible to use the Gtk.TreeView class in Gir.Core GTK 4 in C#. The problem is that to use a TreeView you would need a Gtk.ListStore or a Gtk.TreeStore, and Gir.Core doesn't expose any ListStore or TreeStore constructor that would let you specify the number of columns or their types.

In C there is a function gtk_list_store_newv(int n_columns, GType* types):

https://docs.gtk.org/gtk4/ctor.ListStore.newv.html

But in Gir.Core, the only accessible constructors for Gtk.ListStore don't have n_columns or a GType array.

They are

public ListStore(params ConstructArgument[] constructArguments)

and

public ListStore(ListStoreHandle handle)

The situation with Gtk.TreeStore is similar.

https://docs.gtk.org/gtk4/ctor.TreeStore.newv.html

Would it be possible in an update to provider the constructors?

Thank you

ghost avatar Feb 16 '25 08:02 ghost

The constructor can not be provided as they require “VarArgs” which are not supported by dotnet as far as I know.

But it should be checked why api like https://docs.gtk.org/gtk4/method.TreeStore.set_column_types.html is not available.

badcel avatar Feb 26 '25 15:02 badcel

Both ListStore and TreeStore are deprecated for a few years now...

UrtsiSantsi avatar Apr 02 '25 20:04 UrtsiSantsi

For what it's worth, I was able to get this working in an older version of gircore (maybe it still works with the current version - not sure):

https://github.com/hol430/NCBrowse/blob/master/src/NCBrowse/Frontend/Helpers/GenericListView.cs

As @UrtsiSantsi said though, this is an old part of the api and there are probably better ways to do what you want these days.

hol430 avatar Apr 03 '25 04:04 hol430