X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ada1ff0dbcd973c0a4630318599eb469dd6e3fb6..af58844636f51ca9c9350c66de3baf427d3e8646:/src/common/docview.cpp?ds=inline diff --git a/src/common/docview.cpp b/src/common/docview.cpp index c00db551ce..51c55bcaf3 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -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(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() ); }