]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/docview.cpp
Add information about the log message generation location to wxLog.
[wxWidgets.git] / src / common / docview.cpp
index c00db551ce9522807bfa2c88076ab3306f5c5c4d..51c55bcaf3f2ed8a999213b811bdd914d64bc550 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()
                           );
 
     }