Skip to content

Commit

Permalink
Dark mode icons now work
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Wennergren committed Aug 26, 2021
1 parent b04d089 commit fbad87c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CsvQuery/CsvQuery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@
<Content Include="CsharpSqlite\License-CsharpSqlite-MIT.txt" />
<Content Include="Properties\CsvQueryIcon.ico" />
<Content Include="Properties\CSVQueryIcon.png" />
<None Include="Resources\CQIcon.ico" />
<None Include="Properties\CsvQueryIconLight.ico" />
<None Include="Properties\CsvQueryIconDark.ico" />
<None Include="License.txt" />
<None Include="gpl-3.0.txt" />
<None Include="packages.config" />
Expand Down
49 changes: 31 additions & 18 deletions CsvQuery/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void OnNotification(ScNotification notification)

public static void CommandMenuInit()
{
PluginBase.AddMenuItem("Toggle query window", ToggleQueryWindow, false, new ShortcutKey(true, true, false, Keys.C));
PluginBase.AddMenuItem("Toggle CSV Query window", ToggleQueryWindow, false, new ShortcutKey(true, true, false, Keys.C));
PluginBase.AddMenuItem("Manual parse settings", ParseWithManualSettings);
PluginBase.AddMenuItem("List parsed files", ListSqliteTables);
PluginBase.AddMenuItem("---", null);
Expand Down Expand Up @@ -155,22 +155,35 @@ private static void ParseWithManualSettings()

public static void SetToolBarIcon()
{
var icons = new toolbarIcons { hToolbarBmp = Resources.cq.GetHbitmap() };
using (var iconPointer = new TemporaryPointer(icons))
if (NotepadPPGateway.GetNppMajorVersion() < 8)
{
Win32.SendMessage(PluginBase.nppData._nppHandle,
(uint)NppMsg.NPPM_ADDTOOLBARICON,
PluginBase.GetMenuItemId("Toggle query window"),
iconPointer.Pointer);
// Old way - for backwards compatibility to Npp before 8.0
var icons = new toolbarIcons { hToolbarBmp = Resources.cq.GetHbitmap() };
using (var iconPointer = new TemporaryPointer(icons))
{
Win32.SendMessage(PluginBase.nppData._nppHandle,
(uint)NppMsg.NPPM_ADDTOOLBARICON,
PluginBase.GetMenuItemId("Toggle CSV Query window"),
iconPointer.Pointer);
}
}
else
{
// New way - for 8.0 and up (dark mode support)
var icons2 = new toolbarIconsWithDarkMode
{
hToolbarBmp = Resources.cq.GetHbitmap(),
hToolbarIcon = Resources.CsvQueryIconLight.Handle,
hToolbarIconDarkMode = Resources.CsvQueryIconDark.Handle,
};
using (var iconPointer = new TemporaryPointer(icons2))
{
Win32.SendMessage(PluginBase.nppData._nppHandle,
(uint)NppMsg.NPPM_ADDTOOLBARICON_FORDARKMODE,
PluginBase.GetMenuItemId("Toggle CSV Query window"),
iconPointer.Pointer);
}
}

//var iconPointer = Marshal.AllocHGlobal(Marshal.SizeOf(icons));
//Marshal.StructureToPtr(icons, iconPointer, false);
//Win32.SendMessage(PluginBase.nppData._nppHandle,
// (uint)NppMsg.NPPM_ADDTOOLBARICON,
// PluginBase.GetMenuItemId("Toggle query window"),
// iconPointer);
//Marshal.FreeHGlobal(iconPointer);
}

public static void PluginCleanUp()
Expand Down Expand Up @@ -322,7 +335,7 @@ public static void QueryWindowVisible(bool? show = null, bool supressAnalysis =
{
hClient = QueryWindow.Handle,
pszName = "CSV Query",
dlgID = PluginBase.GetMenuItemId("Toggle query window"),
dlgID = PluginBase.GetMenuItemId("Toggle CSV Query window"),
uMask = NppTbMsg.DWS_DF_CONT_BOTTOM | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR,
hIconTab = (uint) queryWindowIcon.Handle,
pszModuleName = PluginName
Expand All @@ -342,7 +355,7 @@ public static void QueryWindowVisible(bool? show = null, bool supressAnalysis =
{
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMSHOW, 0, QueryWindow.Handle);
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SETMENUITEMCHECK,
PluginBase.GetMenuItemId("Toggle query window"),
PluginBase.GetMenuItemId("Toggle CSV Query window"),
1);
}
else
Expand All @@ -351,7 +364,7 @@ public static void QueryWindowVisible(bool? show = null, bool supressAnalysis =
0, QueryWindow.Handle);
Win32.SendMessage(PluginBase.nppData._nppHandle,
(uint)NppMsg.NPPM_SETMENUITEMCHECK,
PluginBase.GetMenuItemId("Toggle query window"), 0);
PluginBase.GetMenuItemId("Toggle CSV Query window"), 0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportTask" AssemblyFile="NppPlugin.DllExport.MSBuild.dll"/>
<Target Name="AfterBuild" DependsOnTargets="GetFrameworkPaths">
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NppPlugin.DllExport.MSBuild.DllExportTask"
AssemblyFile="NppPlugin.DllExport.MSBuild.dll"/>
<Target Name="AfterBuild"
DependsOnTargets="GetFrameworkPaths"
>
<PropertyGroup>
<!-- LibToolPath is optional - it's needed to debug C++, but you can still debug the C# code without it
If you don't have the C++ toolchain installed this is missing, but then you can't' debug C++ anyway -->
<LibToolPath Condition="Exists('$(DevEnvDir)\..\..\VC\bin')">$(DevEnvDir)\..\..\VC\bin</LibToolPath>
</PropertyGroup>
<DllExportTask Platform="$(Platform)"
PlatformTarget="$(PlatformTarget)"
CpuType="$(CpuType)"
Expand All @@ -13,20 +22,25 @@
ProjectDirectory="$(MSBuildProjectDirectory)"
InputFileName="$(TargetPath)"
FrameworkPath="$(TargetedFrameworkDir);$(TargetFrameworkDirectory)"
LibToolPath="$(DevEnvDir)..\..\SDK\ScopeCppSDK\VC\bin"
LibToolPath="$(LibToolPath)"
LibToolDllPath="$(DevEnvDir)"
SdkPath="$(SDK40ToolsPath)"/>

<!-- $(MSBuildProgramFiles32) points to the 32 bit program files dir.
On 32 bit windows usually C:\Program Files\
On 64 bit windows usually C:\Program Files (x86)\
$(ProgramW6432) points to the 64bit Program Files (on 32 bit windows it is blank) -->
<MakeDir Directories="$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\" Condition="Exists('$(MSBuildProgramFiles32)\Notepad++\plugins\') AND !Exists('$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x86'" />
<Copy
SourceFiles="$(TargetPath)"
DestinationFolder="C:\Program Files (x86)\Notepad++\plugins\CsvQuery\"
Condition="Exists('C:\Program Files (x86)\Notepad++\plugins\CsvQuery\') AND '$(PlatformTarget)' == 'x86' AND '$(Configuration)' != 'Test'"
DestinationFolder="$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\"
Condition="Exists('$(MSBuildProgramFiles32)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x86'"
ContinueOnError="false" />

<MakeDir Directories="$(ProgramW6432)\Notepad++\plugins\$(TargetName)\" Condition="Exists('$(ProgramW6432)\Notepad++\plugins\') AND !Exists('$(ProgramW6432)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x64'" />
<Copy
SourceFiles="$(TargetPath)"
DestinationFolder="C:\Program Files\Notepad++\plugins\CsvQuery\"
Condition="Exists('C:\Program Files\Notepad++\plugins\CsvQuery\') AND '$(PlatformTarget)' == 'x64' AND '$(Configuration)' != 'Test'"
DestinationFolder="$(ProgramW6432)\Notepad++\plugins\$(TargetName)\"
Condition="Exists('$(ProgramW6432)\Notepad++\plugins\$(TargetName)\') AND '$(Platform)'=='x64'"
ContinueOnError="false" />
</Target>
</Project>
8 changes: 8 additions & 0 deletions CsvQuery/PluginInfrastructure/Msgs_h.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@ public enum NppMsg : uint
/// </summary>
NPPM_SAVEFILE = Constants.NPPMSG + 94,

/// <summary>
/// VOID NPPM_ADDTOOLBARICON_FORDARKMODE(UINT funcItem[X]._cmdID, toolbarIconsWithDarkMode iconHandles)
/// Use NPPM_ADDTOOLBARICON_FORDARKMODE instead obsolete NPPM_ADDTOOLBARICON which doesn't support the dark mode
/// 2 formats / 3 icons are needed: 1 * BMP + 2 * ICO
/// All 3 handles below should be set so the icon will be displayed correctly if toolbar icon sets are changed by users, also in dark mode
/// </summary>
NPPM_ADDTOOLBARICON_FORDARKMODE = Constants.NPPMSG + 101,

RUNCOMMAND_USER = Constants.WM_USER + 3000,
NPPM_GETFULLCURRENTPATH = RUNCOMMAND_USER + FULL_CURRENT_PATH,
NPPM_GETCURRENTDIRECTORY = RUNCOMMAND_USER + CURRENT_DIRECTORY,
Expand Down
6 changes: 6 additions & 0 deletions CsvQuery/PluginInfrastructure/NotepadPPGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public static IntPtr GetCurrentBufferId()
return Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTBUFFERID, Unused, Unused);
}

public static int GetNppMajorVersion()
{
var version = Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNPPVERSION, Unused, Unused).ToInt32();
return version >> 16;
}

public void OpenFileInNpp(string filename)
{
// NPPM_DOOPEN
Expand Down
Binary file modified CsvQuery/Properties/CSVQueryIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CsvQuery/Properties/CsvQueryIconDark.ico
Binary file not shown.
Binary file added CsvQuery/Properties/CsvQueryIconLight.ico
Binary file not shown.
16 changes: 13 additions & 3 deletions CsvQuery/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions CsvQuery/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@
<data name="Title_MessagBox" xml:space="preserve">
<value>CSV Query</value>
</data>
<data name="CQIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\CQIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="CsvQueryIconDark" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>CsvQueryIconDark.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="CsvQueryIconLight" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>CsvQueryIconLight.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file removed CsvQuery/Resources/CQIcon.ico
Binary file not shown.

1 comment on commit fbad87c

@jokedst
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #28

Please sign in to comment.