]> 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 c00db551ce9522807bfa2c88076ab3306f5c5c4d..5dae19b52bb071f1ee1d6f45c5d8f8d6e78d3863 100644 (file)
@@ -105,13 +105,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
 namespace
 {
 
-wxWindow *wxFindSuitableParent()
-{
-    wxWindow * const win = wxGetTopLevelParent(wxWindow::FindFocus());
-
-    return win ? win : wxTheApp->GetTopWindow();
-}
-
 wxString FindExtension(const wxString& path)
 {
     wxString ext;
@@ -489,8 +482,7 @@ bool wxDocument::OnSaveModified()
                      GetUserReadableName()
                     ),
                     wxTheApp->GetAppDisplayName(),
-                    wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTRE,
-                    wxFindSuitableParent()
+                    wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTRE
                  ) )
         {
             case wxNO:
@@ -988,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;
@@ -1566,15 +1580,11 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
 
     int FilterIndex = -1;
 
-    wxWindow* parent = wxFindSuitableParent();
-
     wxString pathTmp = wxFileSelectorEx(_("Open File"),
                                         GetLastDirectory(),
                                         wxEmptyString,
                                         &FilterIndex,
-                                        descrBuf,
-                                        0,
-                                        parent);
+                                        descrBuf);
 
     wxDocTemplate *theTemplate = NULL;
     if (!pathTmp.empty())
@@ -1589,8 +1599,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
 
             wxMessageBox(_("Sorry, could not open this file."),
                          msgTitle,
-                         wxOK | wxICON_EXCLAMATION | wxCENTRE,
-                         parent);
+                         wxOK | wxICON_EXCLAMATION | wxCENTRE);
 
             path = wxEmptyString;
             return NULL;
@@ -1613,8 +1622,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
             // allowed templates in runtime.
             wxMessageBox(_("Sorry, the format for this file is unknown."),
                          _("Open File"),
-                         wxOK | wxICON_EXCLAMATION | wxCENTRE,
-                         parent);
+                         wxOK | wxICON_EXCLAMATION | wxCENTRE);
         }
     }
     else
@@ -1696,8 +1704,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
                             _("Select a document template"),
                             _("Templates"),
                             strings,
-                            (void **)data.get(),
-                            wxFindSuitableParent()
+                            (void **)data.get()
                           );
     }
 
@@ -1771,8 +1778,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
                             _("Select a document view"),
                             _("Views"),
                             strings,
-                            (void **)data.get(),
-                            wxFindSuitableParent()
+                            (void **)data.get()
                           );
 
     }
@@ -2229,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;
 
@@ -2253,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;
 
@@ -2276,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;
 
@@ -2300,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;