Scid  4.6.5
search.tcl
Go to the documentation of this file.
1 ###
2 ### search.tcl: Search routines for Scid.
3 ###
4 
5 namespace eval ::search {}
6 
7 # searchType: set to Header or Material in a SearchOptions file
8 set searchType 0
9 
10 set ::search::filter::operation 2
11 
12 
13 # search::filter::reset
14 # TODO: remove this function
15 proc ::search::filter::reset {} {
17 }
18 
19 # ::search::filter::negate
20 #
21 # Negates the filter, to include only excluded games.
22 #
23 proc ::search::filter::negate {} {
25 }
26 
27 
28 
29 # ::search::addFilterOpFrame
30 #
31 # Adds a search filter operation selection frame to the window.
32 # Adds a frame of radiobuttons allowing the filter operation
33 # (AND with current filter, OR with current filter, or RESET filter)
34 # to be chosen.
35 # The default value for the first search is RESET:
36 proc ::search::addFilterOpFrame {w {small 0}} {
37  ttk::frame $w.filterop
38  set f $w.filterop
39  pack $f -side top -fill x
40 
41  set regular Regular.TRadiobutton
42  set bold Bold.TRadiobutton
43  if {$small} {
44  set regular Small.TRadiobutton
45  set bold SmallBold.TRadiobutton
46  }
47 
48  ttk::label $f.title -font $bold -textvar ::tr(FilterOperation) -anchor center
49  ttk::frame $f.b
50  ttk::radiobutton $f.b.and -textvar ::tr(FilterAnd) -variable ::search::filter::operation -value 0 -style $regular
51  ttk::radiobutton $f.b.or -textvar ::tr(FilterOr) -variable ::search::filter::operation -value 1 -style $regular
52  ttk::radiobutton $f.b.ignore -textvar ::tr(FilterIgnore) -variable ::search::filter::operation -value 2 -style $regular
53  ## ttk::radiobutton $f.b.search -textvar ::tr(FilterIgnore) -variable ::search::filter::operation -value 3 -style $regular
54  pack $f.title -side top
55  pack $f.b -anchor center -side top
56  pack $f.b.and $f.b.or $f.b.ignore -side left -pady 5 -padx 5
57  ### pack $f.b.and $f.b.or $f.b.ignore $f.b.search -side left -pady 5 -padx 5
58 }
59 
60 
61 # ::search::Config
62 #
63 # Sets state of Search button in Header, Board and Material windows
64 #
65 proc ::search::Config {{state ""}} {
66  if {$state == ""} {
67  set state disabled
68  if {[sc_base inUse]} { set state normal}
69  }
70  catch {.sh.b.search configure -state $state}
71  catch {.sb.b.search configure -state $state}
72  catch {.sm.b3.search configure -state $state}
73 }
74 
75 
76 proc ::search::usefile {} {
77  set ftype { { "Scid SearchOption files" {".sso"} } }
78  set ::fName [tk_getOpenFile -initialdir $::initialDir(base) \
79  -filetypes $ftype -title "Select a SearchOptions file"]
80  if {$::fName == ""} { return}
81 
82  if {[catch {uplevel "#0" {source $::fName}}]} {
83  tk_messageBox -title "Scid: Error reading file" -type ok -icon warning \
84  -message "Unable to open or read SearchOptions file: $fName"
85  } else {
86  switch -- $::searchType {
87  "Material" { ::search::material}
88  "Header" { ::search::header}
89  default { return}
90  }
91  }
92 }
93 
94 # will go to the first game found, except if the Tree of current base is opened (of there will be filter collision)
95 proc ::search::loadFirstGame {} {
96  set w ".treeWin[sc_base current]"
97  if {[winfo exists $w]} { return}
98  ::game::Load [sc_filter first]
99 }