0561fb491d24bfee649f938060cdf4cc26dd5672
1 # git-gui blame viewer
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 class blame {
6 image create photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz+nGzmhGzqfGTidIT+nEzGXHTqhGzmfGzifFzadETCVES+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw+Dm510GQQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7}
8 # Persistant data (survives loads)
9 #
10 field history {}; # viewer history: {commit path}
11 field header ; # array commit,key -> header field
13 # Tk UI control paths
14 #
15 field w ; # top window in this viewer
16 field w_back ; # our back button
17 field w_path ; # label showing the current file path
18 field w_columns ; # list of all column widgets in the viewer
19 field w_line ; # text column: all line numbers
20 field w_cgrp ; # text column: abbreviated commit SHA-1s
21 field w_file ; # text column: actual file data
22 field w_cmit ; # pane showing commit message
23 field status ; # text variable bound to status bar
24 field old_height ; # last known height of $w.file_pane
26 # Tk UI colors
27 #
28 field active_color #c0edc5
29 field group_colors {
30 #d6d6d6
31 #e1e1e1
32 #ececec
33 }
35 # Current blame data; cleared/reset on each load
36 #
37 field commit ; # input commit to blame
38 field path ; # input filename to view in $commit
40 field current_fd {} ; # background process running
41 field highlight_line -1 ; # current line selected
42 field highlight_commit {} ; # sha1 of commit selected
43 field old_bgcolor {} ; # background of current selection
45 field total_lines 0 ; # total length of file
46 field blame_lines 0 ; # number of lines computed
47 field have_commit ; # array commit -> 1
48 field line_data ; # list of {commit origfile origline}
50 field r_commit ; # commit currently being parsed
51 field r_orig_line ; # original line number
52 field r_final_line ; # final line number
53 field r_line_count ; # lines in this region
55 field tooltip_wm {} ; # Current tooltip toplevel, if open
56 field tooltip_timer {} ; # Current timer event for our tooltip
57 field tooltip_commit {} ; # Commit in tooltip
58 field tooltip_text {} ; # Text in current tooltip
60 constructor new {i_commit i_path} {
61 global cursor_ptr
63 set commit $i_commit
64 set path $i_path
66 make_toplevel top w
67 wm title $top "[appname] ([reponame]): File Viewer"
69 frame $w.header -background orange
70 label $w.header.commit_l \
71 -text {Commit:} \
72 -background orange \
73 -anchor w \
74 -justify left
75 set w_back $w.header.commit_b
76 label $w_back \
77 -image ::blame::img_back_arrow \
78 -borderwidth 0 \
79 -relief flat \
80 -state disabled \
81 -background orange \
82 -activebackground orange
83 bind $w_back <Button-1> "
84 if {\[$w_back cget -state\] eq {normal}} {
85 [cb _history_menu]
86 }
87 "
88 label $w.header.commit \
89 -textvariable @commit \
90 -background orange \
91 -anchor w \
92 -justify left
93 label $w.header.path_l \
94 -text {File:} \
95 -background orange \
96 -anchor w \
97 -justify left
98 set w_path $w.header.path
99 label $w_path \
100 -background orange \
101 -anchor w \
102 -justify left
103 pack $w.header.commit_l -side left
104 pack $w_back -side left
105 pack $w.header.commit -side left
106 pack $w_path -fill x -side right
107 pack $w.header.path_l -side right
109 panedwindow $w.file_pane -orient vertical
110 frame $w.file_pane.out
111 frame $w.file_pane.cm
112 $w.file_pane add $w.file_pane.out \
113 -sticky nsew \
114 -minsize 100 \
115 -height 100 \
116 -width 100
117 $w.file_pane add $w.file_pane.cm \
118 -sticky nsew \
119 -minsize 25 \
120 -height 25 \
121 -width 100
123 set w_line $w.file_pane.out.linenumber_t
124 text $w_line \
125 -takefocus 0 \
126 -highlightthickness 0 \
127 -padx 0 -pady 0 \
128 -background white -borderwidth 0 \
129 -state disabled \
130 -wrap none \
131 -height 40 \
132 -width 6 \
133 -font font_diff
134 $w_line tag conf linenumber -justify right -rmargin 5
136 set w_cgrp $w.file_pane.out.commit_t
137 text $w_cgrp \
138 -takefocus 0 \
139 -highlightthickness 0 \
140 -padx 0 -pady 0 \
141 -background white -borderwidth 0 \
142 -state disabled \
143 -wrap none \
144 -height 40 \
145 -width 4 \
146 -font font_diff
147 $w_cgrp tag conf curr_commit
148 $w_cgrp tag conf prior_commit \
149 -foreground blue \
150 -underline 1
151 $w_cgrp tag bind prior_commit \
152 <Button-1> \
153 "[cb _load_commit @%x,%y];break"
155 set w_file $w.file_pane.out.file_t
156 text $w_file \
157 -takefocus 0 \
158 -highlightthickness 0 \
159 -padx 0 -pady 0 \
160 -background white -borderwidth 0 \
161 -state disabled \
162 -wrap none \
163 -height 40 \
164 -width 80 \
165 -xscrollcommand [list $w.file_pane.out.sbx set] \
166 -font font_diff
168 set w_columns [list $w_cgrp $w_line $w_file]
170 scrollbar $w.file_pane.out.sbx \
171 -orient h \
172 -command [list $w_file xview]
173 scrollbar $w.file_pane.out.sby \
174 -orient v \
175 -command [list scrollbar2many $w_columns yview]
176 eval grid $w_columns $w.file_pane.out.sby -sticky nsew
177 grid conf \
178 $w.file_pane.out.sbx \
179 -column [expr {[llength $w_columns] - 1}] \
180 -sticky we
181 grid columnconfigure \
182 $w.file_pane.out \
183 [expr {[llength $w_columns] - 1}] \
184 -weight 1
185 grid rowconfigure $w.file_pane.out 0 -weight 1
187 set w_cmit $w.file_pane.cm.t
188 text $w_cmit \
189 -background white -borderwidth 0 \
190 -state disabled \
191 -wrap none \
192 -height 10 \
193 -width 80 \
194 -xscrollcommand [list $w.file_pane.cm.sbx set] \
195 -yscrollcommand [list $w.file_pane.cm.sby set] \
196 -font font_diff
197 $w_cmit tag conf header_key \
198 -tabs {3c} \
199 -background $active_color \
200 -font font_uibold
201 $w_cmit tag conf header_val \
202 -background $active_color \
203 -font font_ui
204 $w_cmit tag raise sel
205 scrollbar $w.file_pane.cm.sbx \
206 -orient h \
207 -command [list $w_cmit xview]
208 scrollbar $w.file_pane.cm.sby \
209 -orient v \
210 -command [list $w_cmit yview]
211 pack $w.file_pane.cm.sby -side right -fill y
212 pack $w.file_pane.cm.sbx -side bottom -fill x
213 pack $w_cmit -expand 1 -fill both
215 frame $w.status \
216 -borderwidth 1 \
217 -relief sunken
218 label $w.status.l \
219 -textvariable @status \
220 -anchor w \
221 -justify left
222 pack $w.status.l -side left
224 menu $w.ctxm -tearoff 0
225 $w.ctxm add command \
226 -label "Copy Commit" \
227 -command [cb _copycommit]
229 foreach i $w_columns {
230 $i conf -cursor $cursor_ptr
231 $i conf -yscrollcommand [list many2scrollbar \
232 $w_columns yview $w.file_pane.out.sby]
233 bind $i <Button-1> "
234 [cb _hide_tooltip]
235 [cb _click $i @%x,%y]
236 focus $i
237 "
238 bind $i <Any-Motion> [cb _show_tooltip $i @%x,%y]
239 bind $i <Any-Enter> [cb _hide_tooltip]
240 bind $i <Any-Leave> [cb _hide_tooltip]
241 bind_button3 $i "
242 [cb _hide_tooltip]
243 set cursorX %x
244 set cursorY %y
245 set cursorW %W
246 tk_popup $w.ctxm %X %Y
247 "
248 }
250 foreach i [concat $w_columns $w_cmit] {
251 bind $i <Key-Up> {catch {%W yview scroll -1 units};break}
252 bind $i <Key-Down> {catch {%W yview scroll 1 units};break}
253 bind $i <Key-Left> {catch {%W xview scroll -1 units};break}
254 bind $i <Key-Right> {catch {%W xview scroll 1 units};break}
255 bind $i <Key-k> {catch {%W yview scroll -1 units};break}
256 bind $i <Key-j> {catch {%W yview scroll 1 units};break}
257 bind $i <Key-h> {catch {%W xview scroll -1 units};break}
258 bind $i <Key-l> {catch {%W xview scroll 1 units};break}
259 bind $i <Control-Key-b> {catch {%W yview scroll -1 pages};break}
260 bind $i <Control-Key-f> {catch {%W yview scroll 1 pages};break}
261 }
263 bind $w_cmit <Button-1> [list focus $w_cmit]
264 bind $top <Visibility> [list focus $top]
265 bind $w_file <Destroy> [list delete_this $this]
267 grid configure $w.header -sticky ew
268 grid configure $w.file_pane -sticky nsew
269 grid configure $w.status -sticky ew
270 grid columnconfigure $top 0 -weight 1
271 grid rowconfigure $top 0 -weight 0
272 grid rowconfigure $top 1 -weight 1
273 grid rowconfigure $top 2 -weight 0
275 set req_w [winfo reqwidth $top]
276 set req_h [winfo reqheight $top]
277 if {$req_w < 600} {set req_w 600}
278 if {$req_h < 400} {set req_h 400}
279 set g "${req_w}x${req_h}"
280 wm geometry $top $g
281 update
283 set old_height [winfo height $w.file_pane]
284 $w.file_pane sash place 0 \
285 [lindex [$w.file_pane sash coord 0] 0] \
286 [expr {int($old_height * 0.70)}]
287 bind $w.file_pane <Configure> \
288 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
290 _load $this
291 }
293 method _load {} {
294 _hide_tooltip $this
296 if {$total_lines != 0 || $current_fd ne {}} {
297 if {$current_fd ne {}} {
298 catch {close $current_fd}
299 set current_fd {}
300 }
302 foreach i $w_columns {
303 $i conf -state normal
304 $i delete 0.0 end
305 foreach cmit [array names have_commit] {
306 $i tag delete g$cmit
307 }
308 $i conf -state disabled
309 }
311 set highlight_line -1
312 set highlight_commit {}
313 set total_lines 0
314 set blame_lines 0
315 array unset have_commit
316 }
318 if {[winfo exists $w.status.c]} {
319 $w.status.c coords bar 0 0 0 20
320 } else {
321 canvas $w.status.c \
322 -width 100 \
323 -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
324 -borderwidth 1 \
325 -relief groove \
326 -highlightt 0
327 $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
328 pack $w.status.c -side right
329 }
331 if {$history eq {}} {
332 $w_back conf -state disabled
333 } else {
334 $w_back conf -state normal
335 }
336 lappend history [list $commit $path]
338 # Index 0 is always empty. There is never line 0 as
339 # we use only 1 based lines, as that matches both with
340 # git-blame output and with Tk's text widget.
341 #
342 set line_data [list [list]]
344 set status "Loading $commit:[escape_path $path]..."
345 $w_path conf -text [escape_path $path]
346 if {$commit eq {}} {
347 set fd [open $path r]
348 } else {
349 set cmd [list git cat-file blob "$commit:$path"]
350 set fd [open "| $cmd" r]
351 }
352 fconfigure $fd -blocking 0 -translation lf -encoding binary
353 fileevent $fd readable [cb _read_file $fd]
354 set current_fd $fd
355 }
357 method _history_menu {} {
358 set m $w.backmenu
359 if {[winfo exists $m]} {
360 $m delete 0 end
361 } else {
362 menu $m -tearoff 0
363 }
365 for {set i [expr {[llength $history] - 2}]
366 } {$i >= 0} {incr i -1} {
367 set e [lindex $history $i]
368 set c [lindex $e 0]
369 set f [lindex $e 1]
371 if {[regexp {^[0-9a-f]{40}$} $c]} {
372 set t [string range $c 0 8]...
373 } elseif {$c eq {}} {
374 set t {Working Directory}
375 } else {
376 set t $c
377 }
378 if {![catch {set summary $header($c,summary)}]} {
379 append t " $summary"
380 if {[string length $t] > 70} {
381 set t [string range $t 0 66]...
382 }
383 }
385 $m add command -label $t -command [cb _goback $i $c $f]
386 }
387 set X [winfo rootx $w_back]
388 set Y [expr {[winfo rooty $w_back] + [winfo height $w_back]}]
389 tk_popup $m $X $Y
390 }
392 method _goback {i c f} {
393 set history [lrange $history 0 [expr {$i - 1}]]
394 set commit $c
395 set path $f
396 _load $this
397 }
399 method _read_file {fd} {
400 if {$fd ne $current_fd} {
401 catch {close $fd}
402 return
403 }
405 foreach i $w_columns {$i conf -state normal}
406 while {[gets $fd line] >= 0} {
407 regsub "\r\$" $line {} line
408 incr total_lines
409 lappend line_data {}
411 if {$total_lines > 1} {
412 foreach i $w_columns {$i insert end "\n"}
413 }
415 $w_line insert end "$total_lines" linenumber
416 $w_file insert end "$line"
417 }
419 set ln_wc [expr {[string length $total_lines] + 2}]
420 if {[$w_line cget -width] < $ln_wc} {
421 $w_line conf -width $ln_wc
422 }
424 foreach i $w_columns {$i conf -state disabled}
426 if {[eof $fd]} {
427 close $fd
429 _status $this
430 set cmd {nice git blame -M -C --incremental}
431 if {$commit eq {}} {
432 lappend cmd --contents $path
433 } else {
434 lappend cmd $commit
435 }
436 lappend cmd -- $path
437 set fd [open "| $cmd" r]
438 fconfigure $fd -blocking 0 -translation lf -encoding binary
439 fileevent $fd readable [cb _read_blame $fd]
440 set current_fd $fd
441 }
442 } ifdeleted { catch {close $fd} }
444 method _read_blame {fd} {
445 if {$fd ne $current_fd} {
446 catch {close $fd}
447 return
448 }
450 $w_cgrp conf -state normal
451 while {[gets $fd line] >= 0} {
452 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
453 cmit original_line final_line line_count]} {
454 set r_commit $cmit
455 set r_orig_line $original_line
456 set r_final_line $final_line
457 set r_line_count $line_count
459 if {[catch {set g $have_commit($cmit)}]} {
460 set bg [lindex $group_colors 0]
461 set group_colors [lrange $group_colors 1 end]
462 lappend group_colors $bg
463 foreach i $w_columns {
464 $i tag conf g$cmit -background $bg
465 }
466 set have_commit($cmit) 1
467 }
468 } elseif {[string match {filename *} $line]} {
469 set file [string range $line 9 end]
470 set n $r_line_count
471 set lno $r_final_line
472 set cmit $r_commit
474 if {[regexp {^0{40}$} $cmit]} {
475 set commit_abbr work
476 set commit_type curr_commit
477 } elseif {$cmit eq $commit} {
478 set commit_abbr this
479 set commit_type curr_commit
480 } else {
481 set commit_type prior_commit
482 set commit_abbr [string range $cmit 0 4]
483 }
485 set author_abbr {}
486 set a_name {}
487 catch {set a_name $header($cmit,author)}
488 while {$a_name ne {}} {
489 if {![regexp {^([[:upper:]])} $a_name _a]} break
490 append author_abbr $_a
491 unset _a
492 if {![regsub \
493 {^[[:upper:]][^\s]*\s+} \
494 $a_name {} a_name ]} break
495 }
496 if {$author_abbr eq {}} {
497 set author_abbr { |}
498 } else {
499 set author_abbr [string range $author_abbr 0 3]
500 while {[string length $author_abbr] < 4} {
501 set author_abbr " $author_abbr"
502 }
503 }
504 unset a_name
506 set first_lno $lno
507 while {
508 $first_lno > 1
509 && $cmit eq [lindex $line_data [expr {$first_lno - 1}] 0]
510 && $file eq [lindex $line_data [expr {$first_lno - 1}] 1]
511 } {
512 incr first_lno -1
513 }
515 while {$n > 0} {
516 set lno_e "$lno.0 lineend + 1c"
517 if {[lindex $line_data $lno] ne {}} {
518 set g [lindex $line_data $lno 0]
519 foreach i $w_columns {
520 $i tag remove g$g $lno.0 $lno_e
521 }
522 }
523 lset line_data $lno [list $cmit $file]
525 $w_cgrp delete $lno.0 "$lno.0 lineend"
526 if {$lno == $first_lno} {
527 $w_cgrp insert $lno.0 $commit_abbr $commit_type
528 } elseif {$lno == [expr {$first_lno + 1}]} {
529 $w_cgrp insert $lno.0 $author_abbr
530 } else {
531 $w_cgrp insert $lno.0 { |}
532 }
534 foreach i $w_columns {
535 $i tag add g$cmit $lno.0 $lno_e
536 }
538 if {$highlight_line == -1} {
539 if {[lindex [$w_file yview] 0] == 0} {
540 $w_file see $lno.0
541 _showcommit $this $lno
542 }
543 } elseif {$highlight_line == $lno} {
544 _showcommit $this $lno
545 }
547 incr n -1
548 incr lno
549 incr blame_lines
550 }
552 while {
553 $cmit eq [lindex $line_data $lno 0]
554 && $file eq [lindex $line_data $lno 1]
555 } {
556 $w_cgrp delete $lno.0 "$lno.0 lineend"
558 if {$lno == $first_lno} {
559 $w_cgrp insert $lno.0 $commit_abbr $commit_type
560 } elseif {$lno == [expr {$first_lno + 1}]} {
561 $w_cgrp insert $lno.0 $author_abbr
562 } else {
563 $w_cgrp insert $lno.0 { |}
564 }
565 incr lno
566 }
568 } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
569 set header($r_commit,$key) $data
570 }
571 }
572 $w_cgrp conf -state disabled
574 if {[eof $fd]} {
575 close $fd
576 set current_fd {}
577 set status {Annotation complete.}
578 destroy $w.status.c
579 } else {
580 _status $this
581 }
582 } ifdeleted { catch {close $fd} }
584 method _status {} {
585 set have $blame_lines
586 set total $total_lines
587 set pdone 0
588 if {$total} {set pdone [expr {100 * $have / $total}]}
590 set status [format \
591 "Loading annotations... %i of %i lines annotated (%2i%%)" \
592 $have $total $pdone]
593 $w.status.c coords bar 0 0 $pdone 20
594 }
596 method _click {cur_w pos} {
597 set lno [lindex [split [$cur_w index $pos] .] 0]
598 if {$lno eq {}} return
599 _showcommit $this $lno
600 }
602 method _load_commit {pos} {
603 set lno [lindex [split [$w_cgrp index $pos] .] 0]
604 set dat [lindex $line_data $lno]
605 if {$dat ne {}} {
606 set commit [lindex $dat 0]
607 set path [lindex $dat 1]
608 _load $this
609 }
610 }
612 method _showcommit {lno} {
613 global repo_config
615 if {$highlight_commit ne {}} {
616 foreach i $w_columns {
617 $i tag conf g$highlight_commit -background $old_bgcolor
618 }
619 }
621 $w_cmit conf -state normal
622 $w_cmit delete 0.0 end
624 set dat [lindex $line_data $lno]
625 if {$dat eq {}} {
626 set cmit {}
627 $w_cmit insert end "Loading annotation..."
628 } else {
629 set cmit [lindex $dat 0]
630 set file [lindex $dat 1]
632 set old_bgcolor [$w_file tag cget g$cmit -background]
633 foreach i $w_columns {
634 $i tag conf g$cmit -background $active_color
635 }
637 set author_name {}
638 set author_email {}
639 set author_time {}
640 catch {set author_name $header($cmit,author)}
641 catch {set author_email $header($cmit,author-mail)}
642 catch {set author_time [clock format \
643 $header($cmit,author-time) \
644 -format {%Y-%m-%d %H:%M:%S}
645 ]}
647 set committer_name {}
648 set committer_email {}
649 set committer_time {}
650 catch {set committer_name $header($cmit,committer)}
651 catch {set committer_email $header($cmit,committer-mail)}
652 catch {set committer_time [clock format \
653 $header($cmit,committer-time) \
654 -format {%Y-%m-%d %H:%M:%S}
655 ]}
657 if {[catch {set msg $header($cmit,message)}]} {
658 set msg {}
659 catch {
660 set fd [open "| git cat-file commit $cmit" r]
661 fconfigure $fd -encoding binary -translation lf
662 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
663 set enc utf-8
664 }
665 while {[gets $fd line] > 0} {
666 if {[string match {encoding *} $line]} {
667 set enc [string tolower [string range $line 9 end]]
668 }
669 }
670 set msg [encoding convertfrom $enc [read $fd]]
671 set msg [string trim $msg]
672 close $fd
674 set author_name [encoding convertfrom $enc $author_name]
675 set committer_name [encoding convertfrom $enc $committer_name]
677 set header($cmit,author) $author_name
678 set header($cmit,committer) $committer_name
679 }
680 set header($cmit,message) $msg
681 }
683 $w_cmit insert end "commit $cmit\n" header_key
684 $w_cmit insert end "Author:\t" header_key
685 $w_cmit insert end "$author_name $author_email" header_val
686 $w_cmit insert end "$author_time\n" header_val
688 $w_cmit insert end "Committer:\t" header_key
689 $w_cmit insert end "$committer_name $committer_email" header_val
690 $w_cmit insert end "$committer_time\n" header_val
692 if {$file ne $path} {
693 $w_cmit insert end "Original File:\t" header_key
694 $w_cmit insert end "[escape_path $file]\n" header_val
695 }
697 $w_cmit insert end "\n$msg"
698 }
699 $w_cmit conf -state disabled
701 set highlight_line $lno
702 set highlight_commit $cmit
704 if {$highlight_commit eq $tooltip_commit} {
705 _hide_tooltip $this
706 }
707 }
709 method _copycommit {} {
710 set pos @$::cursorX,$::cursorY
711 set lno [lindex [split [$::cursorW index $pos] .] 0]
712 set dat [lindex $line_data $lno]
713 if {$dat ne {}} {
714 clipboard clear
715 clipboard append \
716 -format STRING \
717 -type STRING \
718 -- [lindex $dat 0]
719 }
720 }
722 method _show_tooltip {cur_w pos} {
723 set lno [lindex [split [$cur_w index $pos] .] 0]
724 set dat [lindex $line_data $lno]
725 if {$dat eq {}} {
726 _hide_tooltip $this
727 return
728 }
729 set cmit [lindex $dat 0]
731 if {$cmit eq $highlight_commit} {
732 _hide_tooltip $this
733 return
734 }
736 if {$cmit eq $tooltip_commit} {
737 _position_tooltip $this
738 } elseif {$tooltip_wm ne {}} {
739 _open_tooltip $this $cur_w
740 } elseif {$tooltip_timer eq {}} {
741 set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
742 }
743 }
745 method _open_tooltip {cur_w} {
746 set tooltip_timer {}
747 set pos_x [winfo pointerx $cur_w]
748 set pos_y [winfo pointery $cur_w]
749 if {[winfo containing $pos_x $pos_y] ne $cur_w} {
750 _hide_tooltip $this
751 return
752 }
754 set pos @[join [list \
755 [expr {$pos_x - [winfo rootx $cur_w]}] \
756 [expr {$pos_y - [winfo rooty $cur_w]}]] ,]
757 set lno [lindex [split [$cur_w index $pos] .] 0]
758 set dat [lindex $line_data $lno]
759 set cmit [lindex $dat 0]
760 set file [lindex $dat 1]
762 set author_name {}
763 set author_email {}
764 set author_time {}
765 catch {set author_name $header($cmit,author)}
766 catch {set author_email $header($cmit,author-mail)}
767 catch {set author_time [clock format \
768 $header($cmit,author-time) \
769 -format {%Y-%m-%d %H:%M:%S}
770 ]}
772 set committer_name {}
773 set committer_email {}
774 set committer_time {}
775 catch {set committer_name $header($cmit,committer)}
776 catch {set committer_email $header($cmit,committer-mail)}
777 catch {set committer_time [clock format \
778 $header($cmit,committer-time) \
779 -format {%Y-%m-%d %H:%M:%S}
780 ]}
782 set summary {}
783 catch {set summary $header($cmit,summary)}
785 set tooltip_commit $cmit
786 set tooltip_text "commit $cmit
787 $author_name $author_email $author_time
788 $summary"
790 if {$file ne $path} {
791 append tooltip_text "
793 Original File: $file"
794 }
796 if {$tooltip_wm ne "$cur_w.tooltip"} {
797 _hide_tooltip $this
799 set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
800 wm overrideredirect $tooltip_wm 1
801 wm transient $tooltip_wm [winfo toplevel $cur_w]
802 pack [label $tooltip_wm.label \
803 -background lightyellow \
804 -foreground black \
805 -textvariable @tooltip_text \
806 -justify left]
807 }
808 _position_tooltip $this
809 }
811 method _position_tooltip {} {
812 set req_w [winfo reqwidth $tooltip_wm.label]
813 set req_h [winfo reqheight $tooltip_wm.label]
814 set pos_x [expr {[winfo pointerx .] + 5}]
815 set pos_y [expr {[winfo pointery .] + 10}]
817 set g "${req_w}x${req_h}"
818 if {$pos_x >= 0} {append g +}
819 append g $pos_x
820 if {$pos_y >= 0} {append g +}
821 append g $pos_y
823 wm geometry $tooltip_wm $g
824 raise $tooltip_wm
825 }
827 method _hide_tooltip {} {
828 if {$tooltip_wm ne {}} {
829 destroy $tooltip_wm
830 set tooltip_wm {}
831 set tooltip_commit {}
832 }
833 if {$tooltip_timer ne {}} {
834 after cancel $tooltip_timer
835 set tooltip_timer {}
836 }
837 }
839 method _resize {new_height} {
840 set diff [expr {$new_height - $old_height}]
841 if {$diff == 0} return
843 set my [expr {[winfo height $w.file_pane] - 25}]
844 set o [$w.file_pane sash coord 0]
845 set ox [lindex $o 0]
846 set oy [expr {[lindex $o 1] + $diff}]
847 if {$oy < 0} {set oy 0}
848 if {$oy > $my} {set oy $my}
849 $w.file_pane sash place 0 $ox $oy
851 set old_height $new_height
852 }
854 }