Skip to content

Commit b5a0968

Browse files
Sébastien GeiserSébastien Geiser
Sébastien Geiser
authored and
Sébastien Geiser
committed
Toolbar icon again
1 parent 34ecb15 commit b5a0968

File tree

9 files changed

+325
-7
lines changed

9 files changed

+325
-7
lines changed

CSharpRegexTools4Npp/CSharpRegexTools4Npp.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
66
<ProductVersion>9.0.21022</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
8+
<LangVersion>9.0</LangVersion>
89
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
910
<OutputType>Library</OutputType>
1011
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -111,6 +112,12 @@
111112
<DesignTime>True</DesignTime>
112113
<DependentUpon>Resources.resx</DependentUpon>
113114
</Compile>
115+
<Compile Include="Res.Designer.cs">
116+
<AutoGen>True</AutoGen>
117+
<DesignTime>True</DesignTime>
118+
<DependentUpon>Res.resx</DependentUpon>
119+
</Compile>
120+
<Compile Include="Resources.Designer.cs" />
114121
<Compile Include="Utils\BEncoding.cs" />
115122
<!-- tests -->
116123
<!-- other utilities -->
@@ -152,10 +159,15 @@
152159
<Generator>PublicResXFileCodeGenerator</Generator>
153160
<LastGenOutput>Resources1.Designer.cs</LastGenOutput>
154161
</EmbeddedResource>
162+
<EmbeddedResource Include="Res.resx">
163+
<Generator>ResXFileCodeGenerator</Generator>
164+
<LastGenOutput>Res.Designer.cs</LastGenOutput>
165+
</EmbeddedResource>
155166
</ItemGroup>
156167
<ItemGroup>
157168
<!-- icons and such -->
158169
<Content Include="Properties\star_bmp.bmp" />
170+
<Resource Include="Resources\Icon.png" />
159171
</ItemGroup>
160172
<ItemGroup>
161173
<ProjectReference Include="..\RegexDialog\RegexDialog.csproj">

CSharpRegexTools4Npp/Main.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using RegexDialog;
55
using System;
66
using System.Diagnostics;
7+
using System.Drawing;
78
using System.IO;
89
using System.Linq;
910
using System.Reflection;
@@ -17,9 +18,13 @@ namespace CSharpRegexTools4Npp
1718
class Main
1819
{
1920
internal const int UNDO_BUFFER_SIZE = 64;
21+
private static int idMyDlg = 0;
2022
internal const string PluginName = "C# Regex Tools 4 Npp";
2123
public static readonly string PluginConfigDirectory = Path.Combine(Npp.Notepad.GetConfigDirectory(), PluginName);
2224
public const string PluginRepository = "https://github.com/codingseb/CSharpRegexTools4Npp";
25+
26+
private static readonly Bitmap tbBmp = Res.Icon;// Resources;
27+
2328
/// <summary>
2429
/// This listens to the message that Notepad++ sends when its UI language is changed.
2530
/// </summary>
@@ -72,9 +77,11 @@ public static void ShowTheDialog()
7277
{
7378
try
7479
{
80+
string dialogTitle = $"C# Regex Tools - {Assembly.GetExecutingAssembly().GetName().Version}";
81+
7582
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = @"plugins\CSharpRegexTools4Npp";
7683

77-
IntPtr hWnd = FindWindow(null, $"C# Regex Tools - {Assembly.GetExecutingAssembly().GetName().Version}");
84+
IntPtr hWnd = FindWindow(null, dialogTitle);
7885

7986
if (hWnd.ToInt64() > 0)
8087
{
@@ -145,7 +152,7 @@ public static void ShowTheDialog()
145152
result = false;
146153
}
147154

148-
hWnd = FindWindow(null, $"C# Regex Tool - {Assembly.GetExecutingAssembly().GetName().Version}");
155+
hWnd = FindWindow(null, dialogTitle);
149156
if (hWnd.ToInt64() > 0)
150157
{
151158
SetForegroundWindow(hWnd);
@@ -161,10 +168,10 @@ public static void ShowTheDialog()
161168

162169
GetCurrentFileName = () => Npp.Notepad.CurrentFileName
163170
};
164-
171+
165172
dialog.Show();
166173

167-
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.MODELESSDIALOGADD, (int)NppMsg.NPPM_MODELESSDIALOG, new WindowInteropHelper(dialog).Handle.ToInt32());
174+
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.MODELESSDIALOGADD, (int)NppMsg.NPPM_MODELESSDIALOG, new WindowInteropHelper(dialog).Handle);
168175
//SetWindowLong(new WindowInteropHelper(dialog).Handle, (int)WindowLongFlags.GWLP_HWNDPARENT, PluginBase.nppData._nppHandle);
169176
SetLayeredWindowAttributes(new WindowInteropHelper(dialog).Handle, 0, 128, LWA_ALPHA);
170177
}
@@ -192,6 +199,26 @@ static internal void PluginCleanUp()
192199
{
193200
}
194201

202+
internal static void SetToolBarIcon()
203+
{
204+
if (!string.IsNullOrEmpty(Npp.Notepad.NppBinVersion)
205+
&& int.TryParse(Npp.Notepad.NppBinVersion.Split('.')[0], out int majorVersion)
206+
&& majorVersion >= 8)
207+
{
208+
ToolbarIcons tbIcons = new()
209+
{
210+
hToolbarBmp = tbBmp.GetHbitmap(),
211+
hToolbarIcon = tbBmp.GetHicon(),
212+
hToolbarIconDarkMode = tbBmp.GetHicon()
213+
};
214+
215+
IntPtr pTbIcons = Marshal.AllocHGlobal(Marshal.SizeOf(tbIcons));
216+
Marshal.StructureToPtr(tbIcons, pTbIcons, false);
217+
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_ADDTOOLBARICON_FORDARKMODE, PluginBase._funcItems.Items[idMyDlg]._cmdID, pTbIcons);
218+
Marshal.FreeHGlobal(pTbIcons);
219+
}
220+
}
221+
195222
/// <summary>
196223
/// open GitHub repo with the web browser
197224
/// </summary>

CSharpRegexTools4Npp/PluginInfrastructure/NotepadPPGateway.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Runtime.InteropServices;
88
using System.Text;
9+
using System.Windows.Interop;
910
using CSharpRegexTools4Npp.PluginInfrastructure;
1011
using CSharpRegexTools4Npp.Utils;
1112

@@ -280,7 +281,7 @@ public int TabCount
280281
}
281282

282283

283-
public void AddToolbarIcon(int funcItemsIndex, toolbarIcons icon)
284+
public void AddToolbarIcon(int funcItemsIndex, ToolbarIcons icon)
284285
{
285286
IntPtr pTbIcons = Marshal.AllocHGlobal(Marshal.SizeOf(icon));
286287
try {
@@ -297,7 +298,7 @@ public void AddToolbarIcon(int funcItemsIndex, toolbarIcons icon)
297298

298299
public void AddToolbarIcon(int funcItemsIndex, Bitmap icon)
299300
{
300-
toolbarIcons tbi = new toolbarIcons
301+
ToolbarIcons tbi = new ToolbarIcons
301302
{
302303
hToolbarBmp = icon.GetHbitmap()
303304
};
@@ -366,6 +367,13 @@ public void ShowDockingForm(System.Windows.Forms.Form form)
366367
0, form.Handle);
367368
}
368369

370+
public void ShowDockingForm(System.Windows.Window window)
371+
{
372+
Win32.SendMessage(PluginBase.nppData._nppHandle,
373+
(uint)(NppMsg.NPPM_DMMSHOW),
374+
0, new WindowInteropHelper(window).Handle);
375+
}
376+
369377
public Color GetDefaultForegroundColor()
370378
{
371379
var rawColor = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR, 0, 0);

CSharpRegexTools4Npp/PluginInfrastructure/NppPluginNETHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public enum DockMgrMsg : uint
192192
}
193193

194194
[StructLayout(LayoutKind.Sequential)]
195-
public struct toolbarIcons
195+
public struct ToolbarIcons
196196
{
197197
public IntPtr hToolbarBmp; // standard icon (color)
198198
public IntPtr hToolbarIcon; // Fluent UI icon (black)

CSharpRegexTools4Npp/PluginInfrastructure/UnmanagedExports.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static void beNotified(IntPtr notifyCode)
5050
if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
5151
{
5252
PluginBase._funcItems.RefreshItems();
53+
Main.SetToolBarIcon();
5354
}
5455
else if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
5556
{

CSharpRegexTools4Npp/Res.Designer.cs

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

CSharpRegexTools4Npp/Res.resx

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121+
<data name="Icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
122+
<value>Resources\Icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
123+
</data>
124+
</root>

0 commit comments

Comments
 (0)