From 5c6fbd33103f3cde666c48a6a6ce0bcc8a90ff0e Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 2 Jul 2022 17:19:17 +0200 Subject: [PATCH] Fix "Style Configurator..." command makes Notepad++ crash If "stylers.xml" is not loaded, launching "Style Configurator..." command will make Notepad++ crash. This commit fix this issue. Fix #11812 --- PowerEditor/src/NppCommands.cpp | 15 +++++--- PowerEditor/src/Parameters.h | 34 ++++++++----------- .../src/ScintillaComponent/FindReplaceDlg.cpp | 3 -- .../WinControls/ColourPicker/WordStyleDlg.h | 1 + 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index db42aaab3..c9e9282d9 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -3347,10 +3347,17 @@ void Notepad_plus::command(int id) case IDM_LANGSTYLE_CONFIG_DLG : { - bool isFirstTime = !_configStyleDlg.isCreated(); - _configStyleDlg.doDialog(_nativeLangSpeaker.isRTL()); - if (isFirstTime) - _nativeLangSpeaker.changeConfigLang(_configStyleDlg.getHSelf()); + if (!(NppParameters::getInstance()).isStylerDocLoaded()) + { + // do nothing + } + else + { + bool isFirstTime = !_configStyleDlg.isCreated(); + _configStyleDlg.doDialog(_nativeLangSpeaker.isRTL()); + if (isFirstTime) + _nativeLangSpeaker.changeConfigLang(_configStyleDlg.getHSelf()); + } break; } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 474474388..e2cfff633 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -429,48 +429,43 @@ struct GlobalOverride final struct StyleArray { - //auto size() const { return _styleVect.size(); } - auto begin() { return _styleVect.begin(); } - auto end() { return _styleVect.end(); } - void clear() { _styleVect.clear(); } + auto begin() { return _styleVect.begin(); }; + auto end() { return _styleVect.end(); }; + void clear() { _styleVect.clear(); }; - Style & getStyler(size_t index) - { + Style& getStyler(size_t index) { assert(index < _styleVect.size()); return _styleVect[index]; - } + }; void addStyler(int styleID, TiXmlNode *styleNode); - void addStyler(int styleID, const generic_string & styleName) - { + void addStyler(int styleID, const generic_string& styleName) { _styleVect.emplace_back(); - Style & s = _styleVect.back(); + Style& s = _styleVect.back(); s._styleID = styleID; s._styleDesc = styleName; s._fgColor = black; s._bgColor = white; - } + }; - Style * findByID(int id) - { - for (size_t i = 0 ; i < _styleVect.size() ; ++i) + Style* findByID(int id) { + for (size_t i = 0; i < _styleVect.size(); ++i) { if (_styleVect[i]._styleID == id) return &(_styleVect[i]); } return nullptr; - } + }; - Style * findByName(const generic_string & name) - { - for (size_t i = 0 ; i < _styleVect.size() ; ++i) + Style* findByName(const generic_string& name) { + for (size_t i = 0; i < _styleVect.size(); ++i) { if (_styleVect[i]._styleDesc == name) return &(_styleVect[i]); } return nullptr; - } + }; protected: std::vector