8 proc importPgnGame {} {
9 if {[
winfo exists .importWin]} {
return}
12 wm title $w "Scid: $::tr(ImportPGN)"
15 pack $w.b -side bottom -fill x
17 pack $pane -side top -expand true -fill both
19 text $edit.text -height 12 -width 80 -wrap none -background white \
20 -yscroll "$edit.ybar set" -xscroll "$edit.xbar set" -setgrid 1
22 bind $edit.text <Key-Tab> "[
bind all <Key-Tab>]; break"
23 ttk::scrollbar $edit.ybar -command "$edit.text yview" -takefocus 0
24 ttk::scrollbar $edit.xbar -orient horizontal -command "$edit.text xview" -takefocus 0
25 grid $edit.text -row 0 -column 0 -sticky nesw
26 grid $edit.ybar -row 0 -column 1 -sticky nesw
27 grid $edit.xbar -row 1 -column 0 -sticky nesw
28 grid rowconfig $edit 0 -weight 1 -minsize 0
29 grid columnconfig $edit 0 -weight 1 -minsize 0
32 menu $edit.text.rmenu -tearoff 0
33 $edit.text.rmenu add command -label "Cut" -command "tk_textCut $edit.text"
34 $edit.text.rmenu add command -label "Copy" -command "tk_textCopy $edit.text"
35 $edit.text.rmenu add command -label "Paste" -command "tk_textPaste $edit.text"
36 $edit.text.rmenu add command -label "Select all" -command "$edit.text tag add sel 1.0 end"
37 bind $edit.text <ButtonPress-$::MB3> "tk_popup $edit.text.rmenu %X %Y"
39 text $pane.err.text -height 4 -width 75 -wrap word -yscroll "$pane.err.scroll set"
40 $pane.err.text insert end $::tr(ImportHelp1)
41 $pane.err.text insert end "\n"
42 $pane.err.text insert end $::tr(ImportHelp2)
43 $pane.err.text configure -state disabled
44 ttk::scrollbar $pane.err.scroll -command "$pane.err.text yview" -takefocus 0
45 pack $pane.err.scroll -side right -fill y
46 pack $pane.err.text -side left -expand true -fill both
48 ttk::button $w.b.paste -text "$::tr(PasteCurrentGame) (Alt-P)" -command {
49 .importWin.pane.edit.text delete 1.0 end
50 .importWin.pane.edit.text insert end [sc_game pgn -width 70]
51 .importWin.pane.err.text configure -state normal
52 .importWin.pane.err.text delete 1.0 end
53 .importWin.pane.err.text configure -state disabled
55 ttk::button $w.b.clear -text "$::tr(Clear) (Alt-C)" -command {
56 .importWin.pane.edit.text delete 1.0 end
57 .importWin.pane.err.text configure -state normal
58 .importWin.pane.err.text delete 1.0 end
59 .importWin.pane.err.text configure -state disabled
61 ttk::button $w.b.ok -text "$::tr(Import) (Alt-I)" -command {
62 set err [catch {sc_game import \
63 [.importWin.pane.edit.text get 1.0 end]} result]
64 .importWin.pane.err.text configure -state normal
65 .importWin.pane.err.text delete 1.0 end
66 .importWin.pane.err.text insert end $result
67 .importWin.pane.err.text configure -state disabled
72 ttk::button $w.b.cancel -textvar ::tr(Close) -command {
73 destroy .importWin; focus .
75 pack $w.b.paste $w.b.clear -side left -padx 5 -pady "15 5"
82 $w.pane.edit.text tag add sel 1.0 end
84 bind $w <F1> { helpWindow Import }
85 bind $w <Alt-i> { .importWin.b.ok invoke }
86 bind $w <Alt-p> { .importWin.b.paste invoke }
87 bind $w <Alt-c> { .importWin.b.clear invoke }
88 bind $w <Escape> { .importWin.b.cancel invoke }
90 focus $w.pane.edit.text
94 proc importClipboardGame {} {
96 catch {
event generate .importWin.pane.edit.text <<Paste>>}
98 if { [ .importWin.pane.edit.text get 1.0 end] == "\n" } {
99 catch { .importWin.pane.edit.text insert end [selection get]}
103 proc importPgnLine {line} {
105 set w .importWin.pane.edit.text
108 $w tag add sel 1.0 end
115 proc importMoveList {line} {
123 proc importMoveListTrans {line} {
127 if { $::askToReplaceMoves } {
128 if {[
llength [
sc_game firstMoves 1]] == 0} {
130 }
elseif {[
tk_messageBox -message [
::tr "OverwriteExistingMoves"] -type yesno -icon question] == yes} {
147 proc importPgnFile {{base} {fnames ""}} {
149 set ftypes { { "Portable Game Notation files" {".pgn" ".PGN"} } }
150 lappend ftypes { "Text files" {".txt" ".TXT"} }
151 lappend ftypes { "All files" {"*"} }
153 set fnames [
tk_getOpenFile -multiple 1 -initialdir $::initialDir(pgn) -filetypes $ftypes -title "$::tr(ImportingIn) [
file tail [
sc_base filename $base]]"]
154 if {$fnames == ""} {
return}
155 set ::initialDir(pgn) [
file dirname [
lindex $fnames 0]]
162 if {[
winfo exists $w]} {
destroy $w}
164 wm title $w "Scid: $::tr(ImportingFiles) [
file tail [
sc_base filename $base]]"
165 canvas $w.progress -width 400 -height 20 -bg white -relief solid -border 1
166 $w.progress create rectangle 0 0 0 0 -fill blue -outline blue -tags bar
167 $w.progress create text 395 10 -anchor e -font font_Regular -tags time \
168 -fill black -text "0:00 / 0:00"
170 ttk::frame $w.buttons
171 ttk::button $w.buttons.stop -textvar ::tr(Stop) -command { progressBarCancel}
172 ttk::button $w.buttons.close -textvar ::tr(Close) -command "focus .; destroy $w"
173 pack $w.buttons.close $w.buttons.stop -side right -ipadx 5 -padx 5 -pady 2
175 pack [ttk::frame $w.tf] -side top -expand yes -fill both
176 text $w.text -height 8 -width 60 -background gray90 \
177 -wrap none -setgrid 1 -yscrollcommand "$w.ybar set"
178 ttk::scrollbar $w.ybar -command "$w.text yview"
179 pack $w.ybar -in $w.tf -side right -fill y
180 pack $w.text -in $w.tf -side left -fill both -expand yes
181 pack $w.buttons $w.progress -side right
183 catch {grab $w.buttons.stop}
184 bind $w <Escape> "$w.buttons.stop invoke"
185 $w.buttons.close configure -state disabled
188 foreach fname $fnames {
189 $w.text insert end "$::tr(ImportingFrom) [
file tail $fname]...\n"
190 $w.text configure -state disabled
192 set err [
catch {
sc_base import $base $fname} result]
193 $w.text configure -state normal
198 set nImported [
lindex $result 0]
199 set warnings [
lindex $result 1]
200 set str "Imported $nImported "
201 if {$nImported == 1} {
append str "game"}
else {
append str "games"}
202 if {$warnings == ""} {
203 append str " with no PGN errors or warnings."
206 append str ".\nPGN errors/warnings:\n$warnings"
208 $w.text insert end "$str\n\n"
210 $w.text insert end ".\nINTERRUPTED\n"
218 $w.text configure -state disabled
219 $w.buttons.close configure -state normal
220 $w.buttons.stop configure -state disabled
221 catch {grab release $w.buttons.stop}
222 bind $w <Escape> "$w.buttons.close invoke; break"
224 after idle "::notify::DatabaseModified $base"
225 if { $autoclose } {
destroy $w}