6 namespace eval ::utils::history {}
9 set ::utils::history::defaultListLength 10
10 array set ::utils::history::listLength {}
11 array set ::utils::history::comboboxWidget {}
13 if {! [
info exists ::utils::history::listData]} {
14 array set ::utils::history::listData {}
21 proc ::utils::history::SetList {key list} {
22 set ::utils::history::listData($key) $list
26 proc ::utils::history::GetList {key} {
28 if {[
info exists listData($key)]} {
29 return $listData($key)
41 proc ::utils::history::AddEntry {key entry} {
48 if {[
info exists listData($key)]} {
50 set index [lsearch -exact $listData($key) $entry]
54 }
elseif {$index > 0} {
55 set listData($key) [
lreplace $listData($key) $index $index]
57 set listData($key) [
linsert $listData($key) 0 $entry]
60 set listData($key) [list $entry]
64 if { [
llength [
GetList $key]] > 0 } {
66 if { $cb != "" && [
winfo exists $cb]} {
74 proc ::utils::history::SetLimit {key length} {
75 set ::utils::history::listLength($key) $length
80 proc ::utils::history::GetLimit {key} {
82 variable defaultListLength
83 if {[
info exists ::utils::history::listLength($key)]} {
84 return $::utils::history::listLength($key)
86 return $defaultListLength
90 proc ::utils::history::PruneList {key {length -1}} {
92 if {! [
info exists listData($key)]} {
return}
96 set listData($key) [
lrange $listData($key) 0 [
expr {$length - 1}]]
105 proc ::utils::history::GetCombobox {key} {
106 variable comboboxWidget
107 if {[
info exists comboboxWidget($key)]} {
108 return $comboboxWidget($key)
121 proc ::utils::history::SetCombobox {key cbWidget} {
122 set ::utils::history::comboboxWidget($key) $cbWidget
132 proc ::utils::history::RefillCombobox {key} {
133 variable comboboxWidget
136 if {$cbWidget == ""} {
return}
140 if {! [
winfo exists $cbWidget]} {
return}
142 $cbWidget delete 0 end
144 $cbWidget configure -values $entries
152 proc ::utils::history::Save {{reportError 0}} {
158 if {[
catch {open $filename w} f]} {
160 tk_messageBox -title "Scid" -type ok -icon warning \
161 -message "Unable to write file: $filename\n$f"
166 puts $f "# Scid $::scidVersion combobox history lists"
168 foreach i [lsort [
array names listData]] {
169 puts $f "set ::utils::history::listData($i) [list $listData($i)]"