X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9806a0e71eb2190827e93cd463e9682a3b939eee..81c9effa8462662263c3b4eac2cfae1ef5caae2c:/src/common/docview.cpp?ds=sidebyside diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 36ecc6a51a..1127ffe740 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -227,16 +227,13 @@ bool wxDocument::OnNewDocument() bool wxDocument::Save() { - bool ret = FALSE; + if (!IsModified() && m_savedYet) + return TRUE; - if (!IsModified() && m_savedYet) return TRUE; - if (m_documentFile == wxT("") || !m_savedYet) - ret = SaveAs(); - else - ret = OnSaveDocument(m_documentFile); - if ( ret ) - SetDocumentSaved(TRUE); - return ret; + if ( m_documentFile.empty() || !m_savedYet ) + return SaveAs(); + + return OnSaveDocument(m_documentFile); } bool wxDocument::SaveAs() @@ -316,6 +313,7 @@ bool wxDocument::OnSaveDocument(const wxString& file) } Modify(FALSE); SetFilename(file); + SetDocumentSaved(TRUE); return TRUE; } @@ -343,7 +341,8 @@ bool wxDocument::OnOpenDocument(const wxString& file) return FALSE; } #if wxUSE_STD_IOSTREAM - if (!LoadObject(store)) + LoadObject(store); + if ( !store && !store.eof() ) #else int res = LoadObject(store).LastError(); if ((res != wxSTREAM_NOERROR) && @@ -700,6 +699,7 @@ bool wxDocTemplate::FileMatchesTemplate(const wxString& path) BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen) EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose) + EVT_MENU(wxID_CLOSE_ALL, wxDocManager::OnFileCloseAll) EVT_MENU(wxID_REVERT, wxDocManager::OnFileRevert) EVT_MENU(wxID_NEW, wxDocManager::OnFileNew) EVT_MENU(wxID_SAVE, wxDocManager::OnFileSave) @@ -709,6 +709,7 @@ BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen) EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateFileClose) + EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateFileClose) EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert) EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew) EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave) @@ -749,7 +750,7 @@ wxDocManager::~wxDocManager() sm_docManager = (wxDocManager*) NULL; } -bool wxDocManager::Clear(bool force) +bool wxDocManager::CloseDocuments(bool force) { wxNode *node = m_docs.First(); while (node) @@ -773,7 +774,15 @@ bool wxDocManager::Clear(bool force) // delete another. node = next; } - node = m_templates.First(); + return TRUE; +} + +bool wxDocManager::Clear(bool force) +{ + if (!CloseDocuments(force)) + return FALSE; + + wxNode *node = m_templates.First(); while (node) { wxDocTemplate *templ = (wxDocTemplate*) node->Data(); @@ -808,6 +817,11 @@ void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event)) } } +void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event)) +{ + CloseDocuments(FALSE); +} + void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event)) { CreateDocument(wxString(""), wxDOC_NEW); @@ -947,7 +961,7 @@ void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event) void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event) { wxDocument *doc = GetCurrentDocument(); - event.Enable( (doc != (wxDocument*) NULL) ); + event.Enable( doc && doc->IsModified() ); } void wxDocManager::OnUpdateFileSaveAs(wxUpdateUIEvent& event) @@ -1045,7 +1059,10 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags) delete doc; } else + { + delete[] templates; return (wxDocument *) NULL; + } } // New document: user chooses a template, unless there's only one. @@ -1175,8 +1192,9 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc)) wxDocument *wxDocManager::GetCurrentDocument() const { - if (m_currentView) - return m_currentView->GetDocument(); + wxView *view = GetCurrentView(); + if (view) + return view->GetDocument(); else return (wxDocument *) NULL; }