Skip to content

Commit

Permalink
Fix_Styler Configurator performance issue
Browse files Browse the repository at this point in the history
Improve Styler Configurator modification application performance considerably.

Fix notepad-plus-plus#12436
  • Loading branch information
donho committed Aug 20, 2024
1 parent c1954e5 commit cea7830
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 80 deletions.
101 changes: 53 additions & 48 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa

case WM_UPDATESCINTILLAS:
{
bool isThemeChanged = (wParam == TRUE);

//reset styler for change in Stylers.xml
_mainEditView.defineDocType(_mainEditView.getCurrentBuffer()->getLangType());
_mainEditView.performGlobalStyles();
Expand Down Expand Up @@ -2313,62 +2315,65 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
AutoCompletion::drawAutocomplete(_pEditView);
AutoCompletion::drawAutocomplete(_pNonEditView);

NppDarkMode::calculateTreeViewStyle();
auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE);

// Set default fg/bg colors on internal docking dialog
if (pStyle && _pFuncList)
if (isThemeChanged) // Theme change
{
_pFuncList->setBackgroundColor(pStyle->_bgColor);
_pFuncList->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
NppDarkMode::calculateTreeViewStyle();
auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE);

if (pStyle && _pAnsiCharPanel)
{
_pAnsiCharPanel->setBackgroundColor(pStyle->_bgColor);
_pAnsiCharPanel->setForegroundColor(pStyle->_fgColor);
}
// Set default fg/bg colors on internal docking dialog
if (pStyle && _pFuncList)
{
_pFuncList->setBackgroundColor(pStyle->_bgColor);
_pFuncList->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}

if (pStyle && _pDocumentListPanel)
{
_pDocumentListPanel->setBackgroundColor(pStyle->_bgColor);
_pDocumentListPanel->setForegroundColor(pStyle->_fgColor);
}
if (pStyle && _pAnsiCharPanel)
{
_pAnsiCharPanel->setBackgroundColor(pStyle->_bgColor);
_pAnsiCharPanel->setForegroundColor(pStyle->_fgColor);
}

if (pStyle && _pClipboardHistoryPanel)
{
_pClipboardHistoryPanel->setBackgroundColor(pStyle->_bgColor);
_pClipboardHistoryPanel->setForegroundColor(pStyle->_fgColor);
_pClipboardHistoryPanel->redraw(true);
}
if (pStyle && _pDocumentListPanel)
{
_pDocumentListPanel->setBackgroundColor(pStyle->_bgColor);
_pDocumentListPanel->setForegroundColor(pStyle->_fgColor);
}

if (pStyle && _pProjectPanel_1)
{
_pProjectPanel_1->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_1->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (pStyle && _pClipboardHistoryPanel)
{
_pClipboardHistoryPanel->setBackgroundColor(pStyle->_bgColor);
_pClipboardHistoryPanel->setForegroundColor(pStyle->_fgColor);
_pClipboardHistoryPanel->redraw(true);
}

if (pStyle && _pProjectPanel_2)
{
_pProjectPanel_2->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_2->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (pStyle && _pProjectPanel_1)
{
_pProjectPanel_1->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_1->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}

if (pStyle && _pProjectPanel_3)
{
_pProjectPanel_3->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_3->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
if (pStyle && _pProjectPanel_2)
{
_pProjectPanel_2->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_2->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}

if (pStyle && _pFileBrowser)
{
_pFileBrowser->setBackgroundColor(pStyle->_bgColor);
_pFileBrowser->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
if (pStyle && _pProjectPanel_3)
{
_pProjectPanel_3->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_3->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}

if (pStyle && _pFileBrowser)
{
_pFileBrowser->setBackgroundColor(pStyle->_bgColor);
_pFileBrowser->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
}
}

if (_pDocMap)
Expand Down
93 changes: 64 additions & 29 deletions PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
{
updateUserKeywords();
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}
else if (editID == IDC_USER_EXT_EDIT)
{
updateExtension();
notifyDataModified();
apply(false);
apply(NO_VISUAL_CHANGE);
return TRUE;
}
return FALSE;
Expand All @@ -309,19 +309,19 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
case IDC_BOLD_CHECK :
updateFontStyleStatus(BOLD_STATUS);
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;

case IDC_ITALIC_CHECK :
updateFontStyleStatus(ITALIC_STATUS);
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;

case IDC_UNDERLINE_CHECK :
updateFontStyleStatus(UNDERLINE_STATUS);
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;

case IDC_GLOBAL_GOTOSETTINGS_LINK :
Expand Down Expand Up @@ -429,7 +429,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableFg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}

Expand All @@ -438,7 +438,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableBg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}

Expand All @@ -447,23 +447,23 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableFont = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}
case IDC_GLOBAL_FONTSIZE_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableFontSize = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}
case IDC_GLOBAL_BOLD_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableBold = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}

Expand All @@ -472,15 +472,15 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableItalic = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}
case IDC_GLOBAL_UNDERLINE_CHECK :
{
GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle();
glo.enableUnderLine = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0));
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
return TRUE;
}

Expand All @@ -494,12 +494,12 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
case IDC_FONT_COMBO :
updateFontName();
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
break;
case IDC_FONTSIZE_COMBO :
updateFontSize();
notifyDataModified();
apply();
apply(GENERAL_CHANGE);
break;
case IDC_LANGUAGES_LIST :
{
Expand All @@ -525,28 +525,32 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM

case CPN_COLOURPICKED:
{
int applicationInfo = getApplicationInfo();
int tabColourIndex = whichTabColourIndex();

if (reinterpret_cast<HWND>(lParam) == _pFgColour->getHSelf())
{
updateColour(C_FOREGROUND);
notifyDataModified();
int tabColourIndex;
if ((tabColourIndex = whichTabColourIndex()) != -1)

if (tabColourIndex != -1)
{
TabBarPlus::setColour(_pFgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex, nullptr);
}
else if (isDocumentMapStyle())
{
ViewZoneDlg::setColour(_pFgColour->getColour(), ViewZoneDlg::ViewZoneColorIndex::focus);
}
apply();
apply(applicationInfo);
return TRUE;
}
else if (reinterpret_cast<HWND>(lParam) == _pBgColour->getHSelf())
{
updateColour(C_BACKGROUND);
notifyDataModified();
int tabColourIndex;
if ((tabColourIndex = whichTabColourIndex()) != -1)


if (tabColourIndex != -1)
{
tabColourIndex = (tabColourIndex == TabBarPlus::inactiveText ? TabBarPlus::inactiveBg : tabColourIndex);
TabBarPlus::setColour(_pBgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex, nullptr);
Expand All @@ -569,7 +573,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
}
}

apply();
apply(applicationInfo);
return TRUE;
}
else
Expand Down Expand Up @@ -633,7 +637,7 @@ void WordStyleDlg::updateThemeName(const wstring& themeName)
nppGUI._themeName.assign( themeName );
}

bool WordStyleDlg::getStyleName(wchar_t *styleName, const size_t styleNameLen)
bool WordStyleDlg::getStyleName(wchar_t *styleName, const size_t styleNameLen) const
{
auto i = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETCURSEL, 0, 0);
if (i == LB_ERR)
Expand All @@ -648,7 +652,40 @@ bool WordStyleDlg::getStyleName(wchar_t *styleName, const size_t styleNameLen)
return true;
}

int WordStyleDlg::whichTabColourIndex()
int WordStyleDlg::getApplicationInfo() const
{
constexpr size_t styleNameLen = 128;
wchar_t styleName[styleNameLen + 1] = { '\0' };

if (!WordStyleDlg::getStyleName(styleName, styleNameLen))
{
return NO_VISUAL_CHANGE;
}

if (lstrcmp(styleName, L"Default Style") == 0)
return (GENERAL_CHANGE | THEME_CHANGE);

if ((lstrcmp(styleName, L"Mark Style 1") == 0) ||
(lstrcmp(styleName, L"Mark Style 2") == 0) ||
(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))
return (GENERAL_CHANGE | COLOR_CHANGE_4_MENU);

return GENERAL_CHANGE;
}

int WordStyleDlg::whichTabColourIndex() const
{
constexpr size_t styleNameLen = 128;
wchar_t styleName[styleNameLen + 1] = { '\0' };
Expand Down Expand Up @@ -880,7 +917,7 @@ void WordStyleDlg::applyCurrentSelectedThemeAndUpdateUI()
setVisualFromStyleList();
notifyDataModified();
_isThemeDirty = false;
apply();
apply(GENERAL_CHANGE | THEME_CHANGE);
}

bool WordStyleDlg::selectThemeByName(const wchar_t* themeName)
Expand Down Expand Up @@ -1319,20 +1356,18 @@ void WordStyleDlg::restoreGlobalOverrideValues()
gOverride = _gOverride2restored;
}


void WordStyleDlg::apply(bool needVisualApply)
void WordStyleDlg::apply(int applicationInfo)
{
LexerStylerArray & lsa = (NppParameters::getInstance()).getLStylerArray();
lsa = _lsArray;

StyleArray & globalStyles = (NppParameters::getInstance()).getGlobalStylers();
globalStyles = _globalStyles;

if (needVisualApply)
{
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
if (applicationInfo & GENERAL_CHANGE || applicationInfo & THEME_CHANGE)
::SendMessage(_hParent, WM_UPDATESCINTILLAS, (applicationInfo & THEME_CHANGE) != 0, 0);
if (applicationInfo & COLOR_CHANGE_4_MENU)
::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0);
}

::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE);
}
Expand Down
Loading

0 comments on commit cea7830

Please sign in to comment.