]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
another fix for wxUSE_DRAG_AND_DROP==0 build
[wxWidgets.git] / src / common / docview.cpp
index b9eac572333fd83a0d4bcc23ab264b13f63db156..459ce5585ccc8fe77119f9203ce74cdc7b51c20c 100644 (file)
@@ -56,6 +56,7 @@
 #include "wx/cmdproc.h"
 #include "wx/tokenzr.h"
 #include "wx/filename.h"
+#include "wx/stdpaths.h"
 #include "wx/vector.h"
 #include "wx/ptr_scpd.h"
 
@@ -307,8 +308,12 @@ bool wxDocument::SaveAs()
     wxString filter = docTemplate->GetFileFilter() ;
 #endif
     wxString defaultDir = docTemplate->GetDirectory();
-    if (defaultDir.IsEmpty())
+    if ( defaultDir.empty() )
+    {
         defaultDir = wxPathOnly(GetFilename());
+        if ( defaultDir.empty() )
+            defaultDir = GetDocumentManager()->GetLastDirectory();
+    }
 
     wxString fileName = wxFileSelector(_("Save As"),
             defaultDir,
@@ -471,7 +476,7 @@ bool wxDocument::OnSaveModified()
                  (
                     wxString::Format
                     (
-                     _("Do you want to save changes to document %s?"),
+                     _("Do you want to save changes to %s?"),
                      GetUserReadableName()
                     ),
                     wxTheApp->GetAppDisplayName(),
@@ -938,6 +943,19 @@ bool wxDocManager::Initialize()
     return true;
 }
 
+wxString wxDocManager::GetLastDirectory() const
+{
+    // use the system-dependent default location for the document files if
+    // we're being opened for the first time
+    if ( m_lastDirectory.empty() )
+    {
+        wxDocManager * const self = const_cast<wxDocManager *>(this);
+        self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
+    }
+
+    return m_lastDirectory;
+}
+
 wxFileHistory *wxDocManager::OnCreateFileHistory()
 {
     return new wxFileHistory;
@@ -1070,7 +1088,9 @@ void wxDocManager::OnRedo(wxCommandEvent& event)
 
 void wxDocManager::OnUpdateFileOpen(wxUpdateUIEvent& event)
 {
-    event.Enable( true );
+    // CreateDocument() (which is called from OnFileOpen) may succeed
+    // only when there is at least a template:
+    event.Enable( GetTemplates().GetCount()>0 );
 }
 
 void wxDocManager::OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event)
@@ -1080,7 +1100,9 @@ void wxDocManager::OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event)
 
 void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event)
 {
-    event.Enable( true );
+    // CreateDocument() (which is called from OnFileNew) may succeed
+    // only when there is at least a template:
+    event.Enable( GetTemplates().GetCount()>0 );
 }
 
 void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
@@ -1486,7 +1508,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
     wxWindow* parent = wxFindSuitableParent();
 
     wxString pathTmp = wxFileSelectorEx(_("Open File"),
-                                        m_lastDirectory,
+                                        GetLastDirectory(),
                                         wxEmptyString,
                                         &FilterIndex,
                                         descrBuf,
@@ -1510,7 +1532,8 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
             path = wxEmptyString;
             return NULL;
         }
-        m_lastDirectory = wxPathOnly(pathTmp);
+
+        SetLastDirectory(wxPathOnly(pathTmp));
 
         path = pathTmp;