Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect background color #41

Closed
Fruchtzwerg94 opened this issue Oct 22, 2022 · 1 comment
Closed

Automatically detect background color #41

Fruchtzwerg94 opened this issue Oct 22, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Fruchtzwerg94
Copy link
Contributor

Fruchtzwerg94 commented Oct 22, 2022

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:

  1. 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();
    }
}
  1. 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);
  1. 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.

@BdR76 BdR76 added the enhancement New feature or request label Oct 23, 2022
@BdR76
Copy link
Owner

BdR76 commented Oct 23, 2022

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.

@BdR76 BdR76 closed this as completed Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants