From 391f4281efac81649a02aa8cdd4e765fa76d1237 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 5 Aug 2023 02:58:05 +0200 Subject: [PATCH] Fix leading & tailling spaces being allowed after renaming tab issue Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/13344#issuecomment-1665687932 Fix #13967, close #13967 --- PowerEditor/installer/nativeLang/english.xml | 1 + .../nativeLang/english_customizable.xml | 1 + PowerEditor/installer/nativeLang/french.xml | 1 + .../nativeLang/taiwaneseMandarin.xml | 2 ++ PowerEditor/src/MISC/Common/Common.cpp | 11 +++---- PowerEditor/src/MISC/Common/Common.h | 2 +- PowerEditor/src/NppIO.cpp | 33 ++++++++++++------- 7 files changed, 33 insertions(+), 18 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 6bf1f4935..23c906ba9 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1383,6 +1383,7 @@ Continue?"/> + + + + + : " / \ | ? * std::wstring reservedChars = TEXT("<>:\"/\\|\?*"); - generic_string staticName = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-newname", TEXT("New name")); + std::wstring staticName = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-newname", L"New name"); StringDlg strDlg; - generic_string title = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-title", TEXT("Rename Current Tab")); + std::wstring title = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-title", L"Rename Current Tab"); strDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), title.c_str(), staticName.c_str(), buf->getFileName(), langNameLenMax - 1, reservedChars.c_str(), true); - TCHAR *tabNewName = reinterpret_cast(strDlg.doDialog()); + wchar_t *tabNewName = reinterpret_cast(strDlg.doDialog()); if (tabNewName) { - BufferID sameNamedBufferId = _pDocTab->findBufferByName(tabNewName); + std::wstring tabNewNameStr = tabNewName; + trim(tabNewNameStr); // No leading and tailing space allowed + + BufferID sameNamedBufferId = _pDocTab->findBufferByName(tabNewNameStr.c_str()); if (sameNamedBufferId == BUFFER_INVALID) { - sameNamedBufferId = _pNonDocTab->findBufferByName(tabNewName); + sameNamedBufferId = _pNonDocTab->findBufferByName(tabNewNameStr.c_str()); } if (sameNamedBufferId != BUFFER_INVALID) { _nativeLangSpeaker.messageBox("RenameTabTemporaryNameAlreadyInUse", _pPublicInterface->getHSelf(), - TEXT("The specified name is already in use on another tab."), - TEXT("Rename failed"), + L"The specified name is already in use on another tab.", + L"Rename failed", + MB_OK | MB_ICONSTOP); + } + else if (tabNewNameStr.empty()) + { + _nativeLangSpeaker.messageBox("RenameTabTemporaryNameIsEmpty", + _pPublicInterface->getHSelf(), + L"The specified name cannot be empty, or it cannot contain only space(s) or TAB(s).", + L"Rename failed", MB_OK | MB_ICONSTOP); } else { success = true; - buf->setFileName(tabNewName); + buf->setFileName(tabNewNameStr.c_str()); bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode(); if (isSnapshotMode) { - generic_string oldBackUpFile = buf->getBackupFileName(); + std::wstring oldBackUpFile = buf->getBackupFileName(); // Change the backup file name and let MainFileManager decide the new filename buf->setBackupFileName(TEXT(""));