From: Vadim Zeitlin Date: Tue, 23 Mar 2010 10:49:51 +0000 (+0000) Subject: Implement wxDocument::Revert() and show its use in the sample. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4311588bfe40e15dc83154b9653ebc432b42baeb Implement wxDocument::Revert() and show its use in the sample. wxDocument::Revert() method existed but didn't do anything, provide a default implementation for it. Also document it and show it in the sample. Closes #11849. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63748 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index c0d0cafc94..1bfa022e3d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -497,6 +497,7 @@ All (GUI): - Added wxTreeCtrl::SelectChildren() (Nikolay Tjushkov). - Show pages icons in window list menu in wxAuiNotebook (Ronny Krüger). - Add "initial selection" parameter to wxGetSingleChoice() (Nikolay Tjushkov). +- Implement wxDocument::Revert() (troelsk). GTK: diff --git a/include/wx/docview.h b/include/wx/docview.h index c9109ce65b..bf9a54d357 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -377,6 +377,7 @@ public: // Handlers for UI update commands void OnUpdateFileOpen(wxUpdateUIEvent& event); void OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event); + void OnUpdateFileRevert(wxUpdateUIEvent& event); void OnUpdateFileNew(wxUpdateUIEvent& event); void OnUpdateFileSave(wxUpdateUIEvent& event); void OnUpdateUndo(wxUpdateUIEvent& event); diff --git a/interface/wx/docview.h b/interface/wx/docview.h index b396918076..e857d57304 100644 --- a/interface/wx/docview.h +++ b/interface/wx/docview.h @@ -1332,6 +1332,14 @@ public: */ virtual bool SaveAs(); + /** + Discard changes and load last saved version. + + Prompts the user first, and then calls DoOpenDocument() to reload the + current file. + */ + virtual bool Revert(); + //@{ /** Override this function and call it from your own SaveObject() before diff --git a/samples/docview/docview.cpp b/samples/docview/docview.cpp index b865b6f425..e0ee83cbd2 100644 --- a/samples/docview/docview.cpp +++ b/samples/docview/docview.cpp @@ -247,6 +247,7 @@ void MyApp::AppendDocumentFileCommands(wxMenu *menu, bool supportsPrinting) menu->Append(wxID_CLOSE); menu->Append(wxID_SAVE); menu->Append(wxID_SAVEAS); + menu->Append(wxID_REVERT, _("Re&vert...")); if ( supportsPrinting ) { diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 102653afa1..265a6e54a6 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; } @@ -888,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) @@ -1168,6 +1183,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