Thank You very much. You always give good explanation @fmuellner.
This really make sense. when Array Integer (ai) is used, no need of quotations.
String Array (as) looks like this [ ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’ ]
where as ArrayInteger (ai) is simple [ 1, 2, 3, 4, 5, 6, 7, 8 ]
You have to create a GVariant of the expected type:
const value = new GLib.Variant('ai', [1, 2, 3, 4, 5, 6, 7, 8]);
this._settings.set_value('buttons-order', value);
This is actually the case for all GSettings values, methods like set_string() or get_boolean() are all convenience wrappers around get_value() and set_value().
This is because the text in the entry is a string, with this code you’re passing the string '[1, 2, 3,…]' instead of the array of integers [1, 2, 3,…] to the settings, and I think the console would have told you about that.
You have to convert the string to the array of integers, GLib.Variant.parse() can help you with that:
const s = '[1, 2, 3, 4]';
const variantType = new GLib.VariantType('ai');
const variant = GLib.Variant.parse(variantType, s, null, null);
This will give you a new GVariant with the parsed array.
let orderEntry = new Gtk.Entry();
orderEntry.connect('changed', (entry) => {
let string = entry.get_text();
const varType = new GLib.VariantType('ai');
let value = GLib.Variant.parse(variantType, string, null, null);
this._settings.set_value('buttons-order', value); });
and in extension.js like this
let BUTTONS_ORDER = this._settings.get_value('buttons-order').deepUnpack();
this BUTTONS_ORDER works initially with the schema’s set in xml file. But when I change in the Gtk.Entry in extension settings, the value is not chaning.
Gtk.Editable.set_text() (the interface implemented by GtkEntry) expects a String, but you’re giving it a GVariant, so it complains. Try passing it value.deepUnpack().toString()? You’ll have to manually add the square brackets as they are not included in the Array.toString() method.