Hello world plugin: Anjuta Developers Reference Manual

## Hello world plugin

This plugin does nothing other then displaying "Hello World Plugin!!" widget. The widget is added to Shell and appear as separate window. You can drag the widget and dock it various ways. This section is meant to give a quick look at how plugins are derived from AnjutaPlugin base class. Most of the things will be explained in the section called “Hello world advanced plugin”. First the plugin class is derived from the abstract class and two virtual methods activate() and deactivate() are implemented. In activate() method, we are create a label and add it to shell. Consequently, we also remove this widget in deactivate() call.

    #include <libanjuta/anjuta-plugin.h>

    typedef struct {
    	AnjutaPlugin parent;

    	/* Hello world widget */
    	GtkWidget *widget;

    } HelloWorldPlugin;

    typedef struct {
    	AnjutaPluginClass parent_class;
    } HelloWorldPluginClass;

    static gboolean
    activate_plugin (AnjutaPlugin *plugin)
    {
    	HelloWorldPlugin *hello_plugin = (HelloWorldPlugin*) plugin;

    	/* Create hello plugin widget */
    	hello_plugin->widget = gtk_label_new ("Hello World Plugin!!");

    	/* Add widget in Shell. Any number of widgets can be added */
    	anjuta_shell_add_widget (plugin->shell, hello_plugin->widget,
    	                         "AnjutaHelloWorldPlugin",
    	                         _("Hello world plugin"),
    	                         GTK_STOCK_ABOUT,
    	                         ANJUTA_SHELL_PLACEMENT_CENTER,
    	                         NULL);

    	return TRUE; /* FALSE if activation failed */
    }

    static gboolean
    deactivate_plugin (AnjutaPlugin *plugin)
    {
    	HelloWorldPlugin *hello_plugin = (HelloWorldPlugin*) plugin;

    	/* Remove widgets from Shell */
    	anjuta_shell_remove_widget (plugin->shell, hello_plugin->widget, NULL);

    	return TRUE; /* FALSE if plugin doesn't want to deactivate */
    }

    static void
    hello_world_plugin_instance_init (GObject *obj)
    {
    }

    static void
    hello_world_plugin_class_init (GObjectClass *klass)
    {
    	AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
    	plugin_class->activate = activate_plugin;
    	plugin_class->deactivate = deactivate_plugin;
    }

    ANJUTA_PLUGIN_BOILERPLATE (HelloWorldPlugin, hello_world_plugin);
    ANJUTA_SIMPLE_PLUGIN (HelloWorldPlugin, hello_world_plugin);