[Gtk-sharp-list] New Glade# hack
Rachel Hestilow
hestilow@ximian.com
01 Jan 2003 15:50:50 -0600
--=-BkerRiudNc+43we7XdB+
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
I was reading through monodoc sources and noticed a long method that
basically was line after line of:
myLabel =3D (Gtk.Label) gxml["my_label"];
I'm sure we've all had to do similar things in programs that use glade
(I know I have, at least), so I figured out a slightly cleaner way to do
this, using attributes.
Here's how to use it: When declaring a member which needs to be
initialized from the Glade.XML, you can simply add a
GladeWidgetAttribute:
[GladeWidget("my_label")]
Gtk.Label myLabel;
And then you can either call the new method BindFields after creating
the Glade.XML, or if you are already calling Autoconnect, it is
automatically called there.
This doesn't really save much in terms of code (for example, in
monodoc's case, it would require breaking up member declarations of the
same type, so the sheer number of lines of code would increase), but it
seems conceptually cleaner to me, particularly because it lets you avoid
an explicit cast.
I have updated GladeTest.cs to demonstrate its usage. Like signal
handlers, it works for both the instance and static cases. (Although the
static case requires a CVS corlib)
Happy Hacking!
-- Rachel
--=-BkerRiudNc+43we7XdB+
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)
iD8DBQA+E2K6apOJdUj74F4RAhf9AKC0B8Y7ejpqXhALXa/YrDWjpL29OACdEoqe
D1PokTmTJwoX2DlwPkhS9jo=
=EEK0
-----END PGP SIGNATURE-----
--=-BkerRiudNc+43we7XdB+--