Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 51935d3

Browse files
committed
OnNotification abstraction
1 parent c474f5f commit 51935d3

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Demo Plugin/NppManagedPluginDemo/Demo.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ static internal void SetToolBarIcon()
3535

3636
static internal void OnCharAdded(char newChar)
3737
{
38-
Kbg.Demo.Namespace.Main.doInsertHtmlCloseTag(newChar);
38+
}
39+
40+
public static void OnNotification(SCNotification notification)
41+
{
42+
if (notification.nmhdr.code == (uint)SciMsg.SCN_CHARADDED)
43+
{
44+
Kbg.Demo.Namespace.Main.doInsertHtmlCloseTag((char)notification.Character);
45+
}
3946
}
4047

4148
internal static string PluginName { get { return Kbg.Demo.Namespace.Main.PluginName; }}
@@ -63,6 +70,7 @@ class Main
6370
#endregion
6471

6572
#region " Startup/CleanUp "
73+
6674
static internal void CommandMenuInit()
6775
{
6876
// Initialization of your plugin commands

Visual Studio Project Template C#/Main.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Main
2020
static Bitmap tbBmp_tbTab = Properties.Resources.star_bmp;
2121
static Icon tbIcon = null;
2222

23+
public static void OnNotification(SCNotification notification)
24+
{
25+
}
26+
2327
internal static void CommandMenuInit()
2428
{
2529
StringBuilder sbIniFilePath = new StringBuilder(Win32.MAX_PATH);
@@ -32,6 +36,7 @@ internal static void CommandMenuInit()
3236
PluginBase.SetCommand(0, "MyMenuCommand", myMenuFunction, new ShortcutKey(false, false, false, Keys.None));
3337
PluginBase.SetCommand(1, "MyDockableDialog", myDockableDialog); idMyDlg = 1;
3438
}
39+
3540
internal static void SetToolBarIcon()
3641
{
3742
toolbarIcons tbIcons = new toolbarIcons();
@@ -41,6 +46,7 @@ internal static void SetToolBarIcon()
4146
Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_ADDTOOLBARICON, PluginBase._funcItems.Items[idMyDlg]._cmdID, pTbIcons);
4247
Marshal.FreeHGlobal(pTbIcons);
4348
}
49+
4450
internal static void PluginCleanUp()
4551
{
4652
Win32.WritePrivateProfileString("SomeSection", "SomeKey", someSetting ? "1" : "0", iniFilePath);

Visual Studio Project Template C#/PluginInfrastructure/UnmanagedExports.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ static IntPtr getName()
4545
[DllExport(CallingConvention = CallingConvention.Cdecl)]
4646
static void beNotified(IntPtr notifyCode)
4747
{
48-
SCNotification nc = (SCNotification)Marshal.PtrToStructure(notifyCode, typeof(SCNotification));
49-
if (nc.nmhdr.code == (uint)NppMsg.NPPN_TBMODIFICATION)
48+
SCNotification notification = (SCNotification)Marshal.PtrToStructure(notifyCode, typeof(SCNotification));
49+
if (notification.nmhdr.code == (uint)NppMsg.NPPN_TBMODIFICATION)
5050
{
5151
PluginBase._funcItems.RefreshItems();
5252
Main.SetToolBarIcon();
5353
}
54-
else if (nc.nmhdr.code == (uint)SciMsg.SCN_CHARADDED)
55-
{
56-
Main.OnCharAdded((char)nc.ch);
57-
}
58-
else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN)
54+
else if (notification.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN)
5955
{
6056
Main.PluginCleanUp();
6157
Marshal.FreeHGlobal(_ptrPluginName);
6258
}
59+
else
60+
{
61+
Main.OnNotification(notification);
62+
}
6363
}
6464
}
6565
}

0 commit comments

Comments
 (0)