5 set bookmarks(subMenus) 0
11 namespace eval ::bookmarks {}
16 proc ::bookmarks::PostMenu {} {
17 .main.tb.bkm.menu post [
winfo pointerx .] [
winfo pointery .]
19 .main.tb.bkm.menu activate 0
21 .main.tb.bkm.menu activate 2
28 proc ::bookmarks::Refresh {} {
29 foreach menu {.menu.file.bookmarks .main.tb.bkm.menu} {
34 proc ::bookmarks::RefreshMenu {menu} {
35 global bookmarks helpMessage
40 set numBookmarkEntries [
llength $bookmarks(data)]
41 $menu add command -label FileBookmarksAdd -command ::bookmarks::AddCurrent
42 set helpMessage($menu,0) FileBookmarksAdd
43 $menu add cascade -label FileBookmarksFile -menu $menu.file
45 set helpMessage($menu,1) FileBookmarksFile
47 $menu entryconfigure 0 -state disabled
48 $menu entryconfigure 1 -state disabled
50 $menu add command -label FileBookmarksEdit -command ::bookmarks::Edit
51 set helpMessage($menu,2) FileBookmarksEdit
52 if {$bookmarks(subMenus)} {
59 $menu add command -label FileBookmarks$display \
60 -command "set bookmarks(subMenus) $newval; ::bookmarks::Refresh"
61 set helpMessage($menu,3) FileBookmarks$display
62 foreach tag [list Add File Edit $display] {
63 configMenuText $menu FileBookmarks$tag FileBookmarks$tag $::language
65 if {$numBookmarkEntries == 0} {
return}
72 foreach entry $bookmarks(data) {
73 if {$entry == ""} { continue}
79 -command "::bookmarks::AddCurrent $nfolders"
82 if {! $bookmarks(subMenus)} {
85 }
elseif {!$isfolder} {
87 -command [list ::bookmarks::Go $entry]
93 if {$isfolder && $inSubMenu} {
94 set current [
winfo parent $current]
104 -command [list ::bookmarks::Go $entry]
113 proc ::bookmarks::CanAdd {} {
114 if {[
sc_game number] == 0} {
return 0}
115 if {$::curr_db == $::clipbase_db} {
return 0}
116 set fname [
sc_base filename $::curr_db]
117 foreach suffix {.pgn .PGN} {
118 if {[
string match "*$suffix" "$fname"]} {
return 0}
126 proc ::bookmarks::AddCurrent {{folder 0}} {
132 set len [
llength $bookmarks(data)]
134 for {
set i 0} {$i < $len} {
incr i} {
136 if {$fcount == $folder} { break}
140 set bookmarks(data) [
linsert $bookmarks(data) $i $text]
148 proc ::bookmarks::New {type} {
149 if {$type == "folder"} {
return [list "f" ""]}
150 set text "[
file tail [
sc_base filename $::curr_db]]: [
sc_game info result], "
155 if {$round != "" && $round != "?"} {
append text "($round) "}
156 append text "[
sc_game info year]"
157 set list [list "g" $text]
170 proc ::bookmarks::Go {entry} {
172 set fname [
lindex $entry 2]
173 set gnum [
lindex $entry 3]
174 set ply [
lindex $entry 4]
182 tk_messageBox -icon warning -type ok -parent . \
183 -title "Scid" -message "Unable to load the database:\n$fname\n\n$result"
191 set white [
lindex $entry 5]
192 set black [
lindex $entry 6]
193 set year [
lindex $entry 7]
194 set site [
lindex $entry 8]
195 set round [
lindex $entry 9]
196 set result [
lindex $entry 10]
198 set best [
sc_game find $gnum $white $black $site $round $year $result]
200 tk_messageBox -icon warning -type ok -parent . \
201 -title "Scid" -message "Unable to load game number: $best"
213 proc ::bookmarks::DeleteChildren {w} {
214 foreach child [
winfo children $w] {
224 proc ::bookmarks::NewSubMenu {w entry} {
226 while {[
winfo exists $w.m$i]} {
incr i}
228 menu $w.m$i -tearoff 0
234 set bookmarks(edit) ""
235 set bookmarks(ismenu) 0
242 proc ::bookmarks::Edit {} {
245 if {[
winfo exists $w]} {
return}
246 set bookmarks(old) $bookmarks(data)
248 wm title $w "Scid: [
tr FileBookmarksEdit]"
250 bind $w <F1> {helpWindow Bookmarks}
251 ttk::entry $w.e -width 40 \
252 -textvariable bookmarks(edit) -font font_Small -exportselection 0
253 bind $w.e <FocusIn> {.bmedit.e configure -background lightYellow}
254 bind $w.e <FocusOut> {.bmedit.e configure -background white}
256 trace variable bookmarks(edit) w ::bookmarks::EditRefresh
257 pack $w.e -side top -fill x
258 pack [ttk::frame $w.b2] -side bottom -fill x
259 pack [ttk::frame $w.b1] -side bottom -fill x
260 pack [ttk::frame $w.f] -side top -fill both -expand 1
261 listbox $w.f.list -width 50 -height 10 -yscrollcommand "$w.f.ybar set" \
262 -fg black -bg white -exportselection 0 -font font_Small -setgrid 1
263 ttk::scrollbar $w.f.ybar -takefocus 0 -command "$w.f.list yview"
264 bind $w.f.list <<ListboxSelect>> ::bookmarks::EditSelect
265 pack $w.f.ybar -side right -fill y
266 pack $w.f.list -side left -fill x -expand 1
267 foreach entry $bookmarks(data) {
271 -command {::bookmarks::EditNew folder}
273 -command {::bookmarks::EditNew game}
275 dialogbutton $w.b1.delete -text $::tr(Delete) -command ::bookmarks::EditDelete
276 ttk::button $w.b2.up -image tb_up -command {::bookmarks::EditMove up}
277 ttk::button $w.b2.down -image tb_down -command {::bookmarks::EditMove down}
278 dialogbutton $w.b2.ok -text "OK" -command ::bookmarks::EditDone
279 dialogbutton $w.b2.cancel -text $::tr(Cancel) -command {
280 set bookmarks(data) $bookmarks(old)
281 catch {grab release .bmedit}
284 pack $w.b1.newFolder $w.b1.newGame $w.b1.delete -side left -padx 2 -pady 2
285 pack $w.b2.up $w.b2.down -side left -padx 2 -pady 2
287 set bookmarks(edit) ""
291 set x [
expr {[winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
293 set y [
expr {[winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
305 proc ::bookmarks::EditDone {} {
306 catch {grab release .bmedit}
317 proc ::bookmarks::EditRefresh {args} {
319 set list .bmedit.f.list
320 set sel [
lindex [$list curselection] 0]
321 if {$sel == ""} {
return}
322 set text $bookmarks(edit)
323 set e [
lindex $bookmarks(data) $sel]
326 set bookmarks(data) [
lreplace $bookmarks(data) $sel $sel $e]
327 $list insert $sel $text
328 $list delete [
expr {$sel + 1}]
329 $list selection clear 0 end
330 $list selection set $sel
337 proc ::bookmarks::EditSelect {{sel ""}} {
339 set list .bmedit.f.list
340 set sel [
lindex [$list curselection] 0]
342 .bmedit.e delete 0 end
345 if {$sel >= [
llength $bookmarks(data)]} {
346 $list selection clear 0 end
347 set bookmarks(edit) ""
350 set e [
lindex $bookmarks(data) $sel]
358 proc ::bookmarks::isfolder {entry} {
359 if {[
lindex $entry 0] == "f"} {
return 1}
366 proc ::bookmarks::Text {entry} {
367 return [
lindex $entry 1]
370 proc ::bookmarks::IndexText {entry} {
372 if {[
lindex $entry 0] == "f"} {
373 append text "\[[
lindex $entry 1]\]"
375 append text " [
lindex $entry 1]"
380 proc ::bookmarks::SetText {entry text} {
381 return [
lreplace $entry 1 1 $text]
388 proc ::bookmarks::EditMove {{dir "up"}} {
392 set sel [
lindex [$list curselection] 0]
393 if {$sel == ""} {
return}
394 set e [
lindex $bookmarks(data) $sel]
399 if {$newsel < 0} {
return}
402 if {$newsel >= [$list index end]} {
return}
404 set bookmarks(data) [
lreplace $bookmarks(data) $sel $sel]
405 set bookmarks(data) [
linsert $bookmarks(data) $newsel $e]
406 $list selection clear 0 end
408 $list insert $newsel $text
409 $list selection set $newsel
416 proc ::bookmarks::EditDelete {} {
420 set sel [
lindex [$list curselection] 0]
421 if {$sel == ""} {
return}
422 set bookmarks(data) [
lreplace $bookmarks(data) $sel $sel]
423 $list selection clear 0 end
425 set bookmarks(edit) ""
433 proc ::bookmarks::EditNew {{type "folder"}} {
438 if {[
string index $type 0] == "f"} {
444 set sel [
lindex [$list curselection] 0]
446 lappend bookmarks(data) $entry
447 set sel [$list index end]
449 $list selection clear 0 end
450 $list selection set $sel
456 set bookmarks(data) [
linsert $bookmarks(data) $sel $entry]
458 $list selection clear 0 end
459 $list selection set $sel
469 proc ::bookmarks::Save {{reportError 0}} {
473 if {[
catch {open $filename w} f]} {
475 tk_messageBox -title "Scid" -type ok -icon warning \
476 -message "Unable to write bookmarks file: $filename\n$f"
480 puts $f "# Scid $::scidVersion bookmarks file\n"
481 foreach i {subMenus data} {
482 puts $f "set bookmarks($i) [list [
set bookmarks($i)]]"