diff --git a/twander.py b/twander.py index d594ed3..4baaace 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.229 2009/06/29 21:41:23 tundra Exp $" +RCSID = "$Id: twander.py,v 3.230 2009/07/01 00:44:39 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -5073,11 +5073,17 @@ UI.FilterWildcard = ("None", None, None, False) INVERTFILTER = False + # Keep track of current selection and active line *by name*. This + # will ensure correct reselection after a refresh where the + # contents of the directory have changed. Since this uses simple + # string matching, the algorithm below has to be sensitive to + # expanded symbolic links so that the match is made on the symlink + # name, not it's expansion (which can change by toggling one of + # the SYM* options). - # Get current selection and active - - sellist = UI.DirList.curselection() - active = UI.DirList.index(ACTIVE) + selections = [] + for sel in list(UI.DirList.curselection()) + [str(UI.DirList.index(ACTIVE))]: + selections.append(StripPSEP(UI.DirList.get(sel).split(SYMPTR)[0].split()[-1])) # Save current scroll positions @@ -5085,14 +5091,42 @@ ys = UI.vSB.get() # Clean out old listbox contents + UI.DirList.delete(0,END) - # Save the new directory information + # Get and load the new directory information, restoring selections + # and active marker try: - UI.DirList.insert(0, *BuildDirList(UI.CurrentDir)) + dirlist = BuildDirList(UI.CurrentDir) + UI.DirList.insert(0, *dirlist) + + # Build list of all file and directory names + + names = [] + for entry in dirlist: + names.append(StripPSEP(entry.split(SYMPTR)[0].split()[-1])) + + # Get the active entry off the list and convert to an integer index + + active = selections.pop() + try: + active = names.index(active) + except: + active = 0 + + # Build a list of strings describing selections, discarding + # references to files/directories that no longer exist + + sellist = [] + for name in selections: + try: + sellist.append(str(names.index(name))) + except: + pass # Restore selection(s) + UI.SetSelection(sellist, active) # Restore scroll positions @@ -5101,7 +5135,7 @@ UI.DirList.yview(MOVETO, ys[0]) - # Cannot read current directory - probably media remove + # Cannot read current directory - probably media removed. # Just revert back to the original starting directory # This won't work if the original starting directory is # no longer readable - i.e. *It* was removed.