Problem with Gtk.ListStore



Hi,

I'm trying to write a gnome shell extension. As part of that I'm making a preference page for which one of the preferences is a file list. I'm modelling this as a TreeView, with an Add button next to it that opens a FileChooserDialog, and adds the selected file name in the list when OK is pressed.

I have however a problem with inserting values in that treeview. The treeview is created like this:

        this.actor = new Gtk.TreeView({headers_visible: false});
        this.store = new Gtk.ListStore();
        this.store.set_column_types([GObject.TYPE_STRING]);
        this.actor.set_model(this.store);

        this.column = new Gtk.TreeViewColumn();
        this.cell = new Gtk.CellRendererText();
        this.column.pack_start(this.cell, true);
        this.column.add_attribute(this.cell, "text", 0);
        this.actor.append_column(this.column);

this.actor.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
        ...

And when I add literal values, it works:

        this.store.clear();
        let iter = this.store.append();
        this.store.set_value(iter, 0, "test");

But string values passed on from somewhere else don't work (I'm simplifying here, I want to do a loop on items of course):

        update_all: function() {
           this.update(["test"]);
        },

        update: function(items) {
           this.store.set_value(iter, 0, items[0]);
           ...
        }

with as error:
Error: Could not guess unspecified GValue type

When the 'items' variable is a local array in the method, it works and is indeed shown in the treeview:

        // items is an array of string passed to the surrounding function
        update: function() {
           let items = ["test"];
           this.store.set_value(iter, 0, items[0]);
           ...
        }

I've also tried creating a GObject.Value explicitly to pass to set_value (I'm assuming that this is the correct way to construct a GObject.Value, because if I try it in lg at least get_string() returns the proper value):

        let v = new GObject.Value();
        v.init(GObject.TYPE_STRING);
        v.set_string(items[0]);
        this.store.set_value(iter, 0, v);

But that gave me the same error message.

I suppose this is a bug in the javascript binding?

Best regards,
Peter.

--
===================================================================
Peter Verthez                                     Software engineer
Email:                               mailto:Peter Verthez skynet be
WWW:                                    http://www.peterverthez.net
PGP key:        on homepage (see above) or http://www.keyserver.net
===================================================================



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