Plug-ins

Table of Contents :

With Plug-ins you can extend Notepad X to do almost anything. Plug-ins are written with C# or Visual Basic .Net and compiled to .dll Class Library Files.

Installing

To install a plug-in copy your .dll plug-in file with all his decency files, to “Plugins” directory located at Notepad X root path (usually C:\Program Files\Notepad X)

Then to activate it launch Notepad X , open the Options Dialog from Main Menu (Tools -> Options) , then select the Plug-ins tab, your plug-in will appear automatically at the list located bellow if it’s compatible. To Activate click the check box of your item , or select your item and press the Activate Button, then press the apply button to apply your changes.

Removing

To deactivate a plug in launch Notepad X , open the Options Dialog from Main Menu (Tools -> Options) , then select the Plug-ins tab. Uncheck the check box of your item , or select your item and press the Deactivate Button, then press the apply button to apply your changes.

To remove a plug-in delete your .dll plug-in file with all his decency files, from “Plugins” directory located at Notepad X root path (usually C:\Program Files\Notepad X)

Developing

Before you develop a plug-in you have to :

You can develop using C# or Visual Basic.Net  language, we recommend the use of C# because Notepad X is developed with it. Notepad X plug-ins code can use most of  Notepad X  Main form items and attributes so your plug-ins can change completely the application including new features or change something you don’t like.

Creating sample plug-in with C#
In this sample I will demonstrate the basic setup of a plug-in using C#, I use Microsoft Visual C# 2008, if you use an newer version the steps will be exactly the same, if you use an older version you might ignore few steps and finally if you use SharpDevelop every step is the same with some little changes.


1.

Create a new C# Project (or Solution), type of  Class Library



2.

Notepad X is using .Net 2.0 framework this makes it more compatible instead of .Net 3 or 3.5, so to maintain the compatibility you have to switch you project framework to 2.0 , if you using Visual C# 2005 skip this step.
First save your project and then open the project properties dialog, by click at the main menu Projects ->Project Properties (Project -> Project Options for SD) , or at the Solution Explorer (Project for SD) panel and right click at your project and click properties.Then at the Target Framework drop down choose “.Net Framework 2.0″ (for SD select the Compiling Tab and then choose “.Net Framework 2.0″ at Target Framework drop down), close the properties and then save the project, notice that some incompatible framework references are highlighted (System.Data.DataSetExtensions and System.Xml.Linq)(System.Core and System.Xml.Linq for SD) , from Solution Explorer (Project for SD) panel at the references right these references and click and remove them.



3.

Now we have to import Notepad X reference, at the main menu click Projects -> Add Projects or from Solution Explorer (Project for SD) panel at the references right click and select Add References.
Select the Browse tab (.Net Assembly for SD) and browse to Notepad X root directory (usually C:\Program Files\Notepad X) and select “Notepad X.exe” to import it. Also import System.Drawing and System.Windows.Forms references from .Net tab (GAC for SD) or import any other any time you need it.



4.

Open your main class (usually Class1.cs or MyClass.Cs for SD). At the top import your namespaces from the Notepad X reference

using Notepad_X;
using Notepad_X.Plugin

you can ignore this if but you must use Notepad_X or Notepad_X.Plugin each time you want something from Notepad X.



5.

After your class declaration (also make sure it’s public) write : IPlugin
like this :

public class Class1  : IPlugin

IPlugin Class for (Notepad_X.Plugin) class is an interface that we use to create plug-ins , to make this plug-in work you class must implement the IPlugin interface.
To make this inside your class write this sample code :

        public string Name
        {
            get
            { return "Sample Plug In"; }
        }
        public string Author
        {
            get
            { return "You Name"; }
        }
        public string Description
        {
            get
            { return "You Description"; }
        }
        public string Version
        {
            get
            { return "0.1"; }
        }

        public void Initialize()
        {
        }
        public void Dispose()
        {
        }

The Name, Author, Description and Version return the basic information required from our plug-in.
The Initialize method is the method which is running from Notepad X when our plug-in is created;
The Dispose method is the method which is running from Notepad X when our plug-in is closing, here you must write the removal code for any of you objects.



6.

Now for our we will create a Menu item and put it into Notepad X main menu.
First import System.Windows.Forms reference if you didn’t. (You can import the System.Windows.Forms namespace)
Change our Initialize() and Dispose() code with this

        System.Windows.Forms.ToolStripMenuItem menuItem; // Our menu Item
        Main main; // Notepad X Main form
        public void Initialize()
        {
            main= Notepad_X.Static.MainInstance;
            menuItem = new System.Windows.Forms.ToolStripMenuItem();
            menuItem.Name = "SamplePlugIn_Test";
            menuItem.Text = "Test";
            menuItem.Click += handler_menuItem;
            main.Menu_.Items.Add(menuItem);

        }
        private void handler_menuItem(object sender, EventArgs e)
        {
            System.Windows.Forms.MessageBox.Show("It works");
        }
        public void Dispose()
        {
            main.Menu_.Items.Remove(menuItem);
        }

By this we initialized our Main form instance using the main as variable so we can access it later. Then we created an ToolStripMenuItem created an click handler for it and put it into the Notepad X main menu, and the Dispose() will remove our item.



7.

Now save our project and then Build it, to test it copy the .dll file we build from Build directory and follow the Installing Plug-ins