]> git.saurik.com Git - wxWidgets.git/commitdiff
specify the file name in IO errors messages; also make Do{Open,Save}Document() use...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 25 Sep 2008 16:27:22 +0000 (16:27 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 25 Sep 2008 16:27:22 +0000 (16:27 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55873 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/docview.cpp

index 2fa45c7e2cffd466808775413612d5d117c7315e..e308d867c016d9ae5ce405854fd12d13e4a5d06d 100644 (file)
@@ -580,12 +580,6 @@ void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
 
 bool wxDocument::DoSaveDocument(const wxString& file)
 {
-    wxString msgTitle;
-    if (!wxTheApp->GetAppDisplayName().empty())
-        msgTitle = wxTheApp->GetAppDisplayName();
-    else
-        msgTitle = wxString(_("File error"));
-
 #if wxUSE_STD_IOSTREAM
     wxSTD ofstream store(file.mb_str(), wxSTD ios::binary);
     if (store.fail() || store.bad())
@@ -594,16 +588,13 @@ bool wxDocument::DoSaveDocument(const wxString& file)
     if (store.GetLastError() != wxSTREAM_NO_ERROR)
 #endif
     {
-        (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION,
-                           GetDocumentWindow());
-        // Saving error
+        wxLogError(_("File \"%s\" could not be opened for writing."), file);
         return false;
     }
+
     if (!SaveObject(store))
     {
-        (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
-                           GetDocumentWindow());
-        // Saving error
+        wxLogError(_("Failed to save document to the file \"%s\"."), file);
         return false;
     }
 
@@ -614,24 +605,29 @@ bool wxDocument::DoOpenDocument(const wxString& file)
 {
 #if wxUSE_STD_IOSTREAM
     wxSTD ifstream store(file.mb_str(), wxSTD ios::binary);
-    if (!store.fail() && !store.bad())
+    if ( store.fail() || store.bad() )
 #else
     wxFileInputStream store(file);
-    if (store.GetLastError() == wxSTREAM_NO_ERROR)
+    if (store.GetLastError() != wxSTREAM_NO_ERROR)
 #endif
     {
+        wxLogError(_("File \"%s\" could not be opened for reading."), file);
+        return false;
+    }
+
 #if wxUSE_STD_IOSTREAM
-        LoadObject(store);
-        if ( !!store || store.eof() )
+    LoadObject(store);
+    if ( store.fail() || store.bad() )
 #else
-        int res = LoadObject(store).GetLastError();
-        if ( res == wxSTREAM_NO_ERROR || res == wxSTREAM_EOF )
+    int res = LoadObject(store).GetLastError();
+    if ( res != wxSTREAM_NO_ERROR && res != wxSTREAM_EOF )
 #endif
-            return true;
+    {
+        wxLogError(_("Failed to read document from the file \"%s\"."), file);
+        return false;
     }
 
-    wxLogError(_("Sorry, could not open this file."));
-    return false;
+    return true;
 }