From b78b3bdef0eb4d7e66e41aabac1ce2489bad15fb Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 5 Aug 2024 14:44:04 +0200 Subject: [PATCH] Several enhancements for code Close #15516 --- PowerEditor/src/MISC/Common/Common.cpp | 10 +++---- PowerEditor/src/MISC/Common/Common.h | 2 +- .../src/MISC/Common/verifySignedfile.cpp | 4 +-- PowerEditor/src/MISC/Exception/MiniDumper.cpp | 2 +- .../MISC/PluginsManager/PluginsManager.cpp | 10 +++---- PowerEditor/src/Notepad_plus.cpp | 4 +-- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/Notepad_plus_Window.cpp | 2 +- PowerEditor/src/NppBigSwitch.cpp | 2 +- PowerEditor/src/NppCommands.cpp | 20 +++++-------- PowerEditor/src/NppIO.cpp | 12 ++++---- PowerEditor/src/NppNotification.cpp | 1 - PowerEditor/src/Parameters.cpp | 2 +- PowerEditor/src/ScintillaComponent/Buffer.cpp | 30 +++++++++---------- PowerEditor/src/ScintillaComponent/Buffer.h | 6 ++-- .../ScintillaComponent/FunctionCallTip.cpp | 4 +-- PowerEditor/src/winmain.cpp | 2 +- 17 files changed, 52 insertions(+), 63 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 1e92386fc..679ce6293 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -68,7 +68,7 @@ std::string getFileContent(const wchar_t *file2read) do { lenFile = fread(data, 1, blockSize, fp); - if (lenFile <= 0) break; + if (lenFile == 0) break; wholeFileContent.append(data, lenFile); } while (lenFile > 0); @@ -94,11 +94,11 @@ char getDriveLetter() wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath) { wstring fullFilePathName; - wchar_t fullFileName[MAX_PATH]; BOOL isRelative = ::PathIsRelative(relativeFilePath); if (isRelative) { + wchar_t fullFileName[MAX_PATH]; ::GetFullPathName(relativeFilePath, MAX_PATH, fullFileName, NULL); fullFilePathName += fullFileName; } @@ -953,7 +953,7 @@ bool matchInExcludeDirList(const wchar_t* dirName, const std::vector& p return false; } -bool allPatternsAreExclusion(const std::vector patterns) +bool allPatternsAreExclusion(const std::vector& patterns) { bool oneInclusionPatternFound = false; for (size_t i = 0, len = patterns.size(); i < len; ++i) @@ -1096,8 +1096,6 @@ bool isCertificateValidated(const wstring & fullFilePath, const wstring & subjec CERT_INFO CertInfo{}; LPTSTR szName = NULL; - wstring subjectName; - try { // Get message handle and store handle from the signed file. result = CryptQueryObject(CERT_QUERY_OBJECT_FILE, @@ -1182,7 +1180,7 @@ bool isCertificateValidated(const wstring & fullFilePath, const wstring & subjec } // check Subject name. - subjectName = szName; + wstring subjectName = szName; if (subjectName != subjectName2check) { throw wstring(L"Certificate checking error: the certificate is not matched."); diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 9e45397f3..7717f80fd 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -75,7 +75,7 @@ std::wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath); void writeFileContent(const wchar_t *file2write, const char *content2write); bool matchInList(const wchar_t *fileName, const std::vector & patterns); bool matchInExcludeDirList(const wchar_t* dirName, const std::vector& patterns, size_t level); -bool allPatternsAreExclusion(const std::vector patterns); +bool allPatternsAreExclusion(const std::vector& patterns); class WcharMbcsConvertor final { diff --git a/PowerEditor/src/MISC/Common/verifySignedfile.cpp b/PowerEditor/src/MISC/Common/verifySignedfile.cpp index c72667c62..26d65059a 100644 --- a/PowerEditor/src/MISC/Common/verifySignedfile.cpp +++ b/PowerEditor/src/MISC/Common/verifySignedfile.cpp @@ -78,7 +78,7 @@ bool SecurityGuard::checkSha256(const std::wstring& filePath, NppModule module2c for (size_t i = 0; i < 32; i++) wsprintf(sha2hashStr + i * 2, L"%02x", sha2hash[i]); - std::vector* moduleSha256 = nullptr; + const std::vector* moduleSha256 = nullptr; if (module2check == nm_gup) moduleSha256 = &_gupSha256; @@ -87,7 +87,7 @@ bool SecurityGuard::checkSha256(const std::wstring& filePath, NppModule module2c else return false; - for (auto i : *moduleSha256) + for (const auto& i : *moduleSha256) { if (i == sha2hashStr) { diff --git a/PowerEditor/src/MISC/Exception/MiniDumper.cpp b/PowerEditor/src/MISC/Exception/MiniDumper.cpp index 560dae317..4626cca83 100644 --- a/PowerEditor/src/MISC/Exception/MiniDumper.cpp +++ b/PowerEditor/src/MISC/Exception/MiniDumper.cpp @@ -29,7 +29,6 @@ MiniDumper::MiniDumper() bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo) { - wchar_t szDumpPath[MAX_PATH]; wchar_t szScratch[MAX_PATH]; LPCTSTR szResult = NULL; bool retval = false; @@ -41,6 +40,7 @@ bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo) MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" ); if (pDump) { + wchar_t szDumpPath[MAX_PATH]; ::GetModuleFileName(NULL, szDumpPath, MAX_PATH); ::PathRemoveFileSpec(szDumpPath); wcscat_s(szDumpPath, L"\\NppDump.dmp"); diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index ca6f8b7d3..a9b03f4ef 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -358,12 +358,12 @@ bool PluginsManager::loadPlugins(const wchar_t* dir, const PluginViewList* plugi Version nppVer; nppVer.setVersionFrom(nppFullPathName); - const wchar_t* incompatibleWarning = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded."; - const wchar_t* incompatibleWarningWithSolution = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded.\r\n\r\nGo to Updates section and update your plugin to %s for solving the compatibility issue."; - // get plugin folder if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + const wchar_t* incompatibleWarning = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded."; + const wchar_t* incompatibleWarningWithSolution = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded.\r\n\r\nGo to Updates section and update your plugin to %s for solving the compatibility issue."; + wstring foundFileName = foundData.cFileName; if (foundFileName != L"." && foundFileName != L".." && wcsicmp(foundFileName.c_str(), L"Config") != 0) { @@ -441,7 +441,6 @@ bool PluginsManager::loadPlugins(const wchar_t* dir, const PluginViewList* plugi { wstring pluginsFullPathFilter2 = pluginsFolder; pathAppend(pluginsFullPathFilter2, foundFileName2); - wstring pluginsFolderPath2 = pluginsFullPathFilter2; wstring dllName2 = foundFileName2; dllName2 += L".dll"; pathAppend(pluginsFullPathFilter2, dllName2); @@ -630,13 +629,12 @@ HMENU PluginsManager::initMenu(HMENU hMenu, bool enablePluginAdmin) { _hPluginsMenu = ::GetSubMenu(hMenu, MENUINDEX_PLUGINS); - int i = 1; - if (nbPlugin > 0) ::InsertMenu(_hPluginsMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, L""); if (enablePluginAdmin) { + int i = 1; ::InsertMenu(_hPluginsMenu, i++, MF_BYPOSITION, IDM_SETTING_PLUGINADM, L"Plugins Admin..."); ::InsertMenu(_hPluginsMenu, i++, MF_BYPOSITION | MF_SEPARATOR, 0, L""); } diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0d1c95a4f..01031104b 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3217,7 +3217,7 @@ bool scanToUrlStart(wchar_t *text, int textLen, int start, int* distance, int* s // The query pattern going through looks like this: // - ?abc;def;fgh="i j k"&'l m n'+opq // -void scanToUrlEnd(wchar_t *text, int textLen, int start, int* distance) +void scanToUrlEnd(const wchar_t *text, int textLen, int start, int* distance) { int p = start; wchar_t q = 0; @@ -9048,7 +9048,7 @@ void Notepad_plus::changedHistoryGoTo(int idGoTo) } } -HMENU Notepad_plus::createMenuFromMenu(HMENU hSourceMenu, std::vector& commandIds) +HMENU Notepad_plus::createMenuFromMenu(HMENU hSourceMenu, const std::vector& commandIds) { HMENU hNewMenu = ::CreatePopupMenu(); for (const auto& cmdID : commandIds) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index b5a24143f..ce03b7cb1 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -655,7 +655,7 @@ private: void clearChangesHistory(); void changedHistoryGoTo(int idGoTo); - HMENU createMenuFromMenu(HMENU hSourceMenu, std::vector& commandIds); + HMENU createMenuFromMenu(HMENU hSourceMenu, const std::vector& commandIds); BOOL notifyTBShowMenu(LPNMTOOLBARW lpnmtb, const char* menuPosId); BOOL notifyTBShowMenu(LPNMTOOLBARW lpnmtb, const char* menuPosId, std::vector cmdIDs); }; diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 79b2f5423..436912025 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -228,7 +228,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const wchar_t *cmdL fileNames.clear(); - wstring nppThemeDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy + wstring nppThemeDir = nppDir; // <- should use the pointer to avoid the constructor of copy pathAppend(nppThemeDir, L"themes\\"); // Set theme directory to their installation directory diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index cb8c70335..37ad04479 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -487,7 +487,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa { // Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND constexpr int strSize = FINDREPLACE_MAXLENGTH; - wchar_t str[strSize]{}; bool isFirstTime = !_findReplaceDlg.isCreated(); _findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL()); @@ -495,6 +494,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa const NppGUI & nppGui = nppParam.getNppGUI(); if (nppGui._fillFindFieldWithSelected) { + wchar_t str[strSize]{}; _pEditView->getGenericSelectedText(str, strSize, nppGui._fillFindFieldSelectCaret); _findReplaceDlg.setSearchText(str); } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index f792a1f60..b0012f473 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -192,7 +192,7 @@ void Notepad_plus::command(int id) case IDM_FILE_OPENFOLDERASWORSPACE: { - NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); + const NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); wstring openWorkspaceStr = pNativeSpeaker->getAttrNameStr(L"Select a folder to add in Folder as Workspace panel", FOLDERASWORKSPACE_NODE, "SelectFolderFromBrowserString"); wstring folderPath = folderBrowser(_pPublicInterface->getHSelf(), openWorkspaceStr); @@ -977,7 +977,7 @@ void Notepad_plus::command(int id) { if (_pFileBrowser == nullptr) // first launch, check in params to open folders { - NppParameters& nppParam = NppParameters::getInstance(); + const NppParameters& nppParam = NppParameters::getInstance(); launchFileBrowser(nppParam.getFileBrowserRoots(), nppParam.getFileBrowserSelectedItemPath()); if (_pFileBrowser != nullptr) { @@ -1384,7 +1384,7 @@ void Notepad_plus::command(int id) if (_findReplaceDlg.isCreated()) { FindOption op = _findReplaceDlg.getCurrentOptions(); - NppParameters& nppParams = NppParameters::getInstance(); + const NppParameters& nppParams = NppParameters::getInstance(); if ((id == IDM_SEARCH_FINDPREV) && (op._searchType == FindRegex) && !nppParams.regexBackward4PowerUser()) { // regex upward search is disabled @@ -2452,7 +2452,7 @@ void Notepad_plus::command(int id) // Don't put the quots for Edge, otherwise it doesn't work //fullCurrentPath = L"\""; - wstring fullCurrentPath = currentBuf->getFullPathName(); + fullCurrentPath = currentBuf->getFullPathName(); //fullCurrentPath += L"\""; ::ShellExecute(NULL, L"open", L"shell:Appsfolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", fullCurrentPath.c_str(), NULL, SW_SHOW); @@ -2685,8 +2685,6 @@ void Notepad_plus::command(int id) case IDM_VIEW_SUMMARY: { - wstring characterNumber = L""; - Buffer * curBuf = _pEditView->getCurrentBuffer(); int64_t fileLen = curBuf->getFileLength(); @@ -2694,6 +2692,7 @@ void Notepad_plus::command(int id) NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); if (pNativeSpeaker) { + wstring characterNumber = L""; if (fileLen != -1) { @@ -2886,7 +2885,6 @@ void Notepad_plus::command(int id) if (_pEditView->execute(SCI_CANUNDO) == TRUE) { - wstring msg, title; int answer = _nativeLangSpeaker.messageBox("LoseUndoAbilityWarning", _pPublicInterface->getHSelf(), L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?", @@ -2969,7 +2967,7 @@ void Notepad_plus::command(int id) { int index = id - IDM_FORMAT_ENCODE; - EncodingMapper& em = EncodingMapper::getInstance(); + const EncodingMapper& em = EncodingMapper::getInstance(); int encoding = em.getEncodingFromIndex(index); if (encoding == -1) { @@ -2980,7 +2978,6 @@ void Notepad_plus::command(int id) Buffer* buf = _pEditView->getCurrentBuffer(); if (buf->isDirty()) { - wstring warning, title; int answer = _nativeLangSpeaker.messageBox("SaveCurrentModifWarning", _pPublicInterface->getHSelf(), L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?", @@ -2998,7 +2995,6 @@ void Notepad_plus::command(int id) if (_pEditView->execute(SCI_CANUNDO) == TRUE) { - wstring msg, title; int answer = _nativeLangSpeaker.messageBox("LoseUndoAbilityWarning", _pPublicInterface->getHSelf(), L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?", @@ -3342,7 +3338,7 @@ void Notepad_plus::command(int id) L"Editing contextMenu", MB_OK|MB_APPLMODAL); - NppParameters& nppParams = NppParameters::getInstance(); + const NppParameters& nppParams = NppParameters::getInstance(); BufferID bufID = doOpen((nppParams.getContextMenuPath())); switchToFile(bufID); break; @@ -4230,7 +4226,7 @@ void Notepad_plus::command(int id) else if ((id >= ID_USER_CMD) && (id < ID_USER_CMD_LIMIT)) { int i = id - ID_USER_CMD; - vector & theUserCommands = (NppParameters::getInstance()).getUserCommandList(); + const vector & theUserCommands = (NppParameters::getInstance()).getUserCommandList(); UserCommand ucmd = theUserCommands[i]; Command cmd(string2wstring(ucmd.getCmd(), CP_UTF8)); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 221df5e20..49b4630a4 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -262,9 +262,6 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is } _lastRecentFileList.remove(longFileName); - wstring fileName2Find; - wstring gs_fileName{ targetFileName }; - // "fileName" could be: // 1. full file path to open or create @@ -277,6 +274,7 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is // if case 1 & 2 not found, search case 3 if (foundBufID == BUFFER_INVALID) { + wstring fileName2Find; fileName2Find = longFileName; foundBufID = MainFileManager.getBufferFromName(fileName2Find.c_str()); } @@ -1652,7 +1650,7 @@ bool Notepad_plus::fileSave(BufferID id) // Get the current file's directory wstring path = fn; ::PathRemoveFileSpec(path); - fn_bak = path.c_str(); + fn_bak = path; fn_bak += L"\\"; // If verbose, save it in a sub folder @@ -1906,7 +1904,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) if (res && isSaveCopy && fDlg.getOpenTheCopyAfterSaveAsCopy()) { - BufferID bid = doOpen(fn.c_str()); + BufferID bid = doOpen(fn); if (bid != BUFFER_INVALID) { switchToFile(bid); @@ -2605,9 +2603,9 @@ bool Notepad_plus::fileLoadSession(const wchar_t *fn) { CustomFileDialog fDlg(_pPublicInterface->getHSelf()); const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedSessionExt.c_str(); - wstring sessionExt = L""; if (*ext != '\0') { + wstring sessionExt = L""; if (*ext != '.') sessionExt += L"."; sessionExt += ext; @@ -2703,9 +2701,9 @@ const wchar_t * Notepad_plus::fileSaveSession(size_t nbFile, wchar_t ** fileName CustomFileDialog fDlg(_pPublicInterface->getHSelf()); const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedSessionExt.c_str(); - wstring sessionExt = L""; if (*ext != '\0') { + wstring sessionExt = L""; if (*ext != '.') sessionExt += L"."; sessionExt += ext; diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index b27017462..a263b008f 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -283,7 +283,6 @@ BOOL Notepad_plus::notify(SCNotification *notification) int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; if (buf->isDirty()) { - wstring msg, title; _nativeLangSpeaker.messageBox("CannotMoveDoc", _pPublicInterface->getHSelf(), L"Document is modified, save it then try again.", diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 5e6a57bc2..085325e53 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2288,7 +2288,7 @@ void NppParameters::setWorkingDir(const wchar_t * newPath) if (doesDirectoryExist(_nppGUI._defaultDirExp)) _currentDirectory = _nppGUI._defaultDirExp; else - _currentDirectory = _nppPath.c_str(); + _currentDirectory = _nppPath; } } diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index e7185fffb..7720a2f83 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -441,7 +441,7 @@ wstring Buffer::getFileTime(fileTimeType ftt) const } -void Buffer::setPosition(const Position & pos, ScintillaEditView * identifier) +void Buffer::setPosition(const Position & pos, const ScintillaEditView * identifier) { int index = indexOfReference(identifier); if (index == -1) @@ -450,7 +450,7 @@ void Buffer::setPosition(const Position & pos, ScintillaEditView * identifier) } -Position& Buffer::getPosition(ScintillaEditView* identifier) +Position& Buffer::getPosition(const ScintillaEditView* identifier) { int index = indexOfReference(identifier); return _positions.at(index); @@ -522,7 +522,7 @@ int Buffer::addReference(ScintillaEditView * identifier) } -int Buffer::removeReference(ScintillaEditView * identifier) +int Buffer::removeReference(const ScintillaEditView * identifier) { int indexToPop = indexOfReference(identifier); if (indexToPop == -1) @@ -560,25 +560,25 @@ void Buffer::setDeferredReload() // triggers a reload on the next Document acces bool Buffer::allowBraceMach() const { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); return (!_isLargeFile || nppGui._largeFileRestriction._allowBraceMatch) || !nppGui._largeFileRestriction._isEnabled; } bool Buffer::allowAutoCompletion() const { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); return (!_isLargeFile || nppGui._largeFileRestriction._allowAutoCompletion) || !nppGui._largeFileRestriction._isEnabled; } bool Buffer::allowSmartHilite() const { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); return (!_isLargeFile || nppGui._largeFileRestriction._allowSmartHilite) || !nppGui._largeFileRestriction._isEnabled; } bool Buffer::allowClickableLink() const { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); return (!_isLargeFile || nppGui._largeFileRestriction._allowClickableLink) || !nppGui._largeFileRestriction._isEnabled; } @@ -711,7 +711,7 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi // * the auto-completion feature will be disabled for large files // * the session snapshotsand periodic backups feature will be disabled for large files // * the backups on save feature will be disabled for large files - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); bool isLargeFile = false; if (nppGui._largeFileRestriction._isEnabled) isLargeFile = fileSize >= nppGui._largeFileRestriction._largeFileSizeDefInByte; @@ -765,11 +765,11 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi loadedFileFormat._eolFormat = EolType::unknown; loadedFileFormat._language = L_TEXT; - bool res = loadFileData(doc, fileSize, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, loadedFileFormat); + bool loadRes = loadFileData(doc, fileSize, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, loadedFileFormat); delete[] data; - if (res) + if (loadRes) { Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath, isLargeFile); BufferID id = newBuf; @@ -893,7 +893,7 @@ bool FileManager::reloadBufferDeferred(BufferID id) bool FileManager::deleteFile(BufferID id) { - Buffer* buf = getBufferByID(id); + const Buffer* buf = getBufferByID(id); wstring fileNamePath = buf->getFullPathName(); // Make sure to form a string with double '\0' terminator. @@ -1014,7 +1014,7 @@ bool FileManager::backupCurrentBuffer() const int temBufLen = 32; wchar_t tmpbuf[temBufLen]; time_t ltime = time(0); - struct tm* today = localtime(<ime); + const struct tm* today = localtime(<ime); if (!today) return false; @@ -1574,7 +1574,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f } else // x64 { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); if (!nppGui._largeFileRestriction._suppress2GBWarning) { int res = pNativeSpeaker->messageBox("WantToOpenHugeFile", @@ -1654,7 +1654,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f if (isFirstTime) { - NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); + const NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); // check if file contain any BOM if (Utf8_16_Read::determineEncoding((unsigned char *)data, lenFile) != uni8Bit) @@ -1831,7 +1831,7 @@ int FileManager::getFileNameFromBuffer(BufferID id, wchar_t * fn2copy) if (getBufferIndexByID(id) == -1) return -1; - Buffer* buf = getBufferByID(id); + const Buffer* buf = getBufferByID(id); if (fn2copy) lstrcpy(fn2copy, buf->getFullPathName()); diff --git a/PowerEditor/src/ScintillaComponent/Buffer.h b/PowerEditor/src/ScintillaComponent/Buffer.h index 44fdca34a..27d42efcb 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.h +++ b/PowerEditor/src/ScintillaComponent/Buffer.h @@ -228,8 +228,8 @@ public: void setDirty(bool dirty); - void setPosition(const Position & pos, ScintillaEditView * identifier); - Position & getPosition(ScintillaEditView * identifier); + void setPosition(const Position & pos, const ScintillaEditView * identifier); + Position & getPosition(const ScintillaEditView * identifier); void setHeaderLineState(const std::vector & folds, ScintillaEditView * identifier); const std::vector & getHeaderLineState(const ScintillaEditView * identifier) const; @@ -268,7 +268,7 @@ public: //these two return reference count after operation int addReference(ScintillaEditView * identifier); //if ID not registered, creates a new Position for that ID and new foldstate - int removeReference(ScintillaEditView * identifier); //reduces reference. If zero, Document is purged + int removeReference(const ScintillaEditView * identifier); //reduces reference. If zero, Document is purged void setHideLineChanged(bool isHide, size_t location); diff --git a/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp b/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp index 7173df50e..419f15677 100644 --- a/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp +++ b/PowerEditor/src/ScintillaComponent/FunctionCallTip.cpp @@ -404,7 +404,7 @@ void FunctionCallTip::showCalltip() callTipText << L"\001" << _currentOverload + 1 << L" of " << _currentNbOverloads << L"\002"; } - callTipText << _retVals.at(_currentOverload) << TEXT(' ') << _funcName << TEXT(' ') << _start; + callTipText << _retVals.at(_currentOverload) << ' ' << _funcName << ' ' << _start; int highlightstart = 0; int highlightend = 0; @@ -418,7 +418,7 @@ void FunctionCallTip::showCalltip() } callTipText << params.at(i); if (i < nbParams - 1) - callTipText << _param << TEXT(' '); + callTipText << _param << ' '; } callTipText << _stop; diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 77ae1cbe8..203ed1eb5 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -253,7 +253,7 @@ std::wstring getLocalizationPathFromParam(ParamVector & params) if (!getParamVal('L', params, locStr)) return L""; locStr = stringToLower(stringReplace(locStr, L"_", L"-")); // convert to lowercase format with "-" as separator - return NppParameters::getLocPathFromStr(locStr.c_str()); + return NppParameters::getLocPathFromStr(locStr); } intptr_t getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent)