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
This commit is contained in:
Vadim Zeitlin
2010-03-23 10:49:51 +00:00
parent cf30eac295
commit 4311588bfe
5 changed files with 34 additions and 2 deletions

View File

@@ -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