]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / common / docview.cpp
index e4f6bf3bdb2b5f097298e56a8f30be8f83f9ef68..8ed6b129aaf1deb94fd699058af14ef691ef78c4 100644 (file)
@@ -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)