Writing plugins

Before writing any Anjuta plugin, please read Anjuta Architecture to get a picture of how plugins interact with Anjuta shell and other plugins. Only a general overview is necessary for now. Eventually, as we proceed through this article, you can visit respective sections to read more. This is a tutorial style article and is never meant to be a cover-all document. You should read other relevent documents linked at respective places throughout this document to know further.

We are going to write the legacy Hello World plugin. It really doesn't do anything other than displaying hello world. We will then continue with an advanced version of this plugin. Unlike the basic Hello world plugin, this advanced version will have much more. In addition to having a widget where Hello World is displayed, it will also have a menu enty (UI) to display a dialog, implement a IAnjutaFile interface and access other plugins using their interfaces.

Hello world plugin description, icon and UI files

We first begin by creating three helper files for our plugin. The first file is called Plugin description file. This file describes our plugin to Anjuta plugin loader. Various plugin meta information are store in this file, including its name and description. Before a plugin is loaded into memory, Anjuta will examine this file and accordingly decide to load it when required.

[Anjuta Plugin]
_Name=Hellow
_Description=An example hello world plugin.
Location=anjuta-hello-world:HelloWorldPlugin
Icon=anjuta-hello-world-plugin.png
			

The first two fields are name and description field. They start with '_', because the fields are translatable. Location field tells where the plugin class is located. It is of the form library:class, where library is the shared library name without the 'lib' prefix and '.so' suffix. class is the plugin class we define. Our plugin library is libanjuta-hello-world.so, so the plugin location would be anjuta-hello-world:HelloWorldPlugin. More details in Plugin description file. Next field 'Icon', gives the name of icon file for our hello world plugin.

Next file is the XML UI definition file. This file describes the UI structure of our plugin and how it should be connected to our action functions. More details in AnjutaUI. The first hello world plugin doesn't use this file, but the second advanced one uses it.

<!--*- xml -*-->
<ui>
  <menubar name="MenuMain">
    <menu name="MenuFile" action="ActionMenuFile">
      <placeholder name="PlaceholderFileMenus">
        <menuitem name="HelloWorldAction" action="ActionFileHelloWorld" />
      </placeholder>
    </menu>
  </menubar>
</ui>
			

The last file is the icon file in PNG format. All these three files are installed in different places. The prefix of their installation should match with that of Anjuta, otherwise Anjuta will not be able to find our plugin. See the section called “Build setup” for installation of these files.