diff --git a/twander.py b/twander.py index 3863aaf..8424cf1 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.52 2003/01/11 22:52:02 tundra Exp $" +RCSID = "$Id: twander.py,v 2.53 2003/01/11 23:24:15 tundra Exp $" VERSION = RCSID.split()[2] @@ -61,6 +61,7 @@ # General Program Commands +CLRHIST = '' # Clear Command History MOUSECTX = '' # Pop-up Context Menu MOUSEDIR = '' # Pop-up Directory Menu KEYPRESS = '' # Any keypress (for commands) @@ -478,7 +479,8 @@ # These may be overriden in the configuration file # parsing process. - UI.KeyBindings = {"MOUSECTX":MOUSECTX, + UI.KeyBindings = {"CLRHIST":CLRHIST, + "MOUSECTX":MOUSECTX, "MOUSEDIR":MOUSEDIR, "KEYPRESS":KEYPRESS, "QUITPROG":QUITPROG, @@ -960,6 +962,9 @@ # General Program Commands ### + # Bind handler to invoke Clear Command History + self.DirList.bind(self.KeyBindings["CLRHIST"], ClearHistory) + # Bind handler to invoke Context Menu self.DirList.bind(self.KeyBindings["MOUSECTX"], MouseClick) @@ -1294,20 +1299,20 @@ #--------------- General Program Commands -----------------# - ##### -# Event Handler: Popup Menus +# Event Handler: Clear Command History ##### -def PopupMenu(menu, x, y): - - # Popup requested menu at specified coordinates - # but only if the menu has at least one entry. - - if menu.index(END): - menu.tk_popup(x, y) - -# End of 'PopupMenu()' +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) + +# End of 'ClearHistory()' ##### @@ -1717,7 +1722,7 @@ # Event Handler: Run Command #### -def KeyRunCommand(event, initial=""): +def KeyRunCommand(event, initial="", save=TRUE): global UI # Prompt with passed initial edit string @@ -1732,9 +1737,12 @@ else: cmd = askstring(pRUNCMD, pENCMD) - # Save command (if any) as last manually entered and execute it - if cmd: + # Save command (if any) if we're supposed to + if save and cmd: UI.LastCmd = cmd + + # Execute command (if any) + if cmd: ExecuteCommand(cmd) UI.DirList.focus() @@ -1844,6 +1852,21 @@ #-------------- Handler Utility Functions -----------------# ##### +# Event Handler: Popup Menus +##### + +def PopupMenu(menu, x, y): + + # Popup requested menu at specified coordinates + # but only if the menu has at least one entry. + + if menu.index(END): + menu.tk_popup(x, y) + +# End of 'PopupMenu()' + + +##### # Execute A Command ##### @@ -1876,8 +1899,12 @@ UI.HistBtn.menu.delete(0,END) for entry in UI.CmdHist: - UI.HistBtn.menu.add_command(label=entry, command=lambda cmd=entry: KeyRunCommand(None, initial=cmd)) + UI.HistBtn.menu.add_command(label=entry, command=lambda cmd=entry: KeyRunCommand(None, initial=cmd, save=FALSE)) UI.HistBtn['menu'] = UI.HistBtn.menu + + # Enable the History Menu button if there is now content there + if UI.HistBtn.menu.size(): + UI.HistBtn.config(state=NORMAL) # Dump Command History stack if requested @@ -2393,11 +2420,8 @@ # Initialize list of all directories visited UI.AllDirs = [] -# Initialize command history -UI.CmdHist = [] - -# Initialize last command buffer -UI.LastCmd = "" +# Initialize Command History data structures +ClearHistory(None) # Parse the and store configuration file, if any ParseConfFile(None)