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

Commit d69d2c0

Browse files
committed
CheckMenuItem toggle checkmark on/off
CheckMenuItem toggle checkmark on/off as a function, so it can be reused for multiple menu items
1 parent e0c80f0 commit d69d2c0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Demo Plugin/NppManagedPluginDemo/Demo.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,7 @@ static void insertDateTime(bool longFormat)
274274

275275
static void checkInsertHtmlCloseTag()
276276
{
277-
doCloseTag = !doCloseTag;
278-
279-
int i = Win32.CheckMenuItem(Win32.GetMenu(PluginBase.nppData._nppHandle), PluginBase._funcItems.Items[9]._cmdID,
280-
Win32.MF_BYCOMMAND | (doCloseTag ? Win32.MF_CHECKED : Win32.MF_UNCHECKED));
277+
PluginBase.CheckMenuItemToggle(9, ref doCloseTag); // 9 = menu item index
281278
}
282279

283280
static Regex regex = new Regex(@"[\._\-:\w]", RegexOptions.Compiled);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ internal static void SetCommand(int index, string commandName, NppFuncItemDelega
3636
_funcItems.Add(funcItem);
3737
}
3838

39+
// menuitem with checkmark, toggle visible checkmark on/off
40+
internal static void CheckMenuItemToggle(int idx, ref bool value)
41+
{
42+
// toggle value
43+
value = !value;
44+
45+
Win32.CheckMenuItem(Win32.GetMenu(nppData._nppHandle), _funcItems.Items[idx]._cmdID, Win32.MF_BYCOMMAND | (value ? Win32.MF_CHECKED : Win32.MF_UNCHECKED));
46+
}
47+
3948
internal static IntPtr GetCurrentScintilla()
4049
{
4150
int curScintilla;

0 commit comments

Comments
 (0)