specify the file name in IO errors messages; also make Do{Open,Save}Document() use the same logic flow
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55873 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -580,12 +580,6 @@ void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
|
|||||||
|
|
||||||
bool wxDocument::DoSaveDocument(const wxString& file)
|
bool wxDocument::DoSaveDocument(const wxString& file)
|
||||||
{
|
{
|
||||||
wxString msgTitle;
|
|
||||||
if (!wxTheApp->GetAppDisplayName().empty())
|
|
||||||
msgTitle = wxTheApp->GetAppDisplayName();
|
|
||||||
else
|
|
||||||
msgTitle = wxString(_("File error"));
|
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
#if wxUSE_STD_IOSTREAM
|
||||||
wxSTD ofstream store(file.mb_str(), wxSTD ios::binary);
|
wxSTD ofstream store(file.mb_str(), wxSTD ios::binary);
|
||||||
if (store.fail() || store.bad())
|
if (store.fail() || store.bad())
|
||||||
@@ -594,16 +588,13 @@ bool wxDocument::DoSaveDocument(const wxString& file)
|
|||||||
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
(void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION,
|
wxLogError(_("File \"%s\" could not be opened for writing."), file);
|
||||||
GetDocumentWindow());
|
|
||||||
// Saving error
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SaveObject(store))
|
if (!SaveObject(store))
|
||||||
{
|
{
|
||||||
(void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
|
wxLogError(_("Failed to save document to the file \"%s\"."), file);
|
||||||
GetDocumentWindow());
|
|
||||||
// Saving error
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,24 +605,29 @@ bool wxDocument::DoOpenDocument(const wxString& file)
|
|||||||
{
|
{
|
||||||
#if wxUSE_STD_IOSTREAM
|
#if wxUSE_STD_IOSTREAM
|
||||||
wxSTD ifstream store(file.mb_str(), wxSTD ios::binary);
|
wxSTD ifstream store(file.mb_str(), wxSTD ios::binary);
|
||||||
if (!store.fail() && !store.bad())
|
if ( store.fail() || store.bad() )
|
||||||
#else
|
#else
|
||||||
wxFileInputStream store(file);
|
wxFileInputStream store(file);
|
||||||
if (store.GetLastError() == wxSTREAM_NO_ERROR)
|
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if wxUSE_STD_IOSTREAM
|
wxLogError(_("File \"%s\" could not be opened for reading."), file);
|
||||||
LoadObject(store);
|
return false;
|
||||||
if ( !!store || store.eof() )
|
|
||||||
#else
|
|
||||||
int res = LoadObject(store).GetLastError();
|
|
||||||
if ( res == wxSTREAM_NO_ERROR || res == wxSTREAM_EOF )
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLogError(_("Sorry, could not open this file."));
|
#if wxUSE_STD_IOSTREAM
|
||||||
return false;
|
LoadObject(store);
|
||||||
|
if ( store.fail() || store.bad() )
|
||||||
|
#else
|
||||||
|
int res = LoadObject(store).GetLastError();
|
||||||
|
if ( res != wxSTREAM_NO_ERROR && res != wxSTREAM_EOF )
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
wxLogError(_("Failed to read document from the file \"%s\"."), file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user