Prevent names of untitled tabs from duplication

Fix #9119, close #9127
This commit is contained in:
Scott Sumner 2020-11-08 08:49:28 -05:00 committed by Don HO
parent 0405e230eb
commit f75f8b8d40
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
2 changed files with 31 additions and 13 deletions

View File

@ -1119,6 +1119,7 @@ Continue?"/> <!-- HowToReproduce: when you openned file is modified and saved, t
<DocReloadWarning title="Reload" message="Are you sure you want to reload the current file and lose the changes made in Notepad++?"/>
<FileLockedWarning title="Save failed" message="Please check whether if this file is opened in another program"/>
<FileAlreadyOpenedInNpp title="" message="The file is already opened in Notepad++."/> <!-- HowToReproduce: Open a new document and open a file "c:/tmp/foo", save this new document by choosing "c:/tmp/foo" as file to save, reply the override popup "yes", then this message appears. -->
<RenameTabTemporaryNameAlreadyInUse title="Rename failed" message="The specified name is already in use on another tab."/> <!-- HowToReproduce: Rename the tab of an untitled document and provide a name that is the same as an already-existing tab of an untitled document. -->
<DeleteFileFailed title="Delete File" message="Delete File failed"/> <!-- HowToReproduce: this message prevents from system failure. It's hard to reproduce. -->
<NbFileToOpenImportantWarning title="Amount of files to open is too large" message="$INT_REPLACE$ files are about to be opened.

View File

@ -1741,23 +1741,40 @@ bool Notepad_plus::fileRename(BufferID id)
TCHAR *tabNewName = reinterpret_cast<TCHAR *>(strDlg.doDialog());
if (tabNewName)
{
success = true;
buf->setFileName(tabNewName);
bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode();
if (isSnapshotMode)
BufferID sameNamedBufferId = _pDocTab->findBufferByName(tabNewName);
if (sameNamedBufferId == BUFFER_INVALID)
{
generic_string oldBackUpFile = buf->getBackupFileName();
sameNamedBufferId = _pNonDocTab->findBufferByName(tabNewName);
}
if (sameNamedBufferId != BUFFER_INVALID)
{
_nativeLangSpeaker.messageBox("RenameTabTemporaryNameAlreadyInUse",
_pPublicInterface->getHSelf(),
TEXT("The specified name is already in use on another tab."),
TEXT("Rename failed"),
MB_OK | MB_ICONSTOP);
}
else
{
success = true;
buf->setFileName(tabNewName);
bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode();
if (isSnapshotMode)
{
generic_string oldBackUpFile = buf->getBackupFileName();
// Change the backup file name and let MainFileManager decide the new filename
buf->setBackupFileName(TEXT(""));
// Change the backup file name and let MainFileManager decide the new filename
buf->setBackupFileName(TEXT(""));
// Create new backup
buf->setModifiedStatus(true);
bool bRes = MainFileManager.backupCurrentBuffer();
// Create new backup
buf->setModifiedStatus(true);
bool bRes = MainFileManager.backupCurrentBuffer();
// Delete old backup
if (bRes)
::DeleteFile(oldBackUpFile.c_str());
// Delete old backup
if (bRes)
::DeleteFile(oldBackUpFile.c_str());
}
}
}
}