From a16261caaa173689da468d5be66e32866681e152 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 2 Aug 2024 12:17:51 +0200 Subject: [PATCH] Add customizable option for individual tab color Fix #12156, close #15509 --- PowerEditor/src/Notepad_plus.cpp | 2 +- PowerEditor/src/Parameters.cpp | 90 ++++++++++++++++--- PowerEditor/src/Parameters.h | 19 +++- .../WinControls/ColourPicker/WordStyleDlg.cpp | 60 +++++++++++++ .../WinControls/ColourPicker/WordStyleDlg.h | 1 + PowerEditor/src/WinControls/TabBar/TabBar.h | 16 ++++ PowerEditor/src/stylers.model.xml | 10 +++ 7 files changed, 182 insertions(+), 16 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 508804daa..0d1c95a4f 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -475,7 +475,7 @@ LRESULT Notepad_plus::init(HWND hwnd) // ------------ // // Menu Section // // ------------ // - + nppParam.initTabCustomColors(); setupColorSampleBitmapsOnMainMenuItems(); // Macro Menu diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 7af841aa0..5e6a57bc2 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -15,7 +15,7 @@ // along with this program. If not, see . #include -#include + #include #include "Parameters.h" #include "ScintillaEditView.h" @@ -8820,29 +8820,91 @@ EolType convertIntToFormatType(int value, EolType defvalue) } } -#include - -struct HLSColour +void NppParameters::initTabCustomColors() { - WORD _hue; - WORD _lightness; - WORD _saturation; + StyleArray& stylers = getMiscStylerArray(); - COLORREF toRGB() const { return ColorHLSToRGB(_hue, _lightness, _saturation); } -}; + const Style* pStyle = stylers.findByName(L"Tab color 1"); + if (pStyle) + { + individualTabHues[0].changeHLSFrom(pStyle->_bgColor); + } + + pStyle = stylers.findByName(L"Tab color 2"); + if (pStyle) + { + individualTabHues[1].changeHLSFrom(pStyle->_bgColor); + } + + pStyle = stylers.findByName(L"Tab color 3"); + if (pStyle) + { + individualTabHues[2].changeHLSFrom(pStyle->_bgColor); + } + + pStyle = stylers.findByName(L"Tab color 4"); + if (pStyle) + { + individualTabHues[3].changeHLSFrom(pStyle->_bgColor); + } + + pStyle = stylers.findByName(L"Tab color 5"); + if (pStyle) + { + individualTabHues[4].changeHLSFrom(pStyle->_bgColor); + } + + + pStyle = stylers.findByName(L"Tab color dark mode 1"); + if (pStyle) + { + individualTabHuesFor_Dark[0].changeHLSFrom(pStyle->_bgColor); + } + + pStyle = stylers.findByName(L"Tab color dark mode 2"); + if (pStyle) + { + individualTabHuesFor_Dark[1].changeHLSFrom(pStyle->_bgColor); + } -using IndividualTabColours = std::array; + pStyle = stylers.findByName(L"Tab color dark mode 3"); + if (pStyle) + { + individualTabHuesFor_Dark[2].changeHLSFrom(pStyle->_bgColor); + } -static constexpr IndividualTabColours individualTabHuesFor_Dark{ { HLSColour{37, 60, 60}, HLSColour{70, 60, 60}, HLSColour{144, 70, 60}, HLSColour{255, 60, 60}, HLSColour{195, 60, 60} } }; -static constexpr IndividualTabColours individualTabHues{ { HLSColour{37, 210, 150}, HLSColour{70, 210, 150}, HLSColour{144, 210, 150}, HLSColour{255, 210, 150}, HLSColour{195, 210, 150}} }; + pStyle = stylers.findByName(L"Tab color dark mode 4"); + if (pStyle) + { + individualTabHuesFor_Dark[3].changeHLSFrom(pStyle->_bgColor); + } + pStyle = stylers.findByName(L"Tab color dark mode 5"); + if (pStyle) + { + individualTabHuesFor_Dark[4].changeHLSFrom(pStyle->_bgColor); + } +} + + +void NppParameters::setIndividualTabColour(COLORREF colour2Set, int colourIndex, bool isDarkMode) +{ + if (colourIndex < 0 || colourIndex > 4) return; + + if (isDarkMode) + individualTabHuesFor_Dark[colourIndex].changeHLSFrom(colour2Set); + else + individualTabHues[colourIndex].changeHLSFrom(colour2Set); + + return; +} -COLORREF NppParameters::getIndividualTabColour(int colourIndex, bool themeDependant, bool saturated) +COLORREF NppParameters::getIndividualTabColour(int colourIndex, bool isDarkMode, bool saturated) { if (colourIndex < 0 || colourIndex > 4) return {}; HLSColour result; - if (themeDependant) + if (isDarkMode) { result = individualTabHuesFor_Dark[colourIndex]; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 05eda48e7..87e84fa46 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "ILexer.h" #include "Lexilla.h" #include "DockingCont.h" @@ -1378,6 +1380,15 @@ private: std::wstring _stylesXmlPath; }; +struct HLSColour +{ + WORD _hue; + WORD _lightness; + WORD _saturation; + + void changeHLSFrom(COLORREF rgb) { ColorRGBToHLS(rgb, &_hue, &_lightness, &_saturation); } + COLORREF toRGB() const { return ColorHLSToRGB(_hue, _lightness, _saturation); } +}; struct UdlXmlFileState final { TiXmlDocument* _udlXmlDoc = nullptr; @@ -1897,6 +1908,9 @@ private: std::wstring _loadedSessionFullFilePath; + std::array individualTabHuesFor_Dark{ { HLSColour{37, 60, 60}, HLSColour{70, 60, 60}, HLSColour{144, 70, 60}, HLSColour{255, 60, 60}, HLSColour{195, 60, 60} } }; + std::array individualTabHues{ { HLSColour{37, 210, 150}, HLSColour{70, 210, 150}, HLSColour{144, 210, 150}, HLSColour{255, 210, 150}, HLSColour{195, 210, 150}} }; + public: void setShortcutDirty() { _isAnyShortcutModified = true; }; void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; } @@ -2003,7 +2017,10 @@ public: void setTheWarningHasBeenGiven(bool isEnabled) { _theWarningHasBeenGiven = isEnabled; }; bool theWarningHasBeenGiven() const { return _theWarningHasBeenGiven; } - COLORREF getIndividualTabColour(int colourIndex, bool themeDependant, bool saturated); + + void initTabCustomColors(); + void setIndividualTabColour(COLORREF colour2Set, int colourIndex, bool isDarkMode); + COLORREF getIndividualTabColour(int colourIndex, bool isDarkMode, bool saturated); private: void getLangKeywordsFromXmlTree(); diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index 106aa9b80..3353741c1 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -359,6 +359,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM } restoreGlobalOverrideValues(); + nppParamInst.initTabCustomColors(); _restoreInvalid = false; _isDirty = false; @@ -554,6 +555,20 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM { ViewZoneDlg::setColour(_pBgColour->getColour(), ViewZoneDlg::ViewZoneColorIndex::frost); } + else + { + int colourIndex = whichIndividualTabColourId(); + + if (colourIndex != -1) + { + if (colourIndex >= TabBarPlus::individualTabColourId::id5) + colourIndex -= TabBarPlus::individualTabColourId::id5; + + NppParameters& nppParamInst = NppParameters::getInstance(); + nppParamInst.setIndividualTabColour(_pBgColour->getColour(), colourIndex, NppDarkMode::isEnabled()); + } + } + apply(); return TRUE; } @@ -658,6 +673,51 @@ int WordStyleDlg::whichTabColourIndex() return -1; } +int WordStyleDlg::whichIndividualTabColourId() +{ + constexpr size_t styleNameLen = 128; + wchar_t styleName[styleNameLen + 1] = { '\0' }; + + if (!WordStyleDlg::getStyleName(styleName, styleNameLen)) + { + return -1; + } + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_1) == 0) + return TabBarPlus::individualTabColourId::id0; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_2) == 0) + return TabBarPlus::individualTabColourId::id1; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_3) == 0) + return TabBarPlus::individualTabColourId::id2; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_4) == 0) + return TabBarPlus::individualTabColourId::id3; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_5) == 0) + return TabBarPlus::individualTabColourId::id4; + + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_1) == 0) + return TabBarPlus::individualTabColourId::id5; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_2) == 0) + return TabBarPlus::individualTabColourId::id6; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_3) == 0) + return TabBarPlus::individualTabColourId::id7; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_4) == 0) + return TabBarPlus::individualTabColourId::id8; + + if (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_5) == 0) + return TabBarPlus::individualTabColourId::id9; + + + return -1; +} + bool WordStyleDlg::isDocumentMapStyle() { constexpr size_t styleNameLen = 128; diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h index 3beedd768..b8fce2900 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h @@ -119,6 +119,7 @@ private : bool getStyleName(wchar_t *styleName, const size_t styleNameLen); int whichTabColourIndex(); + int whichIndividualTabColourId(); bool isDocumentMapStyle(); void move2CtrlRight(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight); void updateColour(bool which); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.h b/PowerEditor/src/WinControls/TabBar/TabBar.h index 5eaaf7027..226a5734e 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.h +++ b/PowerEditor/src/WinControls/TabBar/TabBar.h @@ -47,6 +47,18 @@ const wchar_t TABBAR_ACTIVEUNFOCUSEDINDCATOR[64] = L"Active tab unfocused indica const wchar_t TABBAR_ACTIVETEXT[64] = L"Active tab text"; const wchar_t TABBAR_INACTIVETEXT[64] = L"Inactive tabs"; +const wchar_t TABBAR_INDIVIDUALCOLOR_1[64] = L"Tab color 1"; +const wchar_t TABBAR_INDIVIDUALCOLOR_2[64] = L"Tab color 2"; +const wchar_t TABBAR_INDIVIDUALCOLOR_3[64] = L"Tab color 3"; +const wchar_t TABBAR_INDIVIDUALCOLOR_4[64] = L"Tab color 4"; +const wchar_t TABBAR_INDIVIDUALCOLOR_5[64] = L"Tab color 5"; + +const wchar_t TABBAR_INDIVIDUALCOLOR_DM_1[64] = L"Tab color dark mode 1"; +const wchar_t TABBAR_INDIVIDUALCOLOR_DM_2[64] = L"Tab color dark mode 2"; +const wchar_t TABBAR_INDIVIDUALCOLOR_DM_3[64] = L"Tab color dark mode 3"; +const wchar_t TABBAR_INDIVIDUALCOLOR_DM_4[64] = L"Tab color dark mode 4"; +const wchar_t TABBAR_INDIVIDUALCOLOR_DM_5[64] = L"Tab color dark mode 5"; + constexpr int g_TabIconSize = 16; constexpr int g_TabHeight = 22; constexpr int g_TabHeightLarge = 25; @@ -157,6 +169,10 @@ public : activeText, activeFocusedTop, activeUnfocusedTop, inactiveText, inactiveBg }; + enum individualTabColourId { + id0, id1, id2, id3, id4, id5, id6, id7, id8, id9 + }; + static void doDragNDrop(bool justDoIt) { _doDragNDrop = justDoIt; }; diff --git a/PowerEditor/src/stylers.model.xml b/PowerEditor/src/stylers.model.xml index fcc1f9f28..7e648df04 100644 --- a/PowerEditor/src/stylers.model.xml +++ b/PowerEditor/src/stylers.model.xml @@ -1580,6 +1580,16 @@ + + + + + + + + + +