From 28c1fb72444d5125f3142d04d3fe1dc8f7897039 Mon Sep 17 00:00:00 2001 From: toshinagata1964 Date: Tue, 30 Oct 2012 00:37:39 +0000 Subject: [PATCH] Revert command is implemented. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@315 a2be9bc6-48de-4e38-9406-05402d4bc13c --- wxSources/MyApp.cpp | 1 + wxSources/MyDocManager.cpp | 1 + wxSources/docview.cpp | 22 +++++++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/wxSources/MyApp.cpp b/wxSources/MyApp.cpp index 5d8a297..0324a44 100755 --- a/wxSources/MyApp.cpp +++ b/wxSources/MyApp.cpp @@ -362,6 +362,7 @@ MyApp::CreateMenuBar(int kind, wxMenu **out_file_history_menu, wxMenu **out_edit file_menu->Append(wxID_CLOSE, _T("&Close\tCtrl-W")); file_menu->Append(wxID_SAVE, _T("&Save\tCtrl-S")); file_menu->Append(wxID_SAVEAS, _T("Save &As...")); + file_menu->Append(wxID_REVERT, _T("Revert...")); file_menu->AppendSeparator(); file_menu->Append(myMenuID_Import, _T("Import...")); diff --git a/wxSources/MyDocManager.cpp b/wxSources/MyDocManager.cpp index ebf9ca5..a76e669 100644 --- a/wxSources/MyDocManager.cpp +++ b/wxSources/MyDocManager.cpp @@ -25,6 +25,7 @@ BEGIN_EVENT_TABLE(MyDocManager, wxDocManager) EVT_MENU(wxID_OPEN, MyDocManager::OnFileOpen) EVT_MENU(wxID_SAVE, MyDocManager::OnFileSave) EVT_MENU(wxID_SAVEAS, MyDocManager::OnFileSaveAs) +EVT_MENU(wxID_REVERT, MyDocManager::OnFileRevert) END_EVENT_TABLE() static const char *sReadOnlyTypes[] = { diff --git a/wxSources/docview.cpp b/wxSources/docview.cpp index e382b26..909de4b 100644 --- a/wxSources/docview.cpp +++ b/wxSources/docview.cpp @@ -410,12 +410,27 @@ wxOutputStream& wxDocument::SaveObject(wxOutputStream& stream) return stream; } +/* Taken from wxWidgets 2.9.3 and changed GetAppDisplayName() to GetAppName() */ bool wxDocument::Revert() { - return false; + if ( wxMessageBox + ( + _("Discard changes and reload the last saved version?"), + wxTheApp->GetAppName(), + wxYES_NO | wxCANCEL | wxICON_QUESTION, + GetDocumentWindow() + ) != wxYES ) + return false; + + if ( !DoOpenDocument(GetFilename()) ) + return false; + + Modify(false); + UpdateAllViews(); + + return true; } - // Get title, or filename if no title, else unnamed bool wxDocument::GetPrintableName(wxString& buf) const { @@ -1092,10 +1107,11 @@ void wxDocManager::OnUpdateFileClose(wxUpdateUIEvent& event) event.Enable( (doc != (wxDocument*) NULL) ); } +/* Taken from wxWidgets 2.9.3 */ void wxDocManager::OnUpdateFileRevert(wxUpdateUIEvent& event) { wxDocument *doc = GetCurrentDocument(); - event.Enable( (doc != (wxDocument*) NULL) ); + event.Enable( (doc != (wxDocument*) NULL) && doc->IsModified() && doc->GetDocumentSaved() ); } void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event) -- 2.11.0