GTree.tree_store for more than 2 levels of nesting

Hello OCaml enthusiasts,

How can I, using lablgtk3, code a tree widget which ultimately should looks like this macOS Cocoa widget of VLC. This is for a Flac file player.

I’ve tried everything with no lucks, here is my model builder taken from this file:

let create_model () =
    Tags.reset () ; Tags.scan "/Users/philippe/Music/flac" ; Tags.mktree () ;
    let tree = Tags.get_tree () in
    let model = GTree.tree_store cols in
    Tags.StringMap.iter (
        let row_artist = model #append () in
        fun artist albums -> model #set ~row:row_artist ~column:song artist ;
        Tags.AlbumMap.iter (
            let row_album = model #append ~parent:row_artist () in
            fun (album, year) songs -> model #set ~row:row_album ~column:song album ;
            Tags.SongSet.iter (
                fun (track_nr_opt, title, duration, path) ->
                    model #set ~row:(model #append ~parent:row_album ()) ~column:song title ;
            ) !songs
        ) !albums
    ) tree ;
    model

For example I’ve noticed that:

let row = model #append () in
...
model #set ~row ~column:col content

and

model #set ~row:(model #append ()) ~column:col content

have not the same effect at all, and I can’t understand why.

Here is a screenshot of the result of the above (first source code frame). Songs are fine, but albums titles and artists names not at all.
The first artist, in Russian, is actually the only artist shown with this model builder, and the LAST of the ocaml Set/Map tree. Songs are right in number because I’m using the ~row:(model #append ()) way of adding a new row, which works fine while the let binding way does not works.
Artists and albums row must be referred for being a ~parent, hence uses the let row = model #append () in and comes wrong in number, only the last album name of an artist makes its way into the lablgtk tree. Here’s a text file with the pretty printing of the ocaml Set/Map (not lablgtk) tree.

TIA!

1 Like

Hourahh it works!
me stupid!

let create_model () =
    Tags.reset () ; Tags.scan "/Users/philippe/Music/flac" ; Tags.mktree () ;
    let tree = Tags.get_tree () in
    let model = GTree.tree_store cols in
    Tags.StringMap.iter (
        fun artist albums -> let row_artist = model #append () in
            model #set ~row:row_artist ~column:song artist ;
        Tags.AlbumMap.iter (
            fun (album, year) songs -> let row_album = model #append ~parent:row_artist () in
                model #set ~row:row_album ~column:song album ;
            Tags.SongSet.iter (
                fun (track_nr_opt, title, duration, path) ->
                    model #set ~row:(model #append ~parent:row_album ()) ~column:song title ;
            ) !songs
        ) !albums
    ) tree ;
    model