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;
}
m_viewDocument->RemoveView(this);
}
-// Extend event processing to search the document's event table
-bool wxView::ProcessEvent(wxEvent& event)
+bool wxView::TryValidator(wxEvent& event)
{
- if ( !GetDocument() || !GetDocument()->ProcessEvent(event) )
- return wxEvtHandler::ProcessEvent(event);
-
- return true;
+ wxDocument * const doc = GetDocument();
+ return doc && doc->ProcessEventHere(event);
}
void wxView::OnActivateView(bool WXUNUSED(activate), wxView *WXUNUSED(activeView), wxView *WXUNUSED(deactiveView))
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)
return NULL;
}
-// Extend event processing to search the view's event table
-bool wxDocManager::ProcessEvent(wxEvent& event)
+bool wxDocManager::TryValidator(wxEvent& event)
{
wxView * const view = GetCurrentView();
- if ( view && view->ProcessEvent(event) )
- return true;
-
- return wxEvtHandler::ProcessEvent(event);
+ return view && view->ProcessEventHere(event);
}
namespace
view->SetFrame(this);
}
-// Extend event processing to search the view's event table
-bool wxDocChildFrame::ProcessEvent(wxEvent& event)
+bool wxDocChildFrame::TryValidator(wxEvent& event)
{
- if (m_childView)
- m_childView->Activate(true);
+ if ( !m_childView )
+ return false;
- if ( !m_childView || ! m_childView->ProcessEvent(event) )
- {
- // Only hand up to the parent if it's a menu command
- if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
- return wxEvtHandler::ProcessEvent(event);
- else
- return true;
- }
- else
- return true;
+ // FIXME: why is this needed here?
+ m_childView->Activate(true);
+
+ return m_childView->ProcessEventHere(event);
}
void wxDocChildFrame::OnActivate(wxActivateEvent& event)
}
// Extend event processing to search the view's event table
-bool wxDocParentFrame::ProcessEvent(wxEvent& event)
+bool wxDocParentFrame::TryValidator(wxEvent& event)
{
- // Try the document manager, then do default processing
- if (!m_docManager || !m_docManager->ProcessEvent(event))
- return wxEvtHandler::ProcessEvent(event);
- else
- return true;
+ return m_docManager && m_docManager->ProcessEventHere(event);
}
// Define the behaviour for the frame closing
{
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++;