diff --git a/twander.py b/twander.py index cd3ecd3..aa04aef 100755 --- a/twander.py +++ b/twander.py @@ -4,7 +4,7 @@ # For Updates See: http://www.tundraware.com/Software/twander PROGNAME = "twander" -RCSID = "$Id: twander.py,v 2.54 2003/01/13 18:45:28 tundra Exp $" +RCSID = "$Id: twander.py,v 2.55 2003/01/13 21:33:27 tundra Exp $" VERSION = RCSID.split()[2] @@ -471,7 +471,7 @@ UI.CmdTable = {} UI.FuncKeys = ["", "", "", "", "", "", "", "", "", "", "", ""] - UI.OptionsNumeric = ["DEBUGLEVEL", "HEIGHT", "MAXDIR", "MAXHIST", "MAXNESTING", "REFRESHINT", "WIDTH"] + UI.OptionsNumeric = ["DEBUGLEVEL", "FSZ", "HEIGHT", "MAXDIR", "MAXHIST", "MAXNESTING", "REFRESHINT", "WIDTH"] UI.SymTable = {} linenum = 0 @@ -518,6 +518,9 @@ # Initialize the command menu UI.CmdBtn.menu.delete(0,END) + + # And disable it + UI.CmdBtn.config(state=DISABLED) # If user specified a config file, try that # Otherwise use HOME == either $HOME or ./ @@ -551,7 +554,6 @@ # and enable the menu if it has entries. # If no commands are defined, warn the user. - UI.CmdBtn.configure(state=DISABLED) if UI.CmdBtn.menu.index(END): UI.CmdBtn['menu'] = UI.CmdBtn.menu UI.CmdBtn.configure(state=NORMAL) @@ -926,13 +928,13 @@ # Setup the Directory Menu - self.DirBtn = Menubutton(self.mBar, text=DIRMENU, underline=0) + self.DirBtn = Menubutton(self.mBar, text=DIRMENU, underline=0, state=DISABLED) self.DirBtn.menu = Menu(self.DirBtn) self.DirBtn.pack(side=LEFT, padx=MENUPADX) # Setup the History Menu - self.HistBtn = Menubutton(self.mBar, text=HISTMENU, underline=0) + self.HistBtn = Menubutton(self.mBar, text=HISTMENU, underline=0, state=DISABLED) self.HistBtn.menu = Menu(self.HistBtn) self.HistBtn.pack(side=LEFT, padx=MENUPADX) @@ -993,7 +995,7 @@ ### # Bind handler for "Change Directory" - self.DirList.bind(self.KeyBindings["CHANGEDIR"], ChangeDir) + self.DirList.bind(self.KeyBindings["CHANGEDIR"], KeyChangeDir) # Bind handler for "Home Dir" self.DirList.bind(self.KeyBindings["DIRHOME"], KeyHomeDir) @@ -1302,17 +1304,22 @@ #--------------- General Program Commands -----------------# ##### -# Event Handler: Clear Command History +# Event Handler: Clear Various Program Histories ##### def ClearHistory(event): global UI - UI.CmdHist = [] - UI.LastCmd = "" - UI.HistBtn.menu.delete(0,END) - UI.HistBtn['menu'] = UI.HistBtn.menu - UI.HistBtn.config(state=DISABLED) + UI.AllDirs = [] + UI.CmdHist = [] + UI.LastCmd = "" + UI.LastDir = [] + UI.LastPathEntered = "" + + for x in [UI.HistBtn, UI.DirBtn]: + x.menu.delete(0,END) + x['menu'] = x.menu + x.config(state=DISABLED) # End of 'ClearHistory()' @@ -1464,16 +1471,17 @@ # Event Handler: Change Directory/Path #### -def ChangeDir(event): +def KeyChangeDir(event): - newpath = askstring(pCHPATH, pENPATH) + newpath = askstring(pCHPATH, pENPATH, initialvalue=UI.LastPathEntered) if newpath: + UI.LastPathEntered = newpath LoadDirList(newpath) KeySelTop(event) UI.DirList.focus() -# End of 'ChangeDir()' +# End of 'KeyChangeDir()' ##### @@ -2073,6 +2081,13 @@ else: fList.append(file) + # On Win32, adjust file-name case to make sorting meaningful + + if OSNAME == 'nt': + l = fList + for x in range(len(l)): + l[x] = l[x].lower() + # Put each in sorted order dList.sort() @@ -2313,17 +2328,61 @@ # End Of 'CommandMenuSelection()' +##### +# Add An Entry To The List Of All Directories Visited +# Do this only if it is not already on the list and +# observe the MAXDIR variable to keep list length bounded. +##### + def UpdateDirMenu(newdir): global UI - if newdir not in UI.AllDirs: + # Win32 collapses case so that 'x' and 'X' refer to the same + # directory. We want to preserve this in the user's display + # but we have to collapse case for the purposes of doing our + # checks below otherwise the same directory with different + # capitalization (if the user manually enteres it that way) + # can appear twice in the Directory Menu + + addentry = FALSE + + + if OSNAME == 'nt': + + # First make a case-collapsed copy of the existing list + + dlc = [] + for d in UI.AllDirs: + dlc.append(d.lower()) + + # Now see if our new entry is already there + + if newdir.lower() not in dlc: + addentry = TRUE + + elif newdir not in UI.AllDirs: + addentry = TRUE + + # Now add the entry if we decided it was necessary. observing MAXDIR value. + + if addentry: UI.AllDirs.append(newdir) + if len(UI.AllDirs) > MAXDIR: + UI.AllDirs = UI.AllDirs[1:] + + # If there's anything to display and we've actually changed something, update the menu + + if len(UI.AllDirs) and addentry: UI.AllDirs.sort() UI.DirBtn.menu.delete(0,END) for dir in UI.AllDirs: UI.DirBtn.menu.add_command(label=dir, command=lambda dir=dir: LoadDirList(dir)) UI.DirBtn['menu'] = UI.DirBtn.menu + # Directory Menu now has content, enable it + UI.DirBtn.config(state=NORMAL) + + # End of 'UpdateDirMenu()' @@ -2362,6 +2421,9 @@ # Initialize directory stack UI.LastDir = [] +# Initialize storage for last manually entered directory path +UI.LastPathEntered = "" + # And current location UI.CurrentDir = ""