2009-03-11

Vala Notes Plugin

Or better, there is Vala in the Notes plugin. It's been a long time I thought about a hypertext view widget for the notes plugin, so it can highlight links and open them on click, and doing this in pure C/GObject is quite a PITA because there is a lot to take care about (more lines of code), and then you didn't start thinking about the whole functions of the object. Now this is retro with the presence of Vala. I played with Vala some time ago, doing some very rudimentary hello worlds, and I never had a chance to really write something in Vala, untill two days ago. I started to write a very dummy object on top of GtkTextView that implements the simple undo/redo feature I wrote inside notes.c and it was very fast and easy to backport from the C code to Vala, and this gave me a very good start with Vala (now that was one Vala too much, wasn't it? anyway...). Yesterday I added skel functions to support hyperlinks which I finished today. Finally I integrated the Vala object inside the notes plugin in a way that it compiles to C code when you are in MAINTAINER_MODE, which means for end-users they won't need Vala but only gcc.

Now for those interested into Vala, here is the file I played with: hypertext.vala. This source contains at the end of the HypertextView class, another class that contains a main function so it can be compiled to a binary. This proves how easy it is to test a class, and all you need to do is to run the following command: valac --pkg=gtk+-2.0 hypertextview.vala && ./hypertextview.
There are many samples available with the source of Vala and on Gnome Live. The tutorial covers important points, the FAQ too, but the documentation is a little less interesting if you already know GObject IMHO.
One important thing I learned about Vala was the difference between the out and ref arguments.

If you have a hard time at finding the right method definitions, look into /usr/share/vala/vapi/gtk+-2.0.vapi for instance for GTK+. There you can quickly find any function name you now from the C API, for instance if you want to have a look at gtk_text_view_get_iter_at_location search for get_iter_at_location. By scrolling up you will see that you are in the class Gtk.TextView. Vapis are very easy to read.

I am very interested into porting the objects of the Xfmpc project to Vala, and then start trying out the plugin sample (loading modules during runtime)... I hope my fellow will like that idea :-)

Now for the people interested to develop Vala classes with VIM I have some tips. First follow these instructions in order to get Vala syntax. Then I suggest you install the Tag List plugin, and to get it working with Vala you will need to add the following lines to your vimrc configuration:
" Work-around Tag List
let tlist_vala_settings='c#;d:macro;t:typedef;n:namespace;c:class;'.
\ 'E:event;g:enum;s:struct;i:interface;'.
\ 'p:properties;m:method'
If you don't know about folding then you miss a lot of VIM culture, in fact you can fold/unfold brackets by going over a bracket and typing zf% in command mode. And that's all folk, thanks for reading til here.

No comments:

Post a Comment