X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d38eb01c91f5d84236a881c71c78ae0e3b06fb17..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index e4f6bf3bdb..8ed6b129aa 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -60,6 +60,7 @@ #include "wx/vector.h" #include "wx/scopedarray.h" #include "wx/scopedptr.h" +#include "wx/scopeguard.h" #include "wx/except.h" #if wxUSE_STD_IOSTREAM @@ -397,6 +398,9 @@ bool wxDocument::OnSaveDocument(const wxString& file) if ( !DoSaveDocument(file) ) return false; + if ( m_commandProcessor ) + m_commandProcessor->MarkAsSaved(); + Modify(false); SetFilename(file); SetDocumentSaved(true); @@ -856,17 +860,19 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) bool wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags) { + wxScopeGuard g = wxMakeObjGuard(*doc, &wxDocument::DeleteAllViews); + doc->SetFilename(path); doc->SetDocumentTemplate(this); GetDocumentManager()->AddDocument(doc); doc->SetCommandProcessor(doc->OnCreateCommandProcessor()); - if (doc->OnCreate(path, flags)) - return true; + if ( !doc->OnCreate(path, flags) ) + return false; - if (GetDocumentManager()->GetDocuments().Member(doc)) - doc->DeleteAllViews(); - return false; + g.Dismiss(); // no need to call DeleteAllViews() anymore + + return true; } wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags) @@ -1316,10 +1322,14 @@ void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event) wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor(); if ( !cmdproc ) { - event.Enable(false); + // If we don't have any document at all, the menu item should really be + // disabled. + if ( !GetCurrentDocument() ) + event.Enable(false); + else // But if we do have it, it might handle wxID_UNDO on its own + event.Skip(); return; } - event.Enable(cmdproc->CanUndo()); cmdproc->SetMenuStrings(); } @@ -1329,10 +1339,13 @@ void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event) wxCommandProcessor * const cmdproc = GetCurrentCommandProcessor(); if ( !cmdproc ) { - event.Enable(false); + // Use same logic as in OnUpdateUndo() above. + if ( !GetCurrentDocument() ) + event.Enable(false); + else + event.Skip(); return; } - event.Enable(cmdproc->CanRedo()); cmdproc->SetMenuStrings(); } @@ -1404,7 +1417,7 @@ void wxDocManager::ActivateDocument(wxDocument *doc) view->Activate(true); if ( wxWindow *win = view->GetFrame() ) - win->SetFocus(); + win->Raise(); } wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags)