lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: [lmi] wxmsw-2.9 regression: default directory for File | Open


From: Vadim Zeitlin
Subject: Re[2]: [lmi] wxmsw-2.9 regression: default directory for File | Open
Date: Wed, 17 Jun 2009 13:46:31 +0200

On Tue, 16 Jun 2009 18:52:14 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2009-05-15 02:38Z, Greg Chicares wrote:
GC> > On 2009-04-01 13:31Z, Greg Chicares wrote:
GC> >> On 2009-03-27 23:30Z, Vadim Zeitlin wrote:
GC> >>> On Tue, 24 Mar 2009 14:17:20 +0000 Greg Chicares <address@hidden> wrote:
GC> >>> 
GC> >>> GC> To reproduce:
GC> >>> GC>   load lmi on msw [FWIW, I'm using msw 'xp']
GC> >>> GC>   File | Open
GC> >>> GC> Examine the "Look in:" directory shown at the top of the dialog.
GC> >>> GC> 
GC> >>> GC> With wx-2.8.10 and prior versions, this apparently is set to the
GC> >> 
GC> >> [...it was set to some directory that msw regarded as appropriate;
GC> >> but wx trunk uses "My Documents" instead...]
GC> > [...]
GC> >>>  Second solution would be to make wx a bit smarter with its auto
GC> >>> determination of the last directory and use the most recent file in
GC> >>> wxFileHistory and only fall back to "My Documents" if the history is 
empty.
GC> >>> This seems a bit more fragile but still should typically work very 
well. So
GC> >>> if you don't see any objections to it, I'll implement this behaviour in 
wx
GC> >>> itself.
GC> >> 
GC> >> Yes, I think that's a really good idea.
GC> > 
GC> > Did this change make it into wx svn trunk? With release candidate three,
GC> > I still see the "My Documents" behavior.
GC> 
GC> BTW, I still see the same issue with wx-2.9.0 release candidate four.

 Sorry about this, I simply never did this so far... The following patch
seems to work for me:

Index: src/common/docview.cpp
===================================================================
--- src/common/docview.cpp      (revision 61069)
+++ src/common/docview.cpp      (working copy)
@@ -980,12 +980,34 @@

 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;

and I've committed it to both svn trunk and 2.9 branch so it will appear in
the final 2.9.0 release.

 Sorry again for the delay,
VZ

reply via email to

[Prev in Thread] Current Thread [Next in Thread]