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

Commit ab70481

Browse files
authored
Merge branch 'master' into apply_dark_mode_to_arbitrary_controls
2 parents 7e673e5 + 4f7a4d4 commit ab70481

File tree

7 files changed

+103
-13
lines changed

7 files changed

+103
-13
lines changed

Demo Plugin/NppManagedPluginDemo/Demo.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ static internal void CommandMenuInit()
144144
PluginBase.SetCommand(16, "---", null);
145145

146146
PluginBase.SetCommand(17, "Print Scroll and Row Information", PrintScrollInformation);
147+
148+
PluginBase.SetCommand(18, "Use NanInf class for -inf, inf, nan!!", PrintNanInf);
147149
}
148150

149151
/// <summary>
@@ -550,6 +552,21 @@ static void DockableDlgDemo()
550552
ToggleDarkMode(frmGoToLine, notepad.IsDarkModeEnabled());
551553
frmGoToLine.textBox1.Focus();
552554
}
555+
556+
static void PrintNanInf()
557+
{
558+
bool neginf_correct = double.IsNegativeInfinity(NanInf.neginf);
559+
bool inf_correct = double.IsPositiveInfinity(NanInf.inf);
560+
bool nan_correct = double.IsNaN(NanInf.nan);
561+
string naninf = $@"-infinity == NanInf.neginf: {neginf_correct}
562+
infinity == NanInf.inf: {inf_correct}
563+
NaN == NanInf.nan: {nan_correct}
564+
If you want these constants in your plugin, you can find them in the NanInf class in PluginInfrastructure.
565+
DO NOT USE double.PositiveInfinity, double.NegativeInfinity, or double.NaN.
566+
You will get a compiler error if you do.";
567+
notepad.FileNew();
568+
editor.AppendTextAndMoveCursor(naninf);
569+
}
553570
#endregion
554571
}
555572
}

Demo Plugin/NppManagedPluginDemo/NppManagedPluginDemo.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
<Compile Include="Forms\DarkModeTestForm.Designer.cs">
124124
<DependentUpon>DarkModeTestForm.cs</DependentUpon>
125125
</Compile>
126+
<Compile Include="..\..\Visual Studio Project Template C#\PluginInfrastructure\NanInf.cs">
127+
<Link>PluginInfrastructure\NanInf.cs</Link>
128+
</Compile>
126129
<Compile Include="Forms\frmGoToLine.cs">
127130
<SubType>Form</SubType>
128131
</Compile>

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">
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Kbg.NppPluginNET.PluginInfrastructure
2+
{
3+
/// <summary>
4+
/// holds NaN, Infinity, and -Infinity as things generated at runtime<br></br>
5+
/// because the compiler freaks out if it sees any of<br></br>
6+
/// double.NegativeInfinity, double.PositiveInfinity, or double.NaN<br></br>
7+
/// or any statically analyzed function of two constants that makes one of those constants<br></br>
8+
/// like 1d/0d, 0d/0d, or -1d/0d.
9+
/// </summary>
10+
public class NanInf
11+
{
12+
/// <summary>
13+
/// a/b<br></br>
14+
/// may be necessary to generate infinity or nan at runtime
15+
/// to avoid the compiler pre-computing things<br></br>
16+
/// since if the compiler sees literal 1d/0d in the code
17+
/// it just pre-computes it at compile time
18+
/// </summary>
19+
/// <param name="a"></param>
20+
/// <param name="b"></param>
21+
/// <returns></returns>
22+
public static double Divide(double a, double b) { return a / b; }
23+
24+
public static readonly double inf = Divide(1d, 0d);
25+
public static readonly double neginf = Divide(-1d, 0d);
26+
public static readonly double nan = Divide(0d, 0d);
27+
}
28+
}

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)