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++?"/> <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"/> <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. --> <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. --> <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. <NbFileToOpenImportantWarning title="Amount of files to open is too large" message="$INT_REPLACE$ files are about to be opened.

View File

@ -1740,6 +1740,22 @@ bool Notepad_plus::fileRename(BufferID id)
TCHAR *tabNewName = reinterpret_cast<TCHAR *>(strDlg.doDialog()); TCHAR *tabNewName = reinterpret_cast<TCHAR *>(strDlg.doDialog());
if (tabNewName) if (tabNewName)
{
BufferID sameNamedBufferId = _pDocTab->findBufferByName(tabNewName);
if (sameNamedBufferId == BUFFER_INVALID)
{
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; success = true;
buf->setFileName(tabNewName); buf->setFileName(tabNewName);
@ -1761,6 +1777,7 @@ bool Notepad_plus::fileRename(BufferID id)
} }
} }
} }
}
scnN.nmhdr.code = success ? NPPN_FILERENAMED : NPPN_FILERENAMECANCEL; scnN.nmhdr.code = success ? NPPN_FILERENAMED : NPPN_FILERENAMECANCEL;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);