Update : this is now bug 538021
Since I had a break from my exams (next is on monday), I wrote a little tutorial about writing Anjuta plugins in Vala, it is still incomplete.
I'm posting it here before sending a patch to have more visibility and hopefully someone can proofread it. I'm not really confident about it's quality (and this is the first time I'm writing a software documentation).
Enough speaking, Here you go :
Since I had a break from my exams (next is on monday), I wrote a little tutorial about writing Anjuta plugins in Vala, it is still incomplete.
I'm posting it here before sending a patch to have more visibility and hopefully someone can proofread it. I'm not really confident about it's quality (and this is the first time I'm writing a software documentation).
Enough speaking, Here you go :
Writing plugins in Vala
Before writing an Anjuta plugin, please read Anjuta Architecture for general concepts about how Anjuta plugins interact with Anjuta Shell and other plugins. Anjuta API is divided in two namespaces : Anjuta and IAnjuta. Anjuta contains API to interact with the IDE, and IAnjuta contains interfaces that plugins implement to be able to interact with each other. Writing a plugin for Anjuta is as simple as subclassing Anjuta.Plugin, overriding activate and deactivate, and writing a .plugin file to let Anjuta know about your plugin. This tutorial is still uncomplete. However most of the documentation regarding C plugins is still applicable, so you can always refer to Writing plugins. In this tutorial, we will write a basic Hello world plugin that does nothing but adding a "Hello World" label to Anjuta.Writing the plugin code
As said earlier, we will need to subclass Anjuta.Plugin and override some methods, so here is Anjuta.Plugin :
public class Anjuta.Plugin : GLib.Object {
public uint add_watch (string name, Anjuta.PluginValueAdded added, Anjuta.PluginValueRemoved removed);
public bool is_active ();
public void remove_watch (uint id, bool send_remove);
public virtual bool activate ();
public virtual bool deactivate ();
public weak Anjuta.Shell shell { get; set; }
public signal void activated ();
public signal void deactivated ();
}
The methods we'll need to override are activate and deactivate, the shell
property is what we'll use to interact with Anjuta.
add_watch
and remove_watch are used to interface with the
Values System see Anjuta Architecture
for more information. The rest is pretty self explanatory, and we generally won't need it.
We will only use the add_widget method of
Anjuta.Shell in this tutorial. For more informations, you can see
the C API documentation.
This plugin does nothing more than showing a "Hello World" widget in
Anjuta
using Gtk;
using Anjuta;
public class HelloWorldPlugin: Plugin {
/* The hello world widget */
Widget widget;
/* We use the "override" keyword to override the virtual methods activate and deactivate */
public override bool activate () {
widget = new Label("Hello World");
/* adding the widget */
shell.add_widget(widget, /* the widget to add */
"AnjutaHelloWorldPlugin", /* name of the widget */
"HelloWorldPlugin", /* title, should be translated */
Gtk.STOCK_ABOUT, /* icon stock id */
ShellPlacement.CENTER); /* placement in in the shell */
return true; /* false if activation failed */
}
public override bool deactivate () {
/* remove the widget we've added */
shell.remove_widget(widget);
return true; /* false if plugin doesn't want to deactivate */
}
}
/* Initialization function, in C this would be automatically generated by the
ANJUTA_SIMPLE_PLUGIN macro */
[ModuleInit]
public GLib.Type anjuta_glue_register_components (GLib.TypeModule module) {
return typeof (HelloWorldPlugin);
}
Writing a plugin description
Anjuta needs a file with a plugin extension to know about our plugin, its name and description, where it is located, when to load it. Here is an example for our basic plugin :[Anjuta Plugin] Name=Hello World Description=An example hello world plugin. Location=anjuta-hello-world:HelloWorldPlugin Icon=anjuta-sample-plugin-48.png
Generally, Name and Description should be translated. Using intltool, you can
do this by prefixing them with _.
Location is of the form libraryname:ClassName : libraryname is the name of the
library file (without the lib prefix and .so suffix), and ClassName is the full
class name including the namespace (and not separated by a period as you would
write it in Vala).
Icon is the icon to be used by the plugin, here we put sample plugin icon which
is distributed along with Anjuta, but you could put your own icon instead.
For more information about plugin description files, refer to
Plugin description file.
Compiling and installing the plugin
Manual compilation
Assuming you saved the plugin as hello-plugin.vala, you can compile it with :
valac --ccode --pkg libanjuta-1.0 hello-plugin.vala
gcc -shared -o libanjuta-hello-world.so hello-plugin.c
Using autotools
Coming soon.You can get the vapi (and deps) for Anjuta from my mercurial repository (direct links : vapi, deps), add
--vapidir /path/to/libanjuta-1.0.vapi to valac command line.
Posted by Abderrahim Kitouni
in GNOME
| Comments (3)
| Trackbacks (0)
Related entries by tags:
anjuta-vala new home
Some news
Anjuta-valaplugin 0.3
Vala plugin news
GDB Vala support
anjuta-vala new home
Some news
Anjuta-valaplugin 0.3
Vala plugin news
GDB Vala support
Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
public class Anjuta.Plugin : GLib.Object{ and
public class HelloWorldPlugin: Plugin { classes?
And how and where should I save the description file ?
Layout by Ricky Wilson | Serendipity Template by Carl Galloway | Login

