This is a template for Notepad++ plugins written in C#. The vast majority of the code (certainly all the parts that were really hard to implement) come from kbilsted's now-archived NotepadPlusPlusPluginPack.Net, with some significant changes, including:
- A simpler architecture in which the PluginInfrastructure folder is side-by-side with the rest of the plugin's code, rather than in a separate directory tree.
- An example of a non-docking (pop-up) dialog opened from the plugin menu, a docking form, and a non-docking non-pop-up form.
- A settings form that makes it easy for the maintainer to add, remove or edit settings.
- A template for automated tests that can be run inside Notepad++, including a template for user interface tests that automatically test forms.
If you have any issues, see if updating to the latest release helps, and then feel free to raise an issue on GitHub. Please be sure to include diagnostic information about your system, Notepad++ version, and plugin version (go to ?->Debug Info... from the Notepad++ main menu).
Read information about the plugin architecture (some of this may be out of date)
- Download the source code in one of the following ways:
- clone the repository
- download the source code for the repo, then create a git repo inside
- fork this repo
- download the source code for a release (see the Releases page)
- Open NppCSharpPluginPack/NppCSharpPluginPack.sln in Visual Studio 2022
- Configure the security settings of
%ProgramFiles%/Notepad++/pluginsso that Visual Studio can write to%ProgramFiles%/Notepad++/plugins/CSharpPluginPack. I do this in the following way:- Open
%ProgramFiles%/Notepad++in the File Explorer. - Right-click on the
pluginsfolder. - Choose
Propertiesfrom the drop-down menu - Select the
Securitytab. - Click the
Edit...checkbox - Select
Usersfrom theGroup or user namesmenu, then click the checkbox in theFull Controlrow of theAllowcolumn. - Click the
Applybutton.
- Open
- Try building the project using Visual Studio using
x64build target (this build for 64-bit Notepad++). You will know that the project is working correctly when Notepad++ starts up, andCSharpPluginPackappears on the list of plugins. - Try changing the assembly version in NppCSharpPluginPack/Properties/AssemblyInfo.cs to
1.0.3.0. - Try building the project again, then select
Plugins->CSharpPluginPack->Aboutfrom the Notepad++ dropdown menu. The title of the about form should readNppCSharpPluginPack v1.0.3. If it does not, your project is not building correctly. - Copy the
testfilesdirectory of the repo to the%ProgramFiles%/Notepad++/plugins/CSharpPluginPackdirectory. Note: this step is not necessary starting in v0.0.3.20, because that is the first version that automatically syncs thetestfilesdirectory in the repo with thetestfilesdirectory in the directory targeted by the build process. - Run the tests. The third line of the test results file should read
No tests failed. If you seeTests failed: Performance of somethingon the third line, that's because you forgot step 7. - To test your project for 32-bit Notepad++, repeat steps 3-8 for
%ProgramFiles (x86)%/Notepad++/pluginsand change your build target tox86.
This plugin is verified to work on versions of Notepad++ as old as v7.3.3, but it may have some bugs (see the CHANGELOG to see the what bugs may still exist).
It has also been tested and verified to work normally on the newest versions of Notepad++, v8.8.1.
Every version of the template works on Windows 10 May 2019 update or later, or you must install .NET Framework 4.8.
If you are interested in helping users of your plugin who don't speak English, this plugin pack makes it easy to translate your plugin to other languages beginning in v0.0.3.7.
Translator.cs infers your preferred language and attempts to translate in the following way:
- It first attempts to use NPPM_GETNATIVELANGFILENAME (introduced in Notepad++ 8.7) to get the name of the Notepad++ UI language.
- If step 1 fails, it checks your Notepad++
nativeLang.xmlconfig file (at XPath path/NotepadPlus/Native-Langue/@name) to determine what language you prefer to use, and setslowerEnglishNameto the appropriate value and skips to step 3. For example, if this file saysgalician, we will attempt to translate your plugin togalician. If the Notepad++ native language isenglishor if your plugin does not have a translation file for the Notepad++ native language,Translator.csthen does the following: - If steps 1 and 2 fail and the
CHECK_WINDOWS_CULTUREflag is set totrue(it isfalseby default),Translator.cslooks up yourcurrent culture(which can be checked using theget-culturecommand in Powershell).- Next, we find the
EnglishNameproperty of thecurrent culture(which can be found by the$foo = get-culture; $foo.EnglishNamecommand in Powershell), take the first word, and convert it to lowercase, and setlowerEnglishNameto this.- Example: the
EnglishNameof theen-usculture isEnglish (United States), solowerEnglishNameisenglish - Example: the
EnglishNameof theit-itculture isItalian (Italy), solowerEnglishNameisitalian
- Example: the
- Next, we find the
Translator.csthen does one of the following:- If
lowerEnglishNameisenglish, it does nothing (because the plugin is naturally in English) - Otherwise, it looks in the
translationsubdirectory of theCSharpPluginPackplugin folder (whereCSharpPluginPack.dlllives) for a file named{lowerEnglishName}.json5 - NOTE: because the translation files are in a subdirectory of the plugin folder, translation does not work for versions of Notepad++ older than version 8, since those older versions do not have separate folders for each plugin.
- If
- If
Translator.csfoundtranslation\{lowerEnglishName}.json5, it attempts to parse the file. If parsing fails, a message box will appear warning the user of this.- If no translation file was found, or if parsing failed, the default English will be used.
- If parsing was successful,
Translator.cswill use the translation file as described below.
When the user changes their Notepad++ UI language, the plugin will respond to this change as follows (according to the version number of NppCSharpPluginPack):
| CSharpPluginPack version | Translation at startup | Translation possible (but slow) as soon as user changes their preference | Translation guaranteed when user changes their preference |
|---|---|---|---|
| v0.0.3.7 to 0.0.3.10 | YES | NO | NO |
| v0.0.3.11 | YES | YES | NO |
| v0.0.3.14 or higher | YES | YES | YES (only for Notepad++ 8.7 or higher) |
To translate your plugin to another language, just look at english.json5 in the translations directory of this repo and follow the instructions in that file.
Currently NppCSharpPluginPack has been translated into the following languages:
| Language | First version with translation | Translator(s) | Translator is native speaker? |
|---|---|---|---|
| Spanish | v3.7 | molsonkiko | NO |
The following aspects of NppCSharpPluginPack can be translated:
- Forms (including all controls and items in drop-down menus) (see the
TranslateFormmethod inTranslator.cs) - Items in the NppCSharpPluginPack sub-menu of the Notepad++ Plugins menu (see the
GetTranslatedMenuItemmethod inTranslator.cs) - The descriptions of settings in the
CSharpPluginPack.iniconfig file and settings form (see theTranslateSettingsDescriptionmethod inTranslator.cs) - Message boxes (includes warnings, errors, requests for confirmation) (see the
ShowTranslatedMessageBoxmethod inTranslator.cs)
The following aspects of NppCSharpPluginPack may eventually be translated:
- This documentation
- The messages of user-defined exceptions (for example, if your plugin
FooHasNoBarException, there is currently no way to translate the message that the user sees when this error is thrown and caught) - Generic modal dialogs (for example, file-opening dialogs, directory selection dialogs)
- Kasper B. Graversen for creating the plugin pack that this is based on.
- jokedst for making the CsvQuery plugin to which I owe the original ideas behind my settings form and my adaptive styling of forms.
- And of course, Don Ho for creating Notepad++!