Question

One month ago I heard about GJS for GNOME 3 and I wanted to try it out. What do I want to make? A simple Media Player for GNOME 3 with GJS.

So, the base has been programmed, eg.:

  • Create and connect the ListStore to a TreeView Object
  • OpenFile Dialog - Select a MP3/OGG/WAV-File
  • Get the File Name and URI from OpenFile Dialog and put it into the Gtk.ListStore Object
  • When the File gets selected (in the TreeView Object) the Gst Object fetches the URI from the currently selected line.

The problem is now that I want to manually change the selected Line in the TreeView Object (when the user presses the Forward or Back Button), and I don't have a clue how to do this.

I looked it up at the official GNOME-Docs, at the unofficial Seed Documentation and Google'd it up with no results. I tried to find it out with the C-Docs of GNOME 3, but still nothing.

I hope that somebody could give me a hand at this "little" problem. :)

The Link to the simple Music Player.

Was it helpful?

Solution

Okay, i just found the answer:

// Get the selection from the Gtk.TreeView Object
this.selection = this._soundList.get_selection ();
// Get the bool "isSelected", the model and the Iter from this.selection.get_selected()
let [ isSelected, model, iter ] = this.selection.get_selected();
// Get the previous row in the list (iter_next(iter) for the next row)
this._listStore.iter_previous(iter);
// The selection should get updated
this.selection.select_iter(iter);
// Get the URI from the Gtk.ListStore Object
this.sound.uri = this._listStore.get_value (iter, 1);

I hope this will help those who will need it.

OTHER TIPS

There are good examples at: https://github.com/optimisme/gjs-examples

The one using 'TreeView' is egList.js but egOpen.js also has onet Gtk.ComboBox using Gtk.ListStore, Gtk.CellRendererTex and Gtk.TreeIter used from one 'changed' event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top