From 903d47b2eb27a40e22b8ee26a4f73123b15bdf1f Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 1 Apr 2024 01:14:47 +0200 Subject: [PATCH] Reduce compiling warning Close #14924 --- PowerEditor/src/Notepad_plus.cpp | 74 +++++++++---------- PowerEditor/src/Notepad_plus_Window.cpp | 2 +- PowerEditor/src/NppBigSwitch.cpp | 4 +- PowerEditor/src/NppCommands.cpp | 2 +- PowerEditor/src/NppIO.cpp | 10 +-- PowerEditor/src/NppNotification.cpp | 18 ++--- PowerEditor/src/Parameters.cpp | 26 +++---- PowerEditor/src/Parameters.h | 14 ++-- .../FunctionList/functionParser.cpp | 6 +- .../OpenSaveFileDialog/CustomFileDialog.cpp | 18 +---- PowerEditor/src/localization.cpp | 34 ++++----- 11 files changed, 91 insertions(+), 117 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0d541b6b9..f7cdb285b 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -404,14 +404,18 @@ LRESULT Notepad_plus::init(HWND hwnd) TabBarPlus::setVertical((tabBarStatus & TAB_VERTICAL) != 0); drawTabbarColoursFromStylerArray(); - // Autocomplete list and calltip - const Style* pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT); + // + // Initialize the default foreground & background color + // + const Style* pStyle = nppParam.getGlobalStylers().findByID(STYLE_DEFAULT); if (pStyle) { - NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor); - NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor); + nppParam.setCurrentDefaultFgColor(pStyle->_fgColor); + nppParam.setCurrentDefaultBgColor(pStyle->_bgColor); drawAutocompleteColoursFromTheme(pStyle->_fgColor, pStyle->_bgColor); } + + // Autocomplete list and calltip AutoCompletion::drawAutocomplete(_pEditView); AutoCompletion::drawAutocomplete(_pNonEditView); @@ -790,18 +794,6 @@ LRESULT Notepad_plus::init(HWND hwnd) ::DrawMenuBar(hwnd); } - // - // Initialize the default foreground & background color - // - { - const Style * pStyle = nppParam.getGlobalStylers().findByID(STYLE_DEFAULT); - if (pStyle) - { - nppParam.setCurrentDefaultFgColor(pStyle->_fgColor); - nppParam.setCurrentDefaultBgColor(pStyle->_bgColor); - } - } - // // launch the plugin dlg memorized at the last session // @@ -948,7 +940,7 @@ bool Notepad_plus::saveGUIParams() bool Notepad_plus::saveColumnEditorParams() { - NppParameters& nppParams = NppParameters::getInstance(); + const NppParameters& nppParams = NppParameters::getInstance(); return nppParams.writeColumnEditorSettings(); } @@ -1179,7 +1171,7 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const char encodingStr[encodingStrLen]; _invisibleEditView.getText(encodingStr, startPos, endPos); - EncodingMapper& em = EncodingMapper::getInstance(); + const EncodingMapper& em = EncodingMapper::getInstance(); int enc = em.getEncodingFromString(encodingStr); return (enc == CP_ACP ? -1 : enc); } @@ -1223,7 +1215,7 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const char encodingStr[encodingStrLen]; _invisibleEditView.getText(encodingStr, startPos, endPos); - EncodingMapper& em = EncodingMapper::getInstance(); + const EncodingMapper& em = EncodingMapper::getInstance(); int enc = em.getEncodingFromString(encodingStr); return (enc == CP_ACP ? -1 : enc); } @@ -2224,7 +2216,7 @@ bool Notepad_plus::findInFilelist(std::vector & fileNames) if (nbTotal > 0) { NppParameters& nppParam = NppParameters::getInstance(); - NppGUI& nppGui = nppParam.getNppGUI(); + const NppGUI& nppGui = nppParam.getNppGUI(); if (!nppGui._findDlgAlwaysVisible) { _findReplaceDlg.display(false); @@ -2323,7 +2315,7 @@ bool Notepad_plus::findInOpenedFiles() if (nbTotal > 0) { NppParameters& nppParam = NppParameters::getInstance(); - NppGUI& nppGui = nppParam.getNppGUI(); + const NppGUI& nppGui = nppParam.getNppGUI(); if (!nppGui._findDlgAlwaysVisible) { _findReplaceDlg.display(false); @@ -2396,7 +2388,7 @@ bool Notepad_plus::findInCurrentFile(bool isEntireDoc) if (nbTotal > 0) { NppParameters& nppParam = NppParameters::getInstance(); - NppGUI& nppGui = nppParam.getNppGUI(); + const NppGUI& nppGui = nppParam.getNppGUI(); if (!nppGui._findDlgAlwaysVisible) { _findReplaceDlg.display(false); @@ -3055,7 +3047,7 @@ void Notepad_plus::setUniModeText() } else { - EncodingMapper& em = EncodingMapper::getInstance(); + const EncodingMapper& em = EncodingMapper::getInstance(); int cmdID = em.getIndexFromEncoding(encoding); if (cmdID == -1) { @@ -4077,7 +4069,7 @@ size_t Notepad_plus::getSelectedCharNumber(UniMode u) #ifdef _OPENMP #include #endif -static inline size_t countUtf8Characters(unsigned char *buf, size_t pos, size_t endpos) +static inline size_t countUtf8Characters(const unsigned char *buf, size_t pos, size_t endpos) { size_t result = 0; while (pos < endpos) @@ -4581,7 +4573,7 @@ bool Notepad_plus::removeBufferFromView(BufferID id, int whichOne) size_t i, n = taskListInfo._tlfsLst.size(); for (i = 0; i < n; i++) { - TaskLstFnStatus& tfs = taskListInfo._tlfsLst[i]; + const TaskLstFnStatus& tfs = taskListInfo._tlfsLst[i]; if (tfs._iView != whichOne || tfs._bufID == id) continue; toActivate = tfs._docIndex >= active ? tfs._docIndex - 1 : tfs._docIndex; @@ -4835,7 +4827,7 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode) bool Notepad_plus::activateBuffer(BufferID id, int whichOne, bool forceApplyHilite) { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); bool isSnapshotMode = nppGui.isSnapshotMode(); if (isSnapshotMode) { @@ -5014,7 +5006,7 @@ void Notepad_plus::checkUnicodeMenuItems() const } else { - EncodingMapper& em = EncodingMapper::getInstance(); + const EncodingMapper& em = EncodingMapper::getInstance(); int cmdID = em.getIndexFromEncoding(encoding); if (cmdID == -1) { @@ -5130,7 +5122,7 @@ bool Notepad_plus::doBlockComment(comment_mode currCommentMode) if (buf->getLangType() == L_USER) { - UserLangContainer * userLangContainer = NppParameters::getInstance().getULCFromName(buf->getUserDefineLangName()); + const UserLangContainer* userLangContainer = NppParameters::getInstance().getULCFromName(buf->getUserDefineLangName()); if (!userLangContainer) return false; @@ -5428,7 +5420,7 @@ bool Notepad_plus::doStreamComment() if (buf->getLangType() == L_USER) { - UserLangContainer * userLangContainer = NppParameters::getInstance().getULCFromName(buf->getUserDefineLangName()); + const UserLangContainer* userLangContainer = NppParameters::getInstance().getULCFromName(buf->getUserDefineLangName()); if (!userLangContainer) return false; @@ -5857,7 +5849,7 @@ void Notepad_plus::postItToggle() { if (!_beforeSpecialView._isPostIt) // PostIt disabled, enable it { - NppGUI & nppGUI = NppParameters::getInstance().getNppGUI(); + const NppGUI & nppGUI = NppParameters::getInstance().getNppGUI(); // get current status before switch to postIt //check these always { @@ -6019,7 +6011,7 @@ void Notepad_plus::distractionFreeToggle() } // check if any dockable panel is visible - std::vector & container = _dockingManager.getContainerInfo(); + const std::vector& container = _dockingManager.getContainerInfo(); _beforeSpecialView._pVisibleDockingContainers.clear(); for (auto i : container) { @@ -6117,7 +6109,7 @@ void Notepad_plus::doSynScorll(HWND whichView) bool Notepad_plus::getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible) { - DockingManagerData & dockingData = (DockingManagerData &)(NppParameters::getInstance()).getNppGUI()._dockingData; + const DockingManagerData & dockingData = (DockingManagerData &)(NppParameters::getInstance()).getNppGUI()._dockingData; for (size_t i = 0, len = dockingData._pluginDockInfo.size(); i < len ; ++i) { @@ -6183,11 +6175,11 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD NppParameters& nppParam = NppParameters::getInstance(); const NppGUI& nppGUI = nppParam.getNppGUI(); - for (size_t k = 0; k < nppGUI._excludedLangList.size(); ++k) // try to find it in exclude lang list + for (size_t j = 0; j < nppGUI._excludedLangList.size(); ++j) // try to find it in exclude lang list { - if (buf->getLangType() == nppGUI._excludedLangList[k]._langType) + if (buf->getLangType() == nppGUI._excludedLangList[j]._langType) { - languageName = nppGUI._excludedLangList[k]._langName; + languageName = nppGUI._excludedLangList[j]._langName; break; } } @@ -6630,7 +6622,7 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) _pFuncList->reload(); } - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); bool isCurrBuffDetection = (nppGui._fileAutoDetection & cdEnabledNew) ? true : false; bool reload = buf->getNeedReload(); if (!reload && isCurrBuffDetection) @@ -7884,11 +7876,11 @@ int Notepad_plus::getRandomAction(int ranNum) } -bool isInList(int elem, vector elemList) +bool isInList(int elem, const vector& elemList) { - for (size_t i = 0, len = elemList.size(); i < len; ++i) + for (auto i : elemList) { - if (elem == elemList[i]) + if (elem == i) return true; } return false; @@ -8367,7 +8359,7 @@ void Notepad_plus::refreshDarkMode(bool resetStyle) { //use _stylerPath; - pair& themeInfo = themeSwitcher.getElementFromIndex(0); + const pair& themeInfo = themeSwitcher.getElementFromIndex(0); themePath = themeInfo.second; themeName = themeSwitcher.getDefaultThemeLabel(); } @@ -8488,7 +8480,7 @@ bool Notepad_plus::undoStreamComment(bool tryBlockComment) return false; if (buf->getLangType() == L_USER) { - UserLangContainer* userLangContainer = NppParameters::getInstance().getULCFromName(buf->getUserDefineLangName()); + const UserLangContainer* userLangContainer = NppParameters::getInstance().getULCFromName(buf->getUserDefineLangName()); if (!userLangContainer) return false; diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index e64be906c..6cfde7753 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -280,7 +280,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin } else { - auto& themeInfo = themeSwitcher.getElementFromIndex(0); + const auto& themeInfo = themeSwitcher.getElementFromIndex(0); themePath = themeInfo.second; } diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index b8b24a97d..2a65bff81 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -310,8 +310,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa NppDarkMode::handleSettingChange(hwnd, lParam); const bool enableDarkMode = NppDarkMode::isExperimentalActive(); - - NppParameters& nppParam = NppParameters::getInstance(); NppGUI& nppGUI = nppParam.getNppGUI(); // Windows mode is enabled @@ -2005,7 +2003,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case WM_NOTIFY: { - NMHDR* nmhdr = reinterpret_cast(lParam); + const NMHDR* nmhdr = reinterpret_cast(lParam); if (nmhdr->code == NM_CUSTOMDRAW && (nmhdr->hwndFrom == _toolBar.getHSelf())) { NMTBCUSTOMDRAW* nmtbcd = reinterpret_cast(lParam); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index cbad5bf94..82844ecf5 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1683,7 +1683,7 @@ void Notepad_plus::command(int id) } break; - case IDM_EDIT_COLUMNMODETIP : + case IDM_EDIT_COLUMNMODETIP : { _nativeLangSpeaker.messageBox("ColumnModeTip", _pPublicInterface->getHSelf(), diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 4f3217221..4b9027e6a 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -263,12 +263,12 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive, // Search case 1 & 2 firstly BufferID foundBufID = MainFileManager.getBufferFromName(targetFileName.c_str()); - if (foundBufID == BUFFER_INVALID) - fileName2Find = longFileName; - // if case 1 & 2 not found, search case 3 if (foundBufID == BUFFER_INVALID) + { + fileName2Find = longFileName; foundBufID = MainFileManager.getBufferFromName(fileName2Find.c_str()); + } // If we found the document, then we don't open the existing doc. We return the found buffer ID instead. if (foundBufID != BUFFER_INVALID && !isSnapshotMode) @@ -656,7 +656,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) else { // try to open Notepad++ in admin mode - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); bool isSnapshotMode = nppGui.isSnapshotMode(); bool isAlwaysInMultiInstMode = nppGui._multiInstSetting == multiInst; if (isSnapshotMode && !isAlwaysInMultiInstMode) // if both rememberSession && backup mode are enabled and "Always In Multi-Instance Mode" option not activated: @@ -1625,7 +1625,7 @@ bool Notepad_plus::fileSave(BufferID id) constexpr int temBufLen = 32; TCHAR tmpbuf[temBufLen]{}; time_t ltime = time(0); - struct tm *today; + const struct tm* today; today = localtime(<ime); if (today) diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 6e9e314c2..ae3a4cecb 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -151,8 +151,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin); Buffer *pBuf = MainFileManager.getBufferByID(id); - Buffer *currentBufMain = _mainEditView.getCurrentBuffer(); - Buffer *currentBufSub = _subEditView.getCurrentBuffer(); + const Buffer* currentBufMain = _mainEditView.getCurrentBuffer(); + const Buffer* currentBufSub = _subEditView.getCurrentBuffer(); RECT rect{}; TabCtrl_GetItemRect(pTabDocView->getHSelf(), tbHdr->_tabOrigin, &rect); @@ -179,10 +179,10 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (pTabDocView) { BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin); - Buffer *pBuf = MainFileManager.getBufferByID(id); + Buffer* pBuf = MainFileManager.getBufferByID(id); - Buffer *currentBufMain = _mainEditView.getCurrentBuffer(); - Buffer *currentBufSub = _subEditView.getCurrentBuffer(); + const Buffer* currentBufMain = _mainEditView.getCurrentBuffer(); + const Buffer* currentBufSub = _subEditView.getCurrentBuffer(); if (pBuf != currentBufMain && pBuf != currentBufSub) // if hover on other tab { @@ -478,10 +478,10 @@ BOOL Notepad_plus::notify(SCNotification *notification) } else if (lpnm->dwItemSpec == DWORD(STATUSBAR_UNICODE_TYPE)) { - POINT p; - ::GetCursorPos(&p); + POINT cursorPos; + ::GetCursorPos(&cursorPos); HMENU hLangMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_FORMAT); - TrackPopupMenu(hLangMenu, 0, p.x, p.y, 0, _pPublicInterface->getHSelf(), NULL); + TrackPopupMenu(hLangMenu, 0, cursorPos.x, cursorPos.y, 0, _pPublicInterface->getHSelf(), NULL); } return TRUE; } @@ -1072,7 +1072,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (_syncInfo.doSync()) doSynScorll(HWND(notification->nmhdr.hwndFrom)); - NppParameters& nppParam = NppParameters::getInstance(); + const NppParameters& nppParam = NppParameters::getInstance(); // if it's searching/replacing, then do nothing if ((_linkTriggered && !nppParam._isFindReplacing) || notification->wParam == LINKTRIGGERED) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index b60c309e9..7cfa671bf 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -713,7 +713,7 @@ std::wstring LocalizationSwitcher::getXmlFilePathFromLangName(const wchar_t *lan bool LocalizationSwitcher::addLanguageFromXml(const std::wstring& xmlFullPath) { - wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str()); + const wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str()); wstring foundLang = getLangFromXmlFileName(fn); if (!foundLang.empty()) { @@ -1705,7 +1705,7 @@ void NppParameters::destroyInstance() delete _pXmlUserStylerDoc; //delete _pXmlUserLangDoc; will be deleted in the vector - for (auto& l : _pXmlUserLangsDoc) + for (const auto& l : _pXmlUserLangsDoc) { delete l._udlXmlDoc; } @@ -2244,6 +2244,7 @@ int NppParameters::getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, const bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU pluginsMenu, bool isEditCM) { std::vector& contextMenuItems = isEditCM ? _contextMenuItems : _tabContextMenuItems; + TiXmlDocumentA* pXmlContextMenuDocA = isEditCM ? _pXmlContextMenuDocA : _pXmlTabContextMenuDocA; std::string cmName = isEditCM ? "ScintillaContextMenu" : "TabContextMenu"; @@ -3748,10 +3749,10 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName) // Node structure and naming corresponds to config.xml TiXmlNode* fileBrowserRootNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("FileBrowser"))); fileBrowserRootNode->ToElement()->SetAttribute(TEXT("latestSelectedItem"), session._fileBrowserSelectedItem.c_str()); - for (const auto& root : session._fileBrowserRoots) + for (const auto& fbRoot : session._fileBrowserRoots) { TiXmlNode *fileNameNode = fileBrowserRootNode->InsertEndChild(TiXmlElement(TEXT("root"))); - (fileNameNode->ToElement())->SetAttribute(TEXT("foldername"), root.c_str()); + (fileNameNode->ToElement())->SetAttribute(TEXT("foldername"), fbRoot.c_str()); } } } @@ -4002,7 +4003,6 @@ void NppParameters::feedUserSettings(TiXmlNode *settingsRoot) void NppParameters::feedUserKeywordList(TiXmlNode *node) { const TCHAR * udlVersion = _userLangArray[_nbUserLang - 1]->_udlVersion.c_str(); - int id = -1; for (TiXmlNode *childNode = node->FirstChildElement(TEXT("Keywords")); childNode ; @@ -4016,7 +4016,7 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node) if (!lstrcmp(udlVersion, TEXT("")) && !lstrcmp(keywordsName, TEXT("Delimiters"))) // support for old style (pre 2.0) { basic_string temp; - kwl = (valueNode)?valueNode->Value():TEXT("000000"); + kwl = valueNode->Value(); temp += TEXT("00"); if (kwl[0] != '0') temp += kwl[0]; temp += TEXT(" 01"); temp += TEXT(" 02"); if (kwl[3] != '0') temp += kwl[3]; @@ -4030,7 +4030,7 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node) } else if (!lstrcmp(keywordsName, TEXT("Comment"))) { - kwl = (valueNode)?valueNode->Value():TEXT(""); + kwl = valueNode->Value(); basic_string temp{TEXT(" ")}; temp += kwl; @@ -4063,10 +4063,10 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node) } else { - kwl = (valueNode)?valueNode->Value():TEXT(""); + kwl = valueNode->Value(); if (globalMappper().keywordIdMapper.find(keywordsName) != globalMappper().keywordIdMapper.end()) { - id = globalMappper().keywordIdMapper[keywordsName]; + int id = globalMappper().keywordIdMapper[keywordsName]; if (wcslen(kwl) < max_char) { wcscpy_s(_userLangArray[_nbUserLang - 1]->_keywordLists[id], kwl); @@ -4083,8 +4083,6 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node) void NppParameters::feedUserStyles(TiXmlNode *node) { - int id = -1; - for (TiXmlNode *childNode = node->FirstChildElement(TEXT("WordsStyle")); childNode ; childNode = childNode->NextSibling(TEXT("WordsStyle"))) @@ -4094,7 +4092,7 @@ void NppParameters::feedUserStyles(TiXmlNode *node) { if (globalMappper().styleIdMapper.find(styleName) != globalMappper().styleIdMapper.end()) { - id = globalMappper().styleIdMapper[styleName]; + int id = globalMappper().styleIdMapper[styleName]; _userLangArray[_nbUserLang - 1]->_styles.addStyler((id | L_USER << 16), childNode); } } @@ -8665,7 +8663,7 @@ Date::Date(int nbDaysFromNow) const time_t oneDay = (60 * 60 * 24); time_t rawtime; - tm* timeinfo; + const tm* timeinfo; time(&rawtime); rawtime += (nbDaysFromNow * oneDay); @@ -8682,7 +8680,7 @@ Date::Date(int nbDaysFromNow) void Date::now() { time_t rawtime; - tm* timeinfo; + const tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 032f1c666..3466ece4e 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -210,7 +210,7 @@ struct sessionFileInfo : public Position if (backupFilePath) _backupFilePath = backupFilePath; } - sessionFileInfo(std::wstring fn) : _fileName(fn) {} + sessionFileInfo(const std::wstring& fn) : _fileName(fn) {} std::wstring _fileName; std::wstring _langName; @@ -533,7 +533,7 @@ private : }; struct SortLexersInAlphabeticalOrder { - bool operator() (LexerStyler& l, LexerStyler& r) { + bool operator() (const LexerStyler& l, const LexerStyler& r) { if (!lstrcmp(l.getLexerDesc(), TEXT("Search result"))) return false; if (!lstrcmp(r.getLexerDesc(), TEXT("Search result"))) @@ -1337,7 +1337,7 @@ public: return _themeList[index]; } - void setThemeDirPath(std::wstring themeDirPath) { _themeDirPath = themeDirPath; } + void setThemeDirPath(const std::wstring& themeDirPath) { _themeDirPath = themeDirPath; } std::wstring getThemeDirPath() const { return _themeDirPath; } std::wstring getDefaultThemeLabel() const { return _defaultThemeLabel; } @@ -1354,7 +1354,7 @@ public: } }; - void addThemeStylerSavePath(std::wstring key, std::wstring val) { + void addThemeStylerSavePath(const std::wstring& key, const std::wstring& val) { _themeStylerSavePath[key] = val; }; @@ -1444,7 +1444,7 @@ public: const TCHAR * getWordList(LangType langID, int typeIndex) const { - Lang *pLang = getLangFromID(langID); + const Lang* pLang = getLangFromID(langID); if (!pLang) return nullptr; return pLang->getWords(typeIndex); @@ -1731,9 +1731,9 @@ public: } std::vector & getBlackList() { return _blacklist; }; - bool isInBlackList(TCHAR *fn) const + bool isInBlackList(const wchar_t* fn) const { - for (auto& element: _blacklist) + for (const auto& element: _blacklist) { if (element == fn) return true; diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp index 64795385e..dfb8017f2 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -281,11 +281,11 @@ bool FunctionParsersManager::getOverrideMapFromXmlTree(const generic_string & xm } else if (userDefinedLangName && userDefinedLangName[0]) { + ++_currentUDIndex; + if (_currentUDIndex < L_EXTERNAL + nbMaxUserDefined) { - ++_currentUDIndex; - _parsers[_currentUDIndex] = new ParserInfo(id, userDefinedLangName); - + _parsers[_currentUDIndex] = new ParserInfo(id, userDefinedLangName); } } } diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp index 7af4135e4..4ec462588 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp @@ -416,21 +416,9 @@ private: void installHooks() { - _prevKbdHook = ::SetWindowsHookEx(WH_KEYBOARD, - reinterpret_cast(&FileDialogEventHandler::KbdProcHook), - nullptr, - ::GetCurrentThreadId() - ); - _prevCallHook = ::SetWindowsHookEx(WH_CALLWNDPROC, - reinterpret_cast(&FileDialogEventHandler::CallProcHook), - nullptr, - ::GetCurrentThreadId() - ); - _langaugeDetectHook = ::SetWindowsHookEx(WH_SHELL, - reinterpret_cast(&FileDialogEventHandler::LanguageDetectHook), - nullptr, - ::GetCurrentThreadId() - ); + _prevKbdHook = ::SetWindowsHookEx(WH_KEYBOARD, &FileDialogEventHandler::KbdProcHook, nullptr, ::GetCurrentThreadId()); + _prevCallHook = ::SetWindowsHookEx(WH_CALLWNDPROC, &FileDialogEventHandler::CallProcHook, nullptr, ::GetCurrentThreadId()); + _langaugeDetectHook = ::SetWindowsHookEx(WH_SHELL, &FileDialogEventHandler::LanguageDetectHook, nullptr,::GetCurrentThreadId()); } void removeHooks() diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index a895e3d89..4844c7959 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -25,7 +25,7 @@ using namespace std; -MenuPosition menuPos[] = { +MenuPosition g_menuFolderPositions[] = { //============================================== // {L0, L1, L2, id}, //============================================== @@ -110,6 +110,18 @@ MenuPosition menuPos[] = { { -1, -1, -1, "" } // End of array }; +MenuPosition& getMenuPosition(const char* id) +{ + int nbSubMenuPos = sizeof(g_menuFolderPositions) / sizeof(MenuPosition); + + for (int i = 0; i < nbSubMenuPos; ++i) + { + if (strcmp(g_menuFolderPositions[i]._id, id) == 0) + return g_menuFolderPositions[i]; + } + return g_menuFolderPositions[nbSubMenuPos - 1]; +} + void NativeLangSpeaker::init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish) { if (nativeLangDocRootA) @@ -158,7 +170,7 @@ void NativeLangSpeaker::init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEngl if (declaration) { const char * encodingStr = declaration->Encoding(); - EncodingMapper& em = EncodingMapper::getInstance(); + const EncodingMapper& em = EncodingMapper::getInstance(); int enc = em.getEncodingFromString(encodingStr); _nativeLangEncoding = (enc != -1)?enc:CP_ACP; } @@ -336,20 +348,6 @@ generic_string NativeLangSpeaker::getLocalizedStrFromID(const char *strID, const } - -MenuPosition & getMenuPosition(const char *id) -{ - - int nbSubMenuPos = sizeof(menuPos)/sizeof(MenuPosition); - - for (int i = 0; i < nbSubMenuPos; ++i) - { - if (strcmp(menuPos[i]._id, id) == 0) - return menuPos[i]; - } - return menuPos[nbSubMenuPos-1]; -} - // Get string from map. // If string not found, get string from menu, then put it into map for the next use. void NativeLangSpeaker::getMainMenuEntryName(std::wstring& dest, HMENU hMenu, const char* menuId, const wchar_t* defaultDest) @@ -789,8 +787,8 @@ void NativeLangSpeaker::changeUserDefineLang(UserDefineDialog *userDefineDlg) { if (id == IDC_DOCK_BUTTON && userDefineDlg->isDocked()) { - generic_string name = getAttrNameByIdStr(TEXT("Undock"), userDefineDlgNode, std::to_string(IDC_UNDOCK_BUTTON).c_str()); - ::SetWindowText(hItem, name.c_str()); + generic_string undockStr = getAttrNameByIdStr(TEXT("Undock"), userDefineDlgNode, std::to_string(IDC_UNDOCK_BUTTON).c_str()); + ::SetWindowText(hItem, undockStr.c_str()); } else {