From 872d6f90a4359a9b99f43eedc437b82bc5add2ee Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 1 Sep 2024 20:37:31 +0200 Subject: [PATCH] Make find dialog status messages color customizable via Style Configurator Fix #5087 --- PowerEditor/src/Notepad_plus.cpp | 2 +- PowerEditor/src/NppBigSwitch.cpp | 2 + PowerEditor/src/NppNotification.cpp | 2 +- PowerEditor/src/Parameters.cpp | 64 +++++++++++++++---- PowerEditor/src/Parameters.h | 10 ++- .../src/ScintillaComponent/FindReplaceDlg.cpp | 21 +++--- .../src/ScintillaComponent/FindReplaceDlg.h | 5 -- .../WinControls/ColourPicker/WordStyleDlg.cpp | 59 +++++++++++++---- .../WinControls/ColourPicker/WordStyleDlg.h | 13 ++-- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 4 +- .../VerticalFileSwitcher.cpp | 2 +- 11 files changed, 132 insertions(+), 52 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b025ebb3c441..4ef057bb7526 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2715,7 +2715,7 @@ void Notepad_plus::setupColorSampleBitmapsOnMainMenuItems() // Adds tab colour icons for (int i = 0; i < 5; ++i) { - COLORREF colour = nppParam.getIndividualTabColour(i, NppDarkMode::isDarkMenuEnabled(), true); + COLORREF colour = nppParam.getIndividualTabColor(i, NppDarkMode::isDarkMenuEnabled(), true); HBITMAP hBitmap = generateSolidColourMenuItemIcon(colour); SetMenuItemBitmaps(_mainMenuHandle, IDM_VIEW_TAB_COLOUR_1 + i, MF_BYCOMMAND, hBitmap, hBitmap); } diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index fca99bfd70fb..3d619df5561e 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2308,6 +2308,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa addHotSpot(& _subEditView); _findReplaceDlg.updateFinderScintilla(); + + _findReplaceDlg.redraw(); drawTabbarColoursFromStylerArray(); diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index a263b008f9d3..be4b697a8699 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -581,7 +581,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) // Adds colour icons for (int i = 0; i < 5; ++i) { - COLORREF colour = nppParam.getIndividualTabColour(i, NppDarkMode::isDarkMenuEnabled(), true); + COLORREF colour = nppParam.getIndividualTabColor(i, NppDarkMode::isDarkMenuEnabled(), true); HBITMAP hBitmap = generateSolidColourMenuItemIcon(colour); SetMenuItemBitmaps(_tabPopupMenu.getMenuHandle(), IDM_VIEW_TAB_COLOUR_1 + i, MF_BYCOMMAND, hBitmap, hBitmap); } diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 20603100df97..b977481cf23b 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -8833,62 +8833,62 @@ void NppParameters::initTabCustomColors() { StyleArray& stylers = getMiscStylerArray(); - const Style* pStyle = stylers.findByName(L"Tab color 1"); + const Style* pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_1); if (pStyle) { individualTabHues[0].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color 2"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_2); if (pStyle) { individualTabHues[1].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color 3"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_3); if (pStyle) { individualTabHues[2].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color 4"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_4); if (pStyle) { individualTabHues[3].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color 5"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_5); if (pStyle) { individualTabHues[4].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color dark mode 1"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_1); if (pStyle) { individualTabHuesFor_Dark[0].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color dark mode 2"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_2); if (pStyle) { individualTabHuesFor_Dark[1].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color dark mode 3"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_3); if (pStyle) { individualTabHuesFor_Dark[2].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color dark mode 4"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_4); if (pStyle) { individualTabHuesFor_Dark[3].changeHLSFrom(pStyle->_bgColor); } - pStyle = stylers.findByName(L"Tab color dark mode 5"); + pStyle = stylers.findByName(TABBAR_INDIVIDUALCOLOR_DM_5); if (pStyle) { individualTabHuesFor_Dark[4].changeHLSFrom(pStyle->_bgColor); @@ -8896,7 +8896,7 @@ void NppParameters::initTabCustomColors() } -void NppParameters::setIndividualTabColour(COLORREF colour2Set, int colourIndex, bool isDarkMode) +void NppParameters::setIndividualTabColor(COLORREF colour2Set, int colourIndex, bool isDarkMode) { if (colourIndex < 0 || colourIndex > 4) return; @@ -8908,7 +8908,7 @@ void NppParameters::setIndividualTabColour(COLORREF colour2Set, int colourIndex, return; } -COLORREF NppParameters::getIndividualTabColour(int colourIndex, bool isDarkMode, bool saturated) +COLORREF NppParameters::getIndividualTabColor(int colourIndex, bool isDarkMode, bool saturated) { if (colourIndex < 0 || colourIndex > 4) return {}; @@ -8936,3 +8936,43 @@ COLORREF NppParameters::getIndividualTabColour(int colourIndex, bool isDarkMode, return result.toRGB(); } + +void NppParameters::initFindDlgStatusMsgCustomColors() +{ + StyleArray& stylers = getMiscStylerArray(); + + const Style* pStyle = stylers.findByName(FINDDLG_STAUSNOTFOUND_COLOR); + if (pStyle) + { + findDlgStatusMessageColor[0] = pStyle->_fgColor; + } + + pStyle = stylers.findByName(FINDDLG_STAUSMESSAGE_COLOR); + if (pStyle) + { + findDlgStatusMessageColor[1] = pStyle->_fgColor; + } + + pStyle = stylers.findByName(FINDDLG_STAUSREACHED_COLOR); + if (pStyle) + { + findDlgStatusMessageColor[2] = pStyle->_fgColor; + } + +} + +void NppParameters::setFindDlgStatusMsgIndexColor(COLORREF colour2Set, int colourIndex) +{ + if (colourIndex < 0 || colourIndex > 2) return; + + findDlgStatusMessageColor[colourIndex] = colour2Set; + + return; +} + +COLORREF NppParameters::getFindDlgStatusMsgColor(int colourIndex) +{ + if (colourIndex < 0 || colourIndex > 2) return black; + + return findDlgStatusMessageColor[colourIndex]; +} diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 6fa1adfd2ab1..54db0a9722ac 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1919,6 +1919,8 @@ class NppParameters final 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}} }; + std::array findDlgStatusMessageColor{ red, blue, darkGreen}; + public: void setShortcutDirty() { _isAnyShortcutModified = true; }; void setAdminMode(bool isAdmin) { _isAdminMode = isAdmin; } @@ -2027,8 +2029,12 @@ class NppParameters final void initTabCustomColors(); - void setIndividualTabColour(COLORREF colour2Set, int colourIndex, bool isDarkMode); - COLORREF getIndividualTabColour(int colourIndex, bool isDarkMode, bool saturated); + void setIndividualTabColor(COLORREF colour2Set, int colourIndex, bool isDarkMode); + COLORREF getIndividualTabColor(int colourIndex, bool isDarkMode, bool saturated); + + void initFindDlgStatusMsgCustomColors(); + void setFindDlgStatusMsgIndexColor(COLORREF colour2Set, int colourIndex); + COLORREF getFindDlgStatusMsgColor(int colourIndex); private: void getLangKeywordsFromXmlTree(); diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 513b4d2e105c..7b0c629a3c37 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -4955,18 +4955,19 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) //printStr(L"OK")); COLORREF fgColor = black; // black by default PCTSTR ptStr =(PCTSTR)lpDrawItemStruct->itemData; - + NppParameters& nppParamInst = NppParameters::getInstance(); + if (_statusbarFindStatus == FSNotFound) { - fgColor = _FSNotFoundTextColor; + fgColor = nppParamInst.getFindDlgStatusMsgColor(0); } else if (_statusbarFindStatus == FSMessage) { - fgColor = _FSMessageTextColor; + fgColor = nppParamInst.getFindDlgStatusMsgColor(1); } else if (_statusbarFindStatus == FSTopReached || _statusbarFindStatus == FSEndReached) { - fgColor = _FSReachedTextColor; + fgColor = nppParamInst.getFindDlgStatusMsgColor(2); } else if (_statusbarFindStatus == FSNoMessage) { @@ -4980,26 +4981,26 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) if (_statusbarFindStatus == FSNotFound) { HLSColour hls; - hls.changeHLSFrom(_FSNotFoundTextColor); + hls.changeHLSFrom(nppParamInst.getFindDlgStatusMsgColor(0)); hls._lightness += 50; hls._saturation -= 20; - fgColor = hls.toRGB(); // red + fgColor = hls.toRGB(); } else if (_statusbarFindStatus == FSMessage) { HLSColour hls; - hls.changeHLSFrom(_FSMessageTextColor); + hls.changeHLSFrom(nppParamInst.getFindDlgStatusMsgColor(1)); hls._lightness += 50; hls._saturation -= 20; - fgColor = hls.toRGB(); // blue + fgColor = hls.toRGB(); } else if (_statusbarFindStatus == FSTopReached || _statusbarFindStatus == FSEndReached) { HLSColour hls; - hls.changeHLSFrom(_FSReachedTextColor); + hls.changeHLSFrom(nppParamInst.getFindDlgStatusMsgColor(2)); hls._lightness += 50; hls._saturation -= 20; - fgColor = hls.toRGB(); // green + fgColor = hls.toRGB(); } } diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h index 12709c1e6cfe..05cef3caefd9 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h @@ -499,12 +499,7 @@ protected : static const int FR_OP_GLOBAL = 8; static const int FR_OP_FIP = 16; void saveInMacro(size_t cmd, int cmdType); - - COLORREF _FSNotFoundTextColor = red; - COLORREF _FSMessageTextColor = blue; - COLORREF _FSReachedTextColor = darkGreen; void drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); - bool replaceInFilesConfirmCheck(const std::wstring& directory, const std::wstring& fileTypes); bool replaceInProjectsConfirmCheck(); bool replaceInOpenDocsConfirmCheck(void); diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index da20190081ad..01d96832dae4 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -360,6 +360,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM restoreGlobalOverrideValues(); nppParamInst.initTabCustomColors(); + nppParamInst.initFindDlgStatusMsgCustomColors(); _restoreInvalid = false; _isDirty = false; @@ -540,9 +541,18 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM { TabBarPlus::setColour(_pFgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex, nullptr); } - else if (isDocumentMapStyle()) + else { - ViewZoneDlg::setColour(_pFgColour->getColour(), ViewZoneDlg::ViewZoneColorIndex::focus); + int findDlgStatusMsgIndex = whichFindDlgStatusMsgColourIndex(); + if (findDlgStatusMsgIndex != -1) + { + NppParameters& nppParamInst = NppParameters::getInstance(); + nppParamInst.setFindDlgStatusMsgIndexColor(_pFgColour->getColour(), findDlgStatusMsgIndex); + } + else if (isDocumentMapStyle()) + { + ViewZoneDlg::setColour(_pFgColour->getColour(), ViewZoneDlg::ViewZoneColorIndex::focus); + } } apply(applicationInfo); return TRUE; @@ -572,7 +582,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM colourIndex -= TabBarPlus::individualTabColourId::id5; NppParameters& nppParamInst = NppParameters::getInstance(); - nppParamInst.setIndividualTabColour(_pBgColour->getColour(), colourIndex, NppDarkMode::isEnabled()); + nppParamInst.setIndividualTabColor(_pBgColour->getColour(), colourIndex, NppDarkMode::isEnabled()); } } @@ -675,20 +685,19 @@ int WordStyleDlg::getApplicationInfo() const (lstrcmp(styleName, L"Mark Style 3") == 0) || (lstrcmp(styleName, L"Mark Style 4") == 0) || (lstrcmp(styleName, L"Mark Style 5") == 0) || - (lstrcmp(styleName, L"Tab color 1") == 0) || - (lstrcmp(styleName, L"Tab color 2") == 0) || - (lstrcmp(styleName, L"Tab color 3") == 0) || - (lstrcmp(styleName, L"Tab color 4") == 0) || - (lstrcmp(styleName, L"Tab color 5") == 0) || - (lstrcmp(styleName, L"Tab color dark mode 1") == 0) || - (lstrcmp(styleName, L"Tab color dark mode 2") == 0) || - (lstrcmp(styleName, L"Tab color dark mode 3") == 0) || - (lstrcmp(styleName, L"Tab color dark mode 4") == 0) || - (lstrcmp(styleName, L"Tab color dark mode 5") == 0)) + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_1) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_2) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_3) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_4) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_5) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_1) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_2) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_3) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_4) == 0) || + (lstrcmp(styleName, TABBAR_INDIVIDUALCOLOR_DM_5) == 0)) { return (GENERAL_CHANGE | COLOR_CHANGE_4_MENU); } - return GENERAL_CHANGE; } @@ -762,6 +771,28 @@ int WordStyleDlg::whichIndividualTabColourId() return -1; } +int WordStyleDlg::whichFindDlgStatusMsgColourIndex() +{ + constexpr size_t styleNameLen = 128; + wchar_t styleName[styleNameLen + 1] = { '\0' }; + + if (!WordStyleDlg::getStyleName(styleName, styleNameLen)) + { + return -1; + } + + if (lstrcmp(styleName, FINDDLG_STAUSNOTFOUND_COLOR) == 0) + return TabBarPlus::individualTabColourId::id0; + + if (lstrcmp(styleName, FINDDLG_STAUSMESSAGE_COLOR) == 0) + return TabBarPlus::individualTabColourId::id1; + + if (lstrcmp(styleName, FINDDLG_STAUSREACHED_COLOR) == 0) + return TabBarPlus::individualTabColourId::id2; + + 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 3035fb0aaad7..b553c1611e06 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h @@ -28,10 +28,14 @@ // The following parameters are for apply() method which will re-initialize the followings GUI with modified styler: // 2 Scintilla edit zones, Search result (displayed by Sintilla), Notepad++ GUI & components concerning theme -#define NO_VISUAL_CHANGE 0x00 // No need to apply visual effect - User ext. -#define GENERAL_CHANGE 0x01 // For Sintilla zones & Notepad++ GUI -#define THEME_CHANGE 0x02 // For the components concerning theme, for example the background color of dockable panels -#define COLOR_CHANGE_4_MENU 0x04 // For the color items displayed on the menu +#define NO_VISUAL_CHANGE 0x00 // No need to apply visual effect - User ext. +#define GENERAL_CHANGE 0x01 // For Sintilla zones & Notepad++ GUI (Tabbar, Find dialog, etc...) +#define THEME_CHANGE 0x02 // For the components concerning theme, for example the background color of dockable panels +#define COLOR_CHANGE_4_MENU 0x04 // For the color items displayed on the menu + +const wchar_t FINDDLG_STAUSNOTFOUND_COLOR[64] = L"Find status: Not found"; +const wchar_t FINDDLG_STAUSMESSAGE_COLOR[64] = L"Find status: Message"; +const wchar_t FINDDLG_STAUSREACHED_COLOR[64] = L"Find status: Search end reached"; enum fontStyleType {BOLD_STATUS, ITALIC_STATUS, UNDERLINE_STATUS}; @@ -127,6 +131,7 @@ private : int whichTabColourIndex() const; int whichIndividualTabColourId(); + int whichFindDlgStatusMsgColourIndex(); void apply(int applicationInfo); int getApplicationInfo() const; bool isDocumentMapStyle(); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 60bb920f41a0..4f6e5f23a208 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -1280,7 +1280,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) if (individualColourId != -1) { - topBarColour = nppParam.getIndividualTabColour(individualColourId, isDarkMode, isFocused); + topBarColour = nppParam.getIndividualTabColor(individualColourId, isDarkMode, isFocused); } hBrush = ::CreateSolidBrush(topBarColour); @@ -1300,7 +1300,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) } else if (individualColourId != -1) { - brushColour = nppParam.getIndividualTabColour(individualColourId, isDarkMode, false); + brushColour = nppParam.getIndividualTabColor(individualColourId, isDarkMode, false); } else { diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 1cdc13032ae2..c71a9405f193 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -157,7 +157,7 @@ LRESULT VerticalFileSwitcher::listViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPA if (colorID != -1) { - bgColor = NppParameters::getInstance().getIndividualTabColour(colorID, isThemeDark, false); + bgColor = NppParameters::getInstance().getIndividualTabColor(colorID, isThemeDark, false); applyColor = true; } else if (isThemeDark)