17 namespace eval ::search {}
25 proc ::search::Open {ref_base ref_filter title create_subwnd} {
27 if {[
winfo exists $w]} {
destroy $w}
31 grid [ttk::frame $w.refdb] -sticky news
33 trace add variable ::search::dbase_($w) write ::search::use_dbfilter_
34 set ::search::filter_($w) $ref_filter
36 grid [ttk::frame $w.options] -sticky news
37 set options_cmd [$create_subwnd $w.options]
39 grid [ttk::labelframe $w.filterOp] -sticky news -pady 8
40 if {![
info exists ::search::filterOp_($w)]} {
41 set ::search::filterOp_($w) reset
43 ttk::radiobutton $w.filterOp.and -text [
::tr FilterAnd] -variable ::search::filterOp_($w) -value and
44 ttk::radiobutton $w.filterOp.or -text [
::tr FilterOr] -variable ::search::filterOp_($w) -value or
45 ttk::radiobutton $w.filterOp.reset -text [
::tr FilterIgnore] -variable ::search::filterOp_($w) -value reset
46 grid $w.filterOp.and $w.filterOp.or $w.filterOp.reset -ipadx 8
48 grid [ttk::frame $w.buttons] -sticky news
49 ttk::button $w.buttons.save -text [
::tr Save] -state disabled \
50 -command "::search::save_ $options_cmd"
51 ttk::button $w.buttons.reset_values -text [
::tr Defaults] \
52 -command "set ::search::filterOp_($w) reset; $options_cmd reset"
53 ttk::button $w.buttons.search_new -text "[
tr Search] ([
tr GlistNewSort] [
tr Filter])" \
54 -command "::search::start_ 1 $w $options_cmd"
55 ttk::button $w.buttons.search -text [
::tr Search] \
56 -command "::search::start_ 0 $w $options_cmd"
57 grid $w.buttons.save $w.buttons.reset_values x $w.buttons.search_new $w.buttons.search -sticky w -padx "0 5"
58 grid columnconfigure $w.buttons 2 -weight 1
60 ttk::button $w.buttons.stop -text [
::tr Stop] -command progressBarCancel
61 canvas $w.progressbar -width 300 -height 20 -bg white -relief solid -border 1 -highlightthickness 0
62 $w.progressbar create rectangle 0 0 0 0 -fill blue -outline blue -tags bar
63 $w.progressbar create text 295 10 -anchor e -font font_Regular -tags time
64 grid $w.buttons.stop -row 0 -column 0
65 grid $w.progressbar -in $w.buttons -row 0 -column 1 -columnspan 4
68 bind $w <Return> "$w.buttons.search invoke"
69 bind $w.buttons.search <Destroy> "unset ::search::dbase_($w)"
74 proc ::search::CloseAll {} {
75 foreach {w} [
array names ::search::dbase_] {
80 proc ::search::DatabaseModified {{dbase} {filter -1}} {
81 foreach {w w_base} [
array get ::search::dbase_] {
82 if {$dbase == $w_base} {
83 if {$filter == -1 || $filter eq $::search::filter_($w)} {
90 proc ::search::refresh_ {w} {
92 lassign [
sc_filter sizes $::search::dbase_($w) $::search::filter_($w)] filterSz gameSz
98 $w.filterOp configure -text "[
::tr FilterOperation] ($n_games)"
101 proc ::search::use_dbfilter_ { unused1 w {unused2 ""} } {
102 set ::search::filter_($w) dbfilter
105 proc ::search::progressbar_ {w show_hide} {
106 if {$show_hide eq "show"} {
107 grid remove $w.buttons.save
108 grid remove $w.buttons.reset_values
109 grid remove $w.buttons.search_new
110 grid remove $w.buttons.search
116 grab release $w.buttons.stop
117 grid remove $w.buttons.stop
118 grid remove $w.progressbar
120 grid $w.buttons.reset_values
121 grid $w.buttons.search_new
122 grid $w.buttons.search
126 proc ::search::save_ {options_cmd} {
130 proc ::search::start_ {new_filter w options_cmd} {
131 set dbase $::search::dbase_($w)
132 set src_filter $::search::filter_($w)
133 set src_op $::search::filterOp_($w)
138 set dest_filter [
sc_filter compose $dbase $src_filter ""]
140 if {$dest_filter ne $src_filter && $src_op ne "reset"} {
141 sc_filter copy $dbase $dest_filter $src_filter
144 lassign [$options_cmd] options ignore_color_hack
145 if {$ignore_color_hack ne ""} {
147 sc_filter copy $dbase $filter_hack $dest_filter
157 if {!$err && $ignore_color_hack ne ""} {
164 sc_filter or $dbase $dest_filter $filter_hack
167 if {$ignore_color_hack ne ""} {
171 set ::search::filter_($w) $dest_filter
179 proc ::search::do_search_ {dbase filter filter_op options} {
193 sc_filter search $dbase $filter {*}$options -filter AND
195 if {[
info exists or_filter]} {
205 proc ::search::board {{ref_base ""} {ref_filter "dbfilter"}} {
206 ::search::Open $ref_base $ref_filter BoardSearch ::search::boardCreateFrame
209 proc ::search::boardCreateFrame {w} {
210 if {![
info exists ::search::boardOptType_]} {
214 ttk::labelframe $w.pos -text [
::tr SearchType]
215 grid $w.pos -sticky news -pady 6
216 grid columnconfigure $w 0 -weight 1
218 ttk::radiobutton $w.pos.exact -textvar ::tr(SearchBoardExact) -variable ::search::boardOptType_ -value Exact
219 ttk::radiobutton $w.pos.pawns -textvar ::tr(SearchBoardPawns) -variable ::search::boardOptType_ -value Pawns
220 ttk::radiobutton $w.pos.files -textvar ::tr(SearchBoardFiles) -variable ::search::boardOptType_ -value Fyles
221 ttk::radiobutton $w.pos.material -textvar ::tr(SearchBoardAny) -variable ::search::boardOptType_ -value Material
222 grid $w.pos.exact -sticky w
223 grid $w.pos.pawns -sticky w
224 grid $w.pos.files -sticky w
225 grid $w.pos.material -sticky w
227 ttk::checkbutton $w.vars -text [
::tr LookInVars] -variable ::search::boardOptInVars_ -onvalue 1 -offvalue 0
228 grid $w.vars -sticky w
230 ttk::checkbutton $w.flip -text [
::tr IgnoreColors] -variable ::search::boardOptIgnoreCol_ -onvalue 1 -offvalue 0
231 grid $w.flip -sticky w
233 return "::search::boardOptions"
236 proc ::search::boardOptions {{cmd ""}} {
237 if {$cmd eq "reset"} {
238 set ::search::boardOptType_ Exact
239 set ::search::boardOptInVars_ 0
240 set ::search::boardOptIgnoreCol_ 0
245 lappend options $::search::boardOptType_
246 lappend options $::search::boardOptInVars_
247 lappend options $::search::boardOptIgnoreCol_
248 return [list $options]