CSVLint
CSVLint copied to clipboard
Automatically detect background color
Hi,
since I always need to change the settings of the plugin after changing the theme of Notepad++ to apply the right colors, autodetecting this would be aweseome. Since I am not deep enought in the code of the plugin I don't know where and how to do this exactly here but you may want to have a look in my plugin PlantUmlViewer which has a similar feature implemented.
The following snippets where the solution for me:
- Detect the change of the editors background color PlantUmlViewer PlantUmlViewer.cs L161
public void OnNotification(ScNotification notification)
{
//NPPN_DARKMODECHANGED or NPPN_WORDSTYLESUPDATED
if (notification.Header.Code == (uint)NppMsg.NPPN_FIRST + 27
|| notification.Header.Code == (uint)NppMsg.NPPN_WORDSTYLESUPDATED)
{
UpdateStyle();
}
}
- Get the background color PlantUmlViewer PlantUmlViewer.cs L168
IntPtr editorBachgroundColorPtr = Win32.SendMessage(PluginBase.nppData._nppHandle,
(uint)NppMsg.NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR, 0, 0);
int bbggrr = editorBachgroundColorPtr.ToInt32();
Color editorBackgroundColor = Color.FromArgb(bbggrr & 0x0000FF, (bbggrr & 0x00FF00) >> 8, (bbggrr & 0xFF0000) >> 16);
- Determine if dark or light PlantUmlViewer PreviewWindow.cs L155
bool newIsLight = editorBackgroundColor.GetBrightness() > 0.4;
Would be a great feature for this plugin as well if applicable.
Thanks for the detailed issue description. You wrote "since I always need to change the settings" but how often do you switch between darkmode and normal mode in Notepad++? I figure most users change the style or switch between darkmode/normal only once, most users never at all.
When you first install the CSV Lint plugin, it detects if Notepad++ is in normal/darkmode and selects a csv colorset accordingly. But, there are two default colorsets for each, so the user may change that as well. So to facilitate toggling+automatic colorset change, the plugin should also store the preferred default colorset for each mode.
But also, the user can change the csv colors in Settings > Style configuration
, so it should probably make a backup of the current colors XML, remember which is darkmode/normal mode, and restore the correct one when toggling between dark/normal mode etc.
But even then it requires a Notepad++ restart to change the colors, because I had tried to make the color-style change immediate, but that wasn't possible, i.e. the plugin can change the style but closing a csv file or even changing between tabs will reset it back to the colors at Notepad++ startup. So changing color style will still require a Notepad++ restart.
So in short, I think this will introduce more complexity and unexpected behaviour for something most users will only do once. So I'm sorry but atm I don't see how I can add this feature in a practical way.