Version 0 of Adding 'history' to BWidget ComboBox widgets.

Updated 2005-06-10 21:10:30

WJG 10th June, 2005. Why doesn't the BWidget ComboBox does have a 'built-in' means of updating the selection list from data validated in its entry box. Perhaps, it has and I haven't looked hard enough. Anyway, it was quicker to just cook something up. So here's my offering.

# ------------------------------------------------------------- # ComboBox_history.tcl # Written by William J Giddings, 2005 # ------------------------------------------------------------- # # Purpose: # -------- # To provide history for the BWidget ComboBox. # # Note: # ----- # * This is not achieved by manipulating the BWidet code but by # simply providing a suitable proceedure to be called when the # entry subwidget is validated. # * New vallidated entries are placed at the top of the list. # * Duplicate entries will not be added. # # Use: # --------------- # ComboBox .cmb -values {A B C} -command _h # # -------------------------------------------------------------

# ------------------------------------------------------------- # a simple handler, no args required # -------------------------------------------------------------

proc _h {} {

    set w [winfo parent [focus]] 
    set a [$w get]
    set b [$w cget -values]
    #check to see if value already there..
    if { [lsearch -exact $b $a] } { $w configure -values "$a $b"} 

}

# ------------------------------------------------------------- # the uniquitous demo! # ------------------------------------------------------------- proc demo {} {

    package require BWidget
    pack [ComboBox .cmb -values {A B C} -command _h]

}

demo