-
Notifications
You must be signed in to change notification settings - Fork 1
How to create an addin
In this example, we'll focus on defining our add-in via assembly versus an XML-manifest.
We'll be taking apart a basic Pomodoro Timer project extends the SystemTray and PropertiesPage extension points.
- Getting Started
- Defining your Add-in
- Mono.Addins.Addin
- Mono.Addins.AddinDependency
- SystemTray ExtensionPoint
- Preferences ExtensionPoint
- Preference Form
- Check-out the ToolsHub project and compile the code
- In the
Addons
folder, create a newClass Library (.NET Framework)
. Here we'll be naming oursPomodoroAddin
. - Set the Build's
Output Path
to the same as ToolsHub's (..\..\..\output\
)- Since our project is immature, you don't get a fancy SDK yet
Let's start by creating a class called, AddinAssembly.cs
// Define our add-in
[assembly: Mono.Addins.Addin(
Namespace = "",
Id = "PomodoroAddin",
Category = "Tools",
CompatVersion = "0.3",
EnabledByDefault = true,
Version = "0.3",
Flags = Mono.Addins.Description.AddinFlags.None,
Url = "https://github.com/xenoinc/ToolsHub")]
// Attach to add-in host
[assembly: Mono.Addins.AddinDependency("XenoInnovations.ToolsHub", "0.3")]
You only need to modify:
Id
Version
EnabledByDefault
Optional arguments:
Flags
Url
Required:
-
CompatVersion
- Current version is,0.3
The only time you'll modify this is if the base version of ToolsHub changes and your add-in needs to support a higher framework version. Currently, we're using 0.3
Create another class called, SysTrayHandler.cs
namespace PomodoroAddin.Handlers
{
using System.Collections.Generic;
using System.Windows.Forms;
using Xeno.ToolsHub.ExtensionModel;
[Mono.Addins.Extension(
NodeName = ExtensionName.SysTrayAddin,
Path = ExtensionPath.SystemTray)]
public class SysTrayHandler : Xeno.ToolsHub.ExtensionModel.SystemTray.SysTrayAddin
{
private PomodoroManager _pomodoro;
public SysTrayHandler()
{
_pomodoro = new PomodoroManager();
this.IsInitialized = true;
}
public override bool IsInitialized { get; }
public override void Initialize()
{
}
public override List<MenuItem> MenuItems()
{
return _pomodoro.MenuItems;
}
}
}
Create a class called, PreferenceHandler
namespace PomodoroAddin.Handlers
{
using System.Windows.Forms;
using PomodoroAddin.Views;
using Xeno.ToolsHub.ExtensionModel;
[Mono.Addins.Extension(
NodeName = ExtensionName.PreferencePageAddin,
Path = ExtensionPath.PreferencePage)]
public class PreferenceHandler : IPreferencePageExtension
{
private PreferencePage _page;
public string Id { get; set; }
public bool IsModified => _page.IsModified;
public Form Page => _page;
public string Title { get { return "Pomodoro"; } }
public void InitializePage()
{
_page = new PreferencePage();
}
public void OnSave()
{
_page.OnSave();
}
}
}
Create a Windows Form called, PreferencePage
which uses the interface, IPreferencePageForm
The IPreferencePageForm
interface - though not required - makes sure that you don't forget anything when starting off.
namespace PomodoroAddin.Views
{
using System;
using System.Windows.Forms;
using Xeno.ToolsHub.ExtensionModel;
using Xeno.ToolsHub.Services;
public partial class PreferencePage : Form, IPreferencePageForm
{
private const string AddinId = "PomodoroTimer";
private const string KeyDuration = "Duration";
private const string KeyShortBreak = "BreakShort";
private const string KeyLongBreak = "BreakLong";
public PreferencePage()
{
InitializeComponent();
TxtDuration.Text = SettingsService.GetInt(AddinId, KeyDuration, 25).ToString();
TxtBreakShort.Text = SettingsService.GetInt(AddinId, KeyShortBreak, 5).ToString();
TxtBreakLong.Text = SettingsService.GetInt(AddinId, KeyLongBreak, 10).ToString();
IsModified = false;
}
public bool IsModified { get; set; }
public bool OnSave()
{
SettingsService.SetValue(AddinId, KeyDuration, TxtDuration.Text);
SettingsService.SetValue(AddinId, KeyShortBreak, TxtBreakShort.Text);
SettingsService.SetValue(AddinId, KeyLongBreak, TxtBreakLong.Text);
return true;
}
private void PreferencePage_Load(object sender, EventArgs e)
{
}
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) &&
!char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
e.Handled = true;
else
IsModified = true;
// Only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
e.Handled = true;
}
}
}
- Home
- ToolsHub Architecture
- Addin ExtensionPoints
- Creating an Add-in
- Design Docs
- Feature Requests
- FAQ