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

Commit 4425137

Browse files
authored
Merge pull request #108 from BdR76/master
Support for Fluent UI icons in template
2 parents b588f00 + c015681 commit 4425137

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

Visual Studio Project Template C#/Main.cs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ class Main
1616
static bool someSetting = false;
1717
static frmMyDlg frmMyDlg = null;
1818
static int idMyDlg = -1;
19-
static Bitmap tbBmp = Properties.Resources.star;
20-
static Bitmap tbBmp_tbTab = Properties.Resources.star_bmp;
19+
20+
// toolbar icons
21+
static Bitmap tbBmp_color = Properties.Resources.star; // standard icon small color
22+
static Icon tbIco_black = Properties.Resources.star_black; // Fluent UI icon black
23+
static Icon tbIco_white = Properties.Resources.star_white; // Fluent UI icon white
2124
static Icon tbIcon = null;
2225

2326
public static void OnNotification(ScNotification notification)
@@ -47,14 +50,25 @@ internal static void CommandMenuInit()
4750

4851
internal static void SetToolBarIcon()
4952
{
53+
// create struct
5054
toolbarIcons tbIcons = new toolbarIcons();
51-
tbIcons.hToolbarBmp = tbBmp.GetHbitmap();
55+
56+
// add bmp icon
57+
tbIcons.hToolbarBmp = tbBmp_color.GetHbitmap();
58+
tbIcons.hToolbarIcon = tbIco_black.Handle; // icon with black lines
59+
tbIcons.hToolbarIconDarkMode = tbIco_white.Handle; // icon with light grey lines
60+
61+
// convert to c++ pointer
5262
IntPtr pTbIcons = Marshal.AllocHGlobal(Marshal.SizeOf(tbIcons));
5363
Marshal.StructureToPtr(tbIcons, pTbIcons, false);
54-
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_ADDTOOLBARICON, PluginBase._funcItems.Items[idMyDlg]._cmdID, pTbIcons);
64+
65+
// call Notepad++ api
66+
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_ADDTOOLBARICON_FORDARKMODE, PluginBase._funcItems.Items[idMyDlg]._cmdID, pTbIcons);
67+
68+
// release pointer
5569
Marshal.FreeHGlobal(pTbIcons);
5670
}
57-
71+
5872
internal static void PluginCleanUp()
5973
{
6074
Win32.WritePrivateProfileString("SomeSection", "SomeKey", someSetting ? "1" : "0", iniFilePath);
@@ -70,8 +84,10 @@ internal static void myDockableDialog()
7084
{
7185
if (frmMyDlg == null)
7286
{
87+
// show dialog for first time
7388
frmMyDlg = new frmMyDlg();
7489

90+
// icon
7591
using (Bitmap newBmp = new Bitmap(16, 16))
7692
{
7793
Graphics g = Graphics.FromImage(newBmp);
@@ -81,17 +97,21 @@ internal static void myDockableDialog()
8197
colorMap[0].NewColor = Color.FromKnownColor(KnownColor.ButtonFace);
8298
ImageAttributes attr = new ImageAttributes();
8399
attr.SetRemapTable(colorMap);
84-
g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
100+
g.DrawImage(tbBmp_color, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
85101
tbIcon = Icon.FromHandle(newBmp.GetHicon());
86102
}
87103

88-
NppTbData _nppTbData = new NppTbData();
89-
_nppTbData.hClient = frmMyDlg.Handle;
90-
_nppTbData.pszName = "My dockable dialog";
91-
_nppTbData.dlgID = idMyDlg;
92-
_nppTbData.uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
93-
_nppTbData.hIconTab = (uint)tbIcon.Handle;
94-
_nppTbData.pszModuleName = PluginName;
104+
// dockable window struct data
105+
var _nppTbData = new NppTbData
106+
{
107+
hClient = frmMyDlg.Handle,
108+
pszName = "My dockable dialog",
109+
dlgID = idMyDlg,
110+
uMask = NppTbMsg.DWS_DF_CONT_RIGHT | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR,
111+
hIconTab = (uint)tbIcon.Handle,
112+
pszModuleName = PluginName
113+
};
114+
95115
IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
96116
Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);
97117

Visual Studio Project Template C#/NppPlugin.vstemplate

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<ProjectItem ReplaceParameters="false" TargetFileName="Resources.resx">Resources.resx</ProjectItem>
3333
<ProjectItem ReplaceParameters="false" TargetFileName="star.png">star.png</ProjectItem>
3434
<ProjectItem ReplaceParameters="false" TargetFileName="star_bmp.bmp">star_bmp.bmp</ProjectItem>
35+
<ProjectItem ReplaceParameters="false" TargetFileName="star_black.ico">star_black.ico</ProjectItem>
36+
<ProjectItem ReplaceParameters="false" TargetFileName="star_white.ico">star_white.ico</ProjectItem>
3537
</Folder>
3638
<Folder Name="PluginInfrastructure" TargetFolderName="PluginInfrastructure">
3739
<Folder Name="DllExport" TargetFolderName="DllExport">

Visual Studio Project Template C#/Properties/Resources.Designer.cs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Visual Studio Project Template C#/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,10 @@
124124
<data name="star_bmp" type="System.Resources.ResXFileRef, System.Windows.Forms">
125125
<value>star_bmp.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126126
</data>
127+
<data name="star_black" type="System.Resources.ResXFileRef, System.Windows.Forms">
128+
<value>star_black.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
129+
</data>
130+
<data name="star_white" type="System.Resources.ResXFileRef, System.Windows.Forms">
131+
<value>star_white.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
132+
</data>
127133
</root>

0 commit comments

Comments
 (0)