Donate

Add Menu Separator To Notepad++ Using The Notepad++ Plugin Pack In C#

Hello,

I'm currently adding modules to my Notepad++ plugin project and we noticed that the menu items are growing. So our architect suggested that it needs to be grouped and using a line separator for organization and proper grouping. At the moment, the menu itmes for the plugin isn't grouped based from the screenshot below.
Add Menu Separator To Notepad++ Using The Notepad++ Plugin Pack In C#
And here's the C# code to add the menu items.
internal static void CommandMenuInit()
{
	StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);
	Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath);
	iniFilePath = sbIniFilePath.ToString();
	if (!Directory.Exists(iniFilePath)) Directory.CreateDirectory(iniFilePath);
	iniFilePath = Path.Combine(iniFilePath, PluginName + ".ini");
	someSetting = (Win32.GetPrivateProfileInt("SomeSection", "SomeKey", 0, iniFilePath) != 0);

	PluginBase.SetCommand(0, "Session Laws", SessionLaws, new ShortcutKey(false, false, false, Keys.None));
	PluginBase.SetCommand(1, "Session Laws Bckmtr", SessionLawBackMtr, new ShortcutKey(false, false, false, Keys.None));
	PluginBase.SetCommand(2, "Supplement", Supplement, new ShortcutKey(false, false, false, Keys.None));
	PluginBase.SetCommand(3, "Supplement Index", SupplementIndex, new ShortcutKey(false, false, false, Keys.None));

	idMyDlg = 1;
}
So, to add a menu item separator, you need to set the command name of the PluginBase class to "---" in order to add a menu separator. After modifying the code to include the Notepad++ plugin separator as presented below.
internal static void CommandMenuInit()
{
	StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);
	Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETPLUGINSCONFIGDIR, Win32.MAX_PATH, sbIniFilePath);
	iniFilePath = sbIniFilePath.ToString();
	if (!Directory.Exists(iniFilePath)) Directory.CreateDirectory(iniFilePath);
	iniFilePath = Path.Combine(iniFilePath, PluginName + ".ini");
	someSetting = (Win32.GetPrivateProfileInt("SomeSection", "SomeKey", 0, iniFilePath) != 0);

	PluginBase.SetCommand(0, "Session Laws", SessionLaws, new ShortcutKey(false, false, false, Keys.None));
	PluginBase.SetCommand(1, "Session Laws Bckmtr", SessionLawBackMtr, new ShortcutKey(false, false, false, Keys.None));
	PluginBase.SetCommand(2, "---", null);
	PluginBase.SetCommand(3, "Supplement", Supplement, new ShortcutKey(false, false, false, Keys.None));
	PluginBase.SetCommand(4, "Supplement Index", SupplementIndex, new ShortcutKey(false, false, false, Keys.None));

	idMyDlg = 1;
}
The items are now grouped according to it's functionality.
Add Menu Separator To Notepad++ Using The Notepad++ Plugin Pack In C#


Cheers!

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input