Adi Roiban <a...@...> writes:

> 
> În data de Jo, 07-05-2009 la 20:18 +0000, Jan Hudec a scris:
> > Adi Roiban <a...@...> writes:
> > > În data de Mi, 06-05-2009 la 17:48 +0000, Jan Hudec a scris:
> [snip]
> > > For example in the case of MenuItem, we have the "activated" signal and
> > > there is not way to pass userdata when connecting the signal.
> > > The method called for the "activate" signal will only receive a pointer
> > > to the MenuItem... and I can not pass userdata.
> > False!
> > 
> > You can always specify a user data for g_signal_connect(). Vala uses
> > that pointer to pass in the *invocant* of the handler. So all you have to 
do
> > is create an object describing the action to take and connect it's instance
> > method (*not* static) to the activated signal of the menu item.
> Thank you very much for you explanations!
> 
> I don't know how to connect userdata. Can you point me to some
> documentation?
> 
> Reading the Vala wiki pages I know I can use this syntax:
> 
> menuItem.activated += (sender) => {doSomething(sender)};
> 
> Where should I fit the userdata?

Use the other syntax:

    SomeClass some_object;
    ...
    menuItem.activated += some_object.handler;
    ...
    class SomeClass {
        public void handler(Gtk.MenuItem sender) { ... }
    }

Now the some_object instance is your user data!

The other thing is, that the syntax you are using is a "closure" syntax, so
I would somehow hope it works as one, but unfortunately it does not.

> > Alternatively, you can simply attach data to the MenuItem using the
> > Glib::Object method set_data (and corresponding get_data to read them).
> 
> I didn't knew about this nice feature of GObject. Thanks!

I may turn out that you will actually have to report a bug or two against vala 
(I would expect GLib.Object.set_data will actually map to 
g_object_set_data_full to take care about reference counts, but it does not and 
I can't tell without thorough testing whether it's wrong or not) before it's 
fully usable, though.

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to