From: Mark A J. <maj...@ra...> - 2004-05-05 04:55:15
|
All, I have created a "DYNAMIC" (command history) combobox. However, the behavior of the UP ARROW is not what I want. I created a combobox which contains a history of commands entered by the user. It starts out as an empty list. As the user enters commands in the combobox, the NEW command is added to the bottom of the combobox command list. The combobox contains a UNIQUE list of commands (i.e., a command ONLY appears in the combobox once) if the user enters a command (or selects a command) that is already in the combobox, that command is moved to the bottom of the list. The UP ARROW can be used by the user to reselect a command already in the combobox or to modify a previously entered command. The behavior I see is as follows: In the combobox entry widget enter the following ... 1<cr> 2<cr> 3<cr> 4<cr> 5<cr> UP ARROW (5 appears in the combobox entry widget) UP ARROW (4 appears in the combobox entry widget) UP ARROW (3 appears in the combobox entry widget) 333<cr> the result is a command list in the combobox of ... 1 2 3 4 5 333 UP ARROW (2 appears in the combobox entry widget, I WANT 333 to appear since that was the last command entered) The behavior I want is for "333" to appear first in the combobox when the UP ARROW is selected in the sequence above since "333" was the last command entered (successive UP ARROWS should result in 5, 4, 3, 2, 1 appearing in the combobox after the 333 appears). Once a command is entered in the combobox entry widget, I want the UP ARROW to bring up the LAST COMMAND entered and then move UP the command history in the combobox. The behavior I see is that the combobox widget "remembers" the position of where it was in the STACK of commands from the previous UP ARROW selection, which results in the next UP ARROW key displaying the previous command in the combobox entry from the LAST REMEMBERED place in the stack, rather than from the last command entered. I expected the command .... "pathname" selection anchor end ... which is in my code, would result in the last command being displayed in the combobox entry the first time the UP ARROW is selected following the <cr> or the <enter> key. Is there a way to obtain the results I am trying to obtain by using the combobox widget or is ther some other widget that I should be using ... like possibly the tixCombobox??? Any help would be greatly appreciated. TIA, Mark ============================================= [BEGIN code snippet] # include the Iwidgets package for use of the combobox function package require Iwidgets; ################################################################################ ## ## Function Name: close_dcb_combobox ## ## Inputs: none ## ## Outputs: none ## ## Description: Exits program ## ## ################################################################################ proc close_dcb_combobox {} { exit; }; ################################################################################ ## ## Function Name: execute_combobox_Cmnd ## ## Inputs: commandString ## ## Outputs: none ## ## Description: ## ## ################################################################################ proc execute_combobox_Cmnd {commandString} { global current_command_list set s1 ""; #string 1 set s2 ""; #string 2 set s3 ""; #string 3 set matchFound 0; set len_current_command_list [ llength $current_command_list ]; # # MAKE THE 'commandString' INTO CAPITAL LETTERS # set commandString [ string toupper [ string trim $commandString ] ]; if { ![ llength $commandString ] > 0 } { # nothing was entered into the combobox before the RETURN or ENTER key was selected return; }; # print the command entered by the user in the output text widget .dcb.output.text insert end "Command entered was ... $commandString\n"; # check to see if the command is already on the list # if the command is NOT on the list ... put it at the bottom of the list # if the command IS on the list ... move the command that is on the list # to the bottom of the list so that the last command is ALWAYS at the # bottom of the list and each command appears on the list ONLY ONCE!!! if { $len_current_command_list > 0 } { set i 0; while { ( $i < $len_current_command_list ) && $matchFound == 0 } { if { ( [ string compare $commandString \ [ lindex [ lrange $current_command_list $i $i ] 0 ] ] == 0 ) } { set matchFound 1; set s1 [ lrange $current_command_list 0 [ expr $i -1 ] ]; set s2 [ lrange $current_command_list [ expr $i +1 ] [ expr $len_current_command_list -1 ] ]; set s3 [ list $commandString ]; set current_command_list [concat $s1 $s2 $s3 ]; }; #endof if '{ ( [ string compare $commandString ... ] ) }' incr i; }; #endof while }; #endof if '{ $len_current_command_list > 0 }' if { !$matchFound } { .dcb.input.curCommand insert list end $commandString; set current_command_list [ concat $current_command_list [ list $commandString ] ]; } else { .dcb.input.curCommand clear list; for { set knt 0 } { $knt < $len_current_command_list } { incr knt } { .dcb.input.curCommand insert list end [ lindex $current_command_list $knt]; }; #endof for }; #endof if '{ !$matchFound }' # set the selection to the end of the list .dcb.input.curCommand selection anchor end ; # clear the entry window for the next command .dcb.input.curCommand clear entry; # clear command string set commandString ""; }; ################################################################################ ## ## main code starts here ## ################################################################################ wm title . "Sample Combobox"; wm iconname . "Combobox"; wm protocol . WM_DELETE_WINDOW close_dcb_combobox; wm resizable . 0 0; ################################################################################# # define the frames ################################################################################# frame .dcb; frame .dcb.input -bg white; frame .dcb.output; ################################################################################# # end of frame definitions ################################################################################# # <----- define the widgets ----> # define the combobox widget iwidgets::combobox .dcb.input.curCommand \ -labeltext "Command:" \ -width 30 \ -unique true \ -completion false \ -listheight 5i \ -textvariable currentCommand; set CmndEntryField [.dcb.input.curCommand component entry]; bind $CmndEntryField <Return> { execute_combobox_Cmnd "$currentCommand" }; # define the output label widget label .dcb.output.output_label \ -text "Output:" \ -anchor w \ -justify left; # define the output text area widget text .dcb.output.text \ -width 60 \ -height 25 \ -relief groove \ -bd 2 \ -wrap word \ -yscrollcommand ".dcb.output.scroll set"; # define the scrollbar widget scrollbar .dcb.output.scroll -relief raised \ -command ".dcb.output.text yview"; ################################################################################# # pack everything ################################################################################# pack .dcb.input.curCommand \ -fill x; pack .dcb.output.output_label \ -anchor w \ -pady 2; pack .dcb.output.text \ .dcb.output.scroll \ -side left \ -fill y; pack .dcb.input \ .dcb.output \ -side top \ -fill x ; pack .dcb; ################################################################################# # Initializations ################################################################################# set current_command_list ""; [END code snippet] |