use the directory of the most recently opened file in wxDocManager if we have any
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_9_0_BRANCH@61077 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -988,12 +988,34 @@ bool wxDocManager::Initialize()
|
|||||||
|
|
||||||
wxString wxDocManager::GetLastDirectory() const
|
wxString wxDocManager::GetLastDirectory() const
|
||||||
{
|
{
|
||||||
// use the system-dependent default location for the document files if
|
// if we haven't determined the last used directory yet, do it now
|
||||||
// we're being opened for the first time
|
|
||||||
if ( m_lastDirectory.empty() )
|
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);
|
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;
|
return m_lastDirectory;
|
||||||
|
Reference in New Issue
Block a user