gtkgnome-shellcluttergnome-shell-extensionsgjs

Clutter.Text's set_editable() doesn't seem work


I'm trying to create an editable multi-line text box by using the Clutter.Text's set_editable() method:

let label = new St.Label({ text: 'My dummy example.' });
label.clutter_text.set_editable(true);
label.clutter_text.set_activatable(true);

But it doesn't seem to work. What am I missing? Here is the simplified extension.js that uses the code above:

const St = imports.gi.St;
const Main = imports.ui.main;
const Pango = imports.gi.Pango;
const PanelMenu = imports.ui.panelMenu;

let btn;

function DummyApp() {
    this._init();
}

DummyApp.prototype = {
    __proto__: PanelMenu.Button.prototype,
    _init: function() {
        PanelMenu.Button.prototype._init.call(this, St.Align.START);

        let button = new St.Bin();
        let icon = new St.Icon({
            icon_name: 'system-run-symbolic',
            style_class: 'system-status-icon' });

        button.set_child(icon);

        this.actor.add_actor(button);

        let mainBox = new St.BoxLayout();
        let label = new St.Label({ text: 'My dummy example.' });
        label.clutter_text.set_editable(true);
        label.clutter_text.set_activatable(true);

        mainBox.add_child(label);
        this.menu.box.add(mainBox);
    },
}

function init() {}

function enable() {
    btn = new DummyApp();
    Main.panel.addToStatusArea('dummyapp_sec', btn);
}

function disable() {
    Main.panel._rightBox.remove_child(btn);
}

As a footnote, Gtk.TextView looks like just what I need, but I've not been able to figure out how to integrate it to the PopupMenu. Any idea?


Solution

  • Actors in Clutter do not react to events by default; you need to explicitly set the actor as reactive in order for it to receive events.

    Additionally, you cannot use GTK widgets inside GNOME Shell extensions: GTK is a client toolkit, and you're writing an extension for the compositor and display server.