X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c77049a04b5918a6b432aab94eaf31bc73c28916..60913641356f364a5efee5966d3a3b0b48c01001:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index b493ec91bd..dbc0e56630 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -246,8 +246,6 @@ bool wxDocument::OnNewDocument() if ( !OnSaveModified() ) return false; - if ( !OnCloseDocument() ) - return false; DeleteContents(); Modify(false); SetDocumentSaved(false); @@ -261,7 +259,7 @@ bool wxDocument::OnNewDocument() bool wxDocument::Save() { - if (!IsModified() && m_savedYet) + if ( AlreadySaved() ) return true; if ( m_documentFile.empty() || !m_savedYet ) @@ -582,30 +580,21 @@ 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()) + 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; } @@ -616,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 ) #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; } @@ -654,13 +648,10 @@ wxView::~wxView() 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)) @@ -981,7 +972,7 @@ void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event)) void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event)) { - CreateDocument( wxEmptyString, wxDOC_NEW ); + CreateNewDocument(); } void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event)) @@ -1103,8 +1094,8 @@ void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& 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) @@ -1147,14 +1138,10 @@ wxView *wxDocManager::GetCurrentView() const 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 @@ -1784,22 +1771,15 @@ wxDocChildFrame::wxDocChildFrame(wxDocument *doc, 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) @@ -1914,13 +1894,9 @@ void wxDocParentFrame::OnMRUFile(wxCommandEvent& 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 @@ -2037,24 +2013,22 @@ void wxFileHistory::AddFileToHistory(const wxString& file) { 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++;