bool wxDocument::Save()
{
- if (!IsModified() && m_savedYet)
+ if ( AlreadySaved() )
return true;
if ( m_documentFile.empty() || !m_savedYet )
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())
+ if ( !store )
#else
wxFileOutputStream store(file);
- if (store.GetLastError() != wxSTREAM_NO_ERROR)
+ 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;
}
{
#if wxUSE_STD_IOSTREAM
wxSTD ifstream store(file.mb_str(), wxSTD ios::binary);
- if (!store.fail() && !store.bad())
+ if ( !store )
#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 )
#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;
}
void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event))
{
- CreateDocument( wxEmptyString, wxDOC_NEW );
+ CreateNewDocument();
}
void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
{
- wxDocument *doc = GetCurrentDocument();
- event.Enable( doc && doc->IsModified() );
+ wxDocument * const doc = GetCurrentDocument();
+ event.Enable( doc && !doc->AlreadySaved() );
}
void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event)
{
RemoveFileFromHistory(--numFiles);
}
- else // add a new menu item to all file menus (will be updated below)
+
+ // add a new menu item to all file menus (they will be updated below)
+ for ( wxList::compatibility_iterator node = m_fileMenus.GetFirst();
+ node;
+ node = node->GetNext() )
{
- for ( wxList::compatibility_iterator node = m_fileMenus.GetFirst();
- node;
- node = node->GetNext() )
- {
- wxMenu * const menu = (wxMenu *)node->GetData();
+ wxMenu * const menu = (wxMenu *)node->GetData();
- if ( !numFiles && menu->GetMenuItemCount() )
- menu->AppendSeparator();
+ if ( !numFiles && menu->GetMenuItemCount() )
+ menu->AppendSeparator();
- // label doesn't matter, it will be set below anyhow, but it can't
- // be empty (this is supposed to indicate a stock item)
- menu->Append(m_idBase + numFiles, " ");
- }
+ // label doesn't matter, it will be set below anyhow, but it can't
+ // be empty (this is supposed to indicate a stock item)
+ menu->Append(m_idBase + numFiles, " ");
}
-
// insert the new file in the beginning of the file history
m_fileHistory.insert(m_fileHistory.begin(), file);
numFiles++;