X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd4618549b4cb22d84930b45853dc09f489e732c..ca1f7cb56322e35a5bf3d9612cd14c128246947c:/src/common/docview.cpp?ds=sidebyside diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 9e5e65a015..635a2529bb 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -418,7 +418,22 @@ wxOutputStream& wxDocument::SaveObject(wxOutputStream& stream) bool wxDocument::Revert() { - return false; + if ( wxMessageBox + ( + _("Discard changes and reload the last saved version?"), + wxTheApp->GetAppDisplayName(), + wxYES_NO | wxCANCEL | wxICON_QUESTION, + GetDocumentWindow() + ) != wxYES ) + return false; + + if ( !DoOpenDocument(GetFilename()) ) + return false; + + Modify(false); + UpdateAllViews(); + + return true; } @@ -651,7 +666,8 @@ wxView::wxView() wxView::~wxView() { - GetDocumentManager()->ActivateView(this, false); + if (m_viewDocument && GetDocumentManager()) + GetDocumentManager()->ActivateView(this, false); // reset our frame view first, before removing it from the document as // SetView(NULL) is a simple call while RemoveView() may result in user @@ -887,7 +903,7 @@ BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen) EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateDisableIfNoDoc) EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateDisableIfNoDoc) - EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateDisableIfNoDoc) + EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert) EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew) EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave) EVT_UPDATE_UI(wxID_SAVEAS, wxDocManager::OnUpdateDisableIfNoDoc) @@ -1098,6 +1114,15 @@ void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) #endif // wxUSE_PRINTING_ARCHITECTURE } +#if wxUSE_PRINTING_ARCHITECTURE +wxPreviewFrame* wxDocManager::CreatePreviewFrame(wxPrintPreviewBase* preview, + wxWindow *parent, + const wxString& title) +{ + return new wxPreviewFrame(preview, parent, title); +} +#endif // wxUSE_PRINTING_ARCHITECTURE + void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) { #if wxUSE_PRINTING_ARCHITECTURE @@ -1119,9 +1144,11 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) return; } - wxPreviewFrame * - frame = new wxPreviewFrame(preview, wxTheApp->GetTopWindow(), - _("Print Preview")); + wxPreviewFrame* frame = CreatePreviewFrame(preview, + wxTheApp->GetTopWindow(), + _("Print Preview")); + wxCHECK_RET( frame, "should create a print preview frame" ); + frame->Centre(wxBOTH); frame->Initialize(); frame->Show(true); @@ -1167,6 +1194,12 @@ void wxDocManager::OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event) event.Enable( GetCurrentDocument() != NULL ); } +void wxDocManager::OnUpdateFileRevert(wxUpdateUIEvent& event) +{ + wxDocument* doc = GetCurrentDocument(); + event.Enable(doc && doc->IsModified() && doc->GetDocumentSaved()); +} + void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event) { // CreateDocument() (which is called from OnFileNew) may succeed @@ -1592,7 +1625,8 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, GetLastDirectory(), wxEmptyString, &FilterIndex, - descrBuf); + descrBuf, + wxFD_OPEN | wxFD_FILE_MUST_EXIST); wxDocTemplate *theTemplate = NULL; if (!pathTmp.empty()) @@ -1843,7 +1877,9 @@ bool wxDocChildFrameAnyBase::CloseView(wxCloseEvent& event) { if ( m_childView ) { - if ( event.CanVeto() && !m_childView->Close(false) ) + // notice that we must call wxView::Close() and OnClose() called from + // it in any case, even if we know that we are going to close anyhow + if ( !m_childView->Close(false) && event.CanVeto() ) { event.Veto(); return false;