]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Fix numpad Del not working in wxRTC
[wxWidgets.git] / src / common / docview.cpp
index 11d6bca96d17631d078784eb03f53a22d11893c3..5dae19b52bb071f1ee1d6f45c5d8f8d6e78d3863 100644 (file)
@@ -980,12 +980,34 @@ bool wxDocManager::Initialize()
 
 wxString wxDocManager::GetLastDirectory() const
 {
-    // use the system-dependent default location for the document files if
-    // we're being opened for the first time
+    // if we haven't determined the last used directory yet, do it now
     if ( m_lastDirectory.empty() )
     {
+        // we're going to modify m_lastDirectory in this const method, so do it
+        // via non-const self pointer instead of const this one
         wxDocManager * const self = const_cast<wxDocManager *>(this);
-        self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
+
+        // first try to reuse the directory of the most recently opened file:
+        // this ensures that if the user opens a file, closes the program and
+        // runs it again the "Open file" dialog will open in the directory of
+        // the last file he used
+        wxString lastOpened = GetHistoryFile(0);
+        if ( !lastOpened.empty() )
+        {
+            const wxFileName fn(lastOpened);
+            if ( fn.DirExists() )
+            {
+                self->m_lastDirectory = fn.GetPath();
+            }
+            //else: should we try the next one?
+        }
+
+        // if we don't have any files in the history (yet?), use the
+        // system-dependent default location for the document files
+        if ( m_lastDirectory.empty() )
+        {
+            self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
+        }
     }
 
     return m_lastDirectory;
@@ -2213,7 +2235,11 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu)
 
 bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
 {
-    wxFFile file(filename, _T("rb"));
+#if wxUSE_FFILE
+    wxFFile file(filename, wxT("rb"));
+#elif wxUSE_FILE
+    wxFile file(filename, wxFile::read);
+#endif
     if ( !file.IsOpened() )
         return false;
 
@@ -2237,7 +2263,11 @@ bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
 
 bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
 {
-    wxFFile file(filename, _T("wb"));
+#if wxUSE_FFILE
+    wxFFile file(filename, wxT("wb"));
+#elif wxUSE_FILE
+    wxFile file(filename, wxFile::write);
+#endif
     if ( !file.IsOpened() )
         return false;
 
@@ -2260,7 +2290,11 @@ bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
 
 bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
 {
-    wxFFile file(filename, _T("rb"));
+#if wxUSE_FFILE
+    wxFFile file(filename, wxT("rb"));
+#elif wxUSE_FILE
+    wxFile file(filename, wxFile::read);
+#endif
     if ( !file.IsOpened() )
         return false;
 
@@ -2284,7 +2318,11 @@ bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
 
 bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
 {
-    wxFFile file(filename, _T("wb"));
+#if wxUSE_FFILE
+    wxFFile file(filename, wxT("wb"));
+#elif wxUSE_FILE
+    wxFile file(filename, wxFile::write);
+#endif
     if ( !file.IsOpened() )
         return false;