2014-07-08 19:02 GMT+02:00 Dimitri Giardina <dimitri.giard...@gmail.com>:
> Il giorno lun, 07/07/2014 alle 17.50 +0100, Emmanuele Bassi ha scritto:
>> hi;
>>
>> to define new signals, you need to use the `Signals` key in object you
>> pass to the Lang.Class() constructor you use when subclassing a
>> GObject.
> ok, i've resolved in this way, it's equivalent?
>
> const WebBrowserTabLabel = new Lang.Class({
>     Name: 'WebBrowserTabLabel',
>     Extends: Gtk.Box,
>     _init: function() {
>         this.parent();
>         Signals.addSignalMethods(WebBrowserTabLabel.prototype);
> [...]
>         button.connect("clicked", this.buttonClick);
>         this.pack_start(button, false, false, 0);
>         this.show_all();
>     },
>     clickClose: function() {},
>     buttonClick: function(self, button, data) {
>         self.p.emit('close-clicked');
>     },
> });
>
> what's the difference using Signals property and
> Signals.addSignalMethods?

If you use Signals.addSignalMethods, you lose all GObject signals and
only see the JS ones. Not what you want, probably.

> without the Singals.addSignalMethods, the interpreter tell me that the
> Gtk.Box haven't the signal 'close-clicked' (it's normal, i know).

Try with

const WebBrowserTabLabel = new Lang.Class({
     Name: 'WebBrowserTabLabel',
     Extends: Gtk.Box,
     Signals: { 'close-clicked': { } }
     _init: function() {
         this.parent();

         button.connect("clicked", Lang.bind(this, this.buttonClick));
         this.pack_start(button, false, false, 0);
         this.show_all();
     },
     clickClose: function() {},
     buttonClick: function(button) {
         this.emit('close-clicked');
     },
});

See https://people.gnome.org/~gcampagna/docs/GObject-2.0/GObject.Class.html
for a description of how GObject.Class works (or Lang.Class, they're
equivalent if you specify Extends)

Btw, you should always use Lang.bind() to have "this" properly set in callbacks.

Giovanni
_______________________________________________
javascript-list mailing list
javascript-list@gnome.org
https://mail.gnome.org/mailman/listinfo/javascript-list

Reply via email to