]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Implement support for gradient stops for OS X.
[wxWidgets.git] / src / common / docview.cpp
index 9e5e65a0154bd287ceb5aa0abe4849db984ee517..635a2529bb8f31d9a5adcd3273df6ae7a0226bbe 100644 (file)
@@ -418,7 +418,22 @@ wxOutputStream& wxDocument::SaveObject(wxOutputStream& stream)
 
 bool wxDocument::Revert()
 {
 
 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()
 {
 
 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
 
     // 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_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)
     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
 }
 
 #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
 void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
 {
 #if wxUSE_PRINTING_ARCHITECTURE
@@ -1119,9 +1144,11 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
             return;
         }
 
             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);
         frame->Centre(wxBOTH);
         frame->Initialize();
         frame->Show(true);
@@ -1167,6 +1194,12 @@ void wxDocManager::OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event)
     event.Enable( GetCurrentDocument() != NULL );
 }
 
     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
 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,
                                         GetLastDirectory(),
                                         wxEmptyString,
                                         &FilterIndex,
-                                        descrBuf);
+                                        descrBuf,
+                                        wxFD_OPEN | wxFD_FILE_MUST_EXIST);
 
     wxDocTemplate *theTemplate = NULL;
     if (!pathTmp.empty())
 
     wxDocTemplate *theTemplate = NULL;
     if (!pathTmp.empty())
@@ -1843,7 +1877,9 @@ bool wxDocChildFrameAnyBase::CloseView(wxCloseEvent& event)
 {
     if ( m_childView )
     {
 {
     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;
         {
             event.Veto();
             return false;