Skip to content

Getting Started: Writing an Addin

Cameron White edited this page Jun 15, 2013 · 5 revisions

This guide will demonstrate how to write a basic add-in.

Create a New Project

In Visual Studio or MonoDevelop, create a new .NET 4.0 Class Library project. Creating a Project

Reference Assemblies

In order to write an add-in, you will need to reference two assemblies:

  • Mono.Addins.dll - this is the framework that Pinta uses to support add-ins.
  • Pinta.Core.dll - this provides access to Pinta's API.

There are several other assemblies that you may want to reference:

  • gdk-sharp.dll
  • glib-sharp.dll
  • gtk-sharp.dll
  • Mono.Cairo.dll

Implement the IExtension Interface

In Pinta, all add-ins implement the IExtension interface. You must provide implementations for two methods: Initialize and Uninitialize. Additionally, you must mark your add-in class with the Mono.Addins.Extension attribute to help Pinta find it.

  • The Initialize method is called when Pinta loads the add-in, and is where you should perform any setup (such as registering an effect).
  • The Uninitialize method is called when the add-in is unloaded (for example, if it is disabled by a user), and is where you should undo any actions that were performed in the Initialize method.
  • You should not perform any initialization in the constructor, as your add-in may be instantiated even if the user has it disabled.

A simple add-in looks like this:

using System;
using Pinta.Core;

namespace MyFirstAddin
{
    [Mono.Addins.Extension]
    public class MyFirstAddin : IExtension
    {
        public void Initialize ()
        {
            System.Console.Out.WriteLine ("Initializing my addin.");
        }

        public void Uninitialize ()
        {
            System.Console.Out.WriteLine ("Uninitializing my addin.");
        }
    }
}

Add-in Information

You will also need to provide some basic information about your add-in so that Pinta can display it in the Add-in Manager dialog. Create a file named .addin.xml, add it to your add-in project, and set its Build Action to Embedded Resource. Creating the .addin.xml file

A simple add-in description looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<Addin id="MyFirstAddin" version="0.1" category="General">
    <Header>
        <Name>My First Add-in</Name>
        <Description>This is my first Pinta add-in!</Description>
        <Author>My Name</Author>
        <Url>https://github.com/MyName/MyFirstAddin</Url>
    </Header>
    <Dependencies>
        <Addin id="Pinta" version="1.5" />
    </Dependencies>
</Addin>
  • Addin takes a unique id for your add-in, a version number for your add-in, and a category. The category is used to group add-ins in the Add-in Manager. Some common categories are: Brushes, Effects, File Formats, Tools, Utilities, and Web.
  • Header contains the information that will be displayed in the Add-in Manager.
  • Name provides a friendly name for your add-in that the user will see.
  • Description provides a useful description so that users know what your add-in does.
  • Author is your name!
  • Url provides a link to the homepage of your add-in's project.
  • Dependencies lets the add-in system know which version of Pinta you require.

Build and Run Your Add-in!

Now, you can compile your add-in and place it in the same directory as the Pinta executable. When you start Pinta, the "Initializing my addin." message should appear in the console, and your add-in should be visible in the Add-in Manager!

Creating a Project