10 namespace eval ::windows::commenteditor {
12 variable w_ .commentWin
13 variable needNotify_ 0
14 variable undoComment_ 1
17 proc clearComment_ {} {
18 if {[
sc_pos getComment] != ""} {
21 set ::windows::commenteditor::needNotify_ 1
27 if {[
sc_pos getNags] != 0} {
30 set ::windows::commenteditor::needNotify_ 1
36 if {$::windows::commenteditor::needNotify_} {
37 after cancel "::notify::PosChanged -pgn"
38 after $wait "::notify::PosChanged -pgn"
42 proc notifyCancel_ {} {
43 after cancel "::notify::PosChanged -pgn"
46 proc storeComment_ {} {
49 set oldComment [
sc_pos getComment]
50 set newComment [$w_.cf.txtframe.text get 1.0 end-1c]
51 if {"$oldComment" ne "$newComment"} {
53 if { $undoComment_ } {
57 sc_pos setComment $newComment
58 set ::windows::commenteditor::needNotify_ 1
65 set nag_stored [
sc_pos getNags]
66 set nag_text [$w_.nf.text get]
68 if {$nag_text == ""} {
set nag_text 0}
69 if {"$nag_text" ne "$nag_stored"} {
76 foreach {nag} [
split "$nag_text" " "] {
79 set ::windows::commenteditor::needNotify_ 1
84 proc updateMarkersCol_ {varname args} {
86 if {![
winfo exists $w_.mf]} {
return}
88 foreach b [
winfo children $w_.mf.markers] {
89 $b configure -foreground $::markColor
92 trace add variable ::markColor write "::windows::commenteditor::updateMarkersCol_"
96 proc ::windows::commenteditor::createWin { {focus_if_exists 1} } {
100 if { $focus_if_exists } {
102 focus $w_.cf.txtframe.text
111 ttk::label $w_.nf.label -font font_Bold -text [
tr AnnotationSymbols]
112 ttk::button $w_.nf.clear -text [
tr Clear] -command "::windows::commenteditor::clearNAGs_"
113 ttk::entry $w_.nf.text
116 foreach {nag description} {
125 +- WhiteDecisiveAdvantage
126 -+ BlackDecisiveAdvantage
127 +/- WhiteClearAdvantage
128 -/+ BlackClearAdvantage
129 += WhiteSlightAdvantage
130 =+ BlackSlightAdvantage
136 ttk::button $w_.nf.b.b$i -text "$nag" -width 3 -command "::addNag $nag"
138 grid $w_.nf.b.b$i -row [
expr {$i % 2}] -column [
expr {int($i / 2)}] -padx 2 -pady 2
141 grid columnconfig $w_.nf 0 -weight 1
142 grid $w_.nf.label $w_.nf.clear -sticky nsew
143 grid $w_.nf.text -sticky nsew -columnspan 2
144 grid $w_.nf.b -sticky nsew -columnspan 2
148 ttk::label $w_.cf.label -font font_Bold -text [
tr Comment]
149 ttk::button $w_.cf.clear -text [
tr Clear] -command "::windows::commenteditor::clearComment_"
150 ttk::frame $w_.cf.txtframe
152 -background white -wrap word -font font_Regular
153 grid rowconfig $w_.cf 1 -weight 1
154 grid columnconfig $w_.cf 0 -weight 1
155 grid $w_.cf.label $w_.cf.clear -sticky nsew
156 grid $w_.cf.txtframe -sticky nsew -columnspan 2
160 ttk::label $w_.mf.header -font font_Bold -text $::tr(InsertMark:)
161 set usage "Usage (on the main board):\n"
162 append usage "ctrl+click --> mark square\n"
163 append usage "ctrl+drag --> draw arrow"
164 ttk::label $w_.mf.usage -text "$usage"
165 ttk::frame $w_.mf.colors
179 radiobutton $w_.mf.colors.col_$color \
180 -indicatoron "false" \
181 -background "$color" -selectcolor "$color" \
183 -variable "::markColor" -value "$color"
184 grid $w_.mf.colors.col_$color -row [
expr {$i / 2}] -column [
expr {int($i % 2)}]
187 ttk::frame $w_.mf.markers
189 foreach {marker lbl} {
216 radiobutton $w_.mf.markers.mark_$marker \
217 -indicatoron "false" \
218 -foreground "$::markColor" -background "light gray" -selectcolor "dark gray" \
219 -text "$lbl" -width 2 \
220 -variable "::markType" -value "$marker"
221 grid $w_.mf.markers.mark_$marker -row [
expr {$i % 5}] -column [
expr {int($i / 5)}]
224 grid $w_.mf.header -columnspan 2 -sticky nsew -padx 8
225 grid $w_.mf.usage -columnspan 2 -sticky nsew -padx 8
226 grid $w_.mf.colors -row 2 -column 0 -sticky nsew -padx 8 -pady 8
227 grid $w_.mf.markers -row 2 -column 1 -sticky nsew -pady 8 -padx 8
230 grid $w_.cf -row 0 -column 0 -columnspan 2 -sticky nsew
231 grid $w_.mf -row 0 -rowspan 2 -column 2 -sticky nsew
232 grid $w_.nf -row 1 -column 0 -columnspan 2 -sticky nsew
233 grid rowconfig $w_ 0 -weight 1
234 grid columnconfig $w_ 0 -weight 1
240 bind $w_ <Destroy> "if {\[string equal $w_ %W\]} { set ::windows::commenteditor::isOpen 0; ::windows::commenteditor::notify_ 1 }"
241 bind $w_.nf.text <KeyPress> "::windows::commenteditor::notifyCancel_"
242 bind $w_.nf.text <KeyRelease> "::windows::commenteditor::storeNAGs_"
243 bind $w_.cf.txtframe.text <KeyPress> "::windows::commenteditor::notifyCancel_"
244 bind $w_.cf.txtframe.text <KeyRelease> "::windows::commenteditor::notify_ 1000"
245 bind $w_.cf.txtframe.text <<Modified>> "
246 ::windows::commenteditor::storeComment_;
247 $w_.cf.txtframe.text edit modified false
250 set ::windows::commenteditor::isOpen 1
251 $w_.cf.txtframe.text edit modified false
252 after idle focus $w_.cf.txtframe.text
258 proc ::windows::commenteditor::Refresh {} {
260 if {![
winfo exists $w_]} {
return}
262 variable needNotify_ 0
264 variable undoComment_ 1
266 set comment [
sc_pos getComment]
267 if {$comment != [$w_.cf.txtframe.text get 1.0 end-1c]} {
268 $w_.cf.txtframe.text delete 1.0 end
269 $w_.cf.txtframe.text insert end $comment
273 $w_.nf.text configure -state normal
274 $w_.nf.text delete 0 end
276 $w_.nf.text insert end $nag
279 if {[
sc_pos isAt vstart]} {
284 $w_.nf.clear configure -state $state
285 $w_.nf.text configure -state $state
286 foreach c [
winfo children $w_.nf.b] {
287 $c configure -state $state
291 proc makeCommentWin {{toggle ""}} {