Don't add default extension in wxDocument::SaveAs().

wxFileSelector() takes care of the default extension itself and if it returned
a file name without one, it means that the user really wants to create a file
without an extension. Adding the default extension here is at best useless and
at worst actively dangerous because it may silently overwrite an existing file
(although this bug is due to a different problem, see #11256 for a scenario in
which this can happen).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-10-09 13:05:10 +00:00
parent 8462a84b2c
commit fd4618549b

View File

@ -339,15 +339,6 @@ bool wxDocument::SaveAs()
if (fileName.empty())
return false; // cancelled by user
wxString ext;
wxFileName::SplitPath(fileName, NULL, NULL, &ext);
if (ext.empty())
{
fileName += wxT(".");
fileName += docTemplate->GetDefaultExtension();
}
// Files that were not saved correctly are not added to the FileHistory.
if (!OnSaveDocument(fileName))
return false;
@ -355,16 +346,16 @@ bool wxDocument::SaveAs()
SetTitle(wxFileNameFromPath(fileName));
SetFilename(fileName, true); // will call OnChangeFileName automatically
// A file that doesn't use the default extension of its document template
// cannot be opened via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName))
{
GetDocumentManager()->AddFileToHistory(fileName);
}
//else: the user will probably not be able to open the file again, so we
// could warn about the wrong file-extension here
// A file that doesn't use the default extension of its document template
// cannot be opened via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName))
{
GetDocumentManager()->AddFileToHistory(fileName);
}
//else: the user will probably not be able to open the file again, so we
// could warn about the wrong file-extension here
return true;
return true;
}
bool wxDocument::OnSaveDocument(const wxString& file)