Make Gio.ActionMap.add_action_entries work
Description
Gio.ActionMap.add_action_entries()
does not work in GJS because the boxed type Gio.ActionEntry
is not introspectable:
gjs> new imports.gi.Gio.ActionEntry({ name: 'new' })
typein:1:1 Error: Unable to construct struct type ActionEntry since it has no default constructor and cannot be allocated directly
@typein:1:1
@<stdin>:1:42
One way to fix this would be to support function pointers in boxed types without a default constructor. It should be safe to set them to null if no function is given as a value.
However, Gio.ActionEntry
kind of feels like a C convenience API anyway, so even if that is fixed, we may want to add an override to turn this
let action = new Gio.SimpleAction({name: 'copy'});
action.connect('activate', () =>
this._text.buffer.copy_clipboard(this._text.get_clipboard()));
this.add_action(action);
action = new Gio.SimpleAction({name: 'paste'});
action.connect('activate', () =>
this._text.buffer.paste_clipboard(this._text.get_clipboard(), null, true));
this.add_action(action);
action = new Gio.SimpleAction({
name: 'fullscreen',
state: new GLib.Variant('b', 'false'),
});
action.connect('activate', this._onToggleActivate.bind(this));
action.connect('change-state', this._onFullscreenStateChange.bind(this));
this.add_action(action);
into something like this
this.add_action_entries([
{
name: 'copy',
activate: () => this._text.buffer.copy_clipboard(this._text.get_clipboard()),
},
{
name: 'paste',
activate: () => this._text.buffer.paste_clipboard(this._text.get_clipboard(), null, true),
},
{
name: 'fullscreen',
state: new GLib.Variant('b', 'false'),
activate: this._onToggleActivate.bind(this),
changeState: this._onFullscreenChangeState.bind(this),
},
]);
This override might be a good newcomers task. But such an override would be blocked on #189 (closed).
Prior Art
The C interface to Gio