git-gui: Display the "Loading annotation..." message in italic
[git-gui.git] / lib / blame.tcl
blob0641ea6d373d1e47ebf029818b5772629f68a238
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)
10 field history {}; # viewer history: {commit path}
11 field header ; # array commit,key -> header field
13 # Tk UI control paths
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_amov ; # text column: annotations + move tracking
21 field w_file ; # text column: actual file data
22 field w_cviewer ; # 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
28 field active_color #c0edc5
29 field group_colors {
30 #d6d6d6
31 #e1e1e1
32 #ececec
35 # Current blame data; cleared/reset on each load
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 amov_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]
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_amov $w.file_pane.out.amove_t
137 text $w_amov \
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_amov tag conf curr_commit
148 $w_amov tag conf prior_commit \
149 -foreground blue \
150 -underline 1
151 $w_amov 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_amov $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_cviewer $w.file_pane.cm.t
188 text $w_cviewer \
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_cviewer tag conf still_loading \
198 -font font_uiitalic \
199 -justify center
200 $w_cviewer tag conf header_key \
201 -tabs {3c} \
202 -background $active_color \
203 -font font_uibold
204 $w_cviewer tag conf header_val \
205 -background $active_color \
206 -font font_ui
207 $w_cviewer tag raise sel
208 scrollbar $w.file_pane.cm.sbx \
209 -orient h \
210 -command [list $w_cviewer xview]
211 scrollbar $w.file_pane.cm.sby \
212 -orient v \
213 -command [list $w_cviewer yview]
214 pack $w.file_pane.cm.sby -side right -fill y
215 pack $w.file_pane.cm.sbx -side bottom -fill x
216 pack $w_cviewer -expand 1 -fill both
218 frame $w.status \
219 -borderwidth 1 \
220 -relief sunken
221 label $w.status.l \
222 -textvariable @status \
223 -anchor w \
224 -justify left
225 pack $w.status.l -side left
227 menu $w.ctxm -tearoff 0
228 $w.ctxm add command \
229 -label "Copy Commit" \
230 -command [cb _copycommit]
232 foreach i $w_columns {
233 $i conf -cursor $cursor_ptr
234 $i conf -yscrollcommand [list many2scrollbar \
235 $w_columns yview $w.file_pane.out.sby]
236 bind $i <Button-1> "
237 [cb _hide_tooltip]
238 [cb _click $i @%x,%y]
239 focus $i
241 bind $i <Any-Motion> [cb _show_tooltip $i @%x,%y]
242 bind $i <Any-Enter> [cb _hide_tooltip]
243 bind $i <Any-Leave> [cb _hide_tooltip]
244 bind_button3 $i "
245 [cb _hide_tooltip]
246 set cursorX %x
247 set cursorY %y
248 set cursorW %W
249 tk_popup $w.ctxm %X %Y
253 foreach i [concat $w_columns $w_cviewer] {
254 bind $i <Key-Up> {catch {%W yview scroll -1 units};break}
255 bind $i <Key-Down> {catch {%W yview scroll 1 units};break}
256 bind $i <Key-Left> {catch {%W xview scroll -1 units};break}
257 bind $i <Key-Right> {catch {%W xview scroll 1 units};break}
258 bind $i <Key-k> {catch {%W yview scroll -1 units};break}
259 bind $i <Key-j> {catch {%W yview scroll 1 units};break}
260 bind $i <Key-h> {catch {%W xview scroll -1 units};break}
261 bind $i <Key-l> {catch {%W xview scroll 1 units};break}
262 bind $i <Control-Key-b> {catch {%W yview scroll -1 pages};break}
263 bind $i <Control-Key-f> {catch {%W yview scroll 1 pages};break}
266 bind $w_cviewer <Button-1> [list focus $w_cviewer]
267 bind $top <Visibility> [list focus $top]
268 bind $w_file <Destroy> [list delete_this $this]
270 grid configure $w.header -sticky ew
271 grid configure $w.file_pane -sticky nsew
272 grid configure $w.status -sticky ew
273 grid columnconfigure $top 0 -weight 1
274 grid rowconfigure $top 0 -weight 0
275 grid rowconfigure $top 1 -weight 1
276 grid rowconfigure $top 2 -weight 0
278 set req_w [winfo reqwidth $top]
279 set req_h [winfo reqheight $top]
280 if {$req_w < 600} {set req_w 600}
281 if {$req_h < 400} {set req_h 400}
282 set g "${req_w}x${req_h}"
283 wm geometry $top $g
284 update
286 set old_height [winfo height $w.file_pane]
287 $w.file_pane sash place 0 \
288 [lindex [$w.file_pane sash coord 0] 0] \
289 [expr {int($old_height * 0.70)}]
290 bind $w.file_pane <Configure> \
291 "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
293 _load $this
296 method _load {} {
297 _hide_tooltip $this
299 if {$total_lines != 0 || $current_fd ne {}} {
300 if {$current_fd ne {}} {
301 catch {close $current_fd}
302 set current_fd {}
305 foreach i $w_columns {
306 $i conf -state normal
307 $i delete 0.0 end
308 foreach cmit [array names have_commit] {
309 $i tag delete g$cmit
311 $i conf -state disabled
314 set highlight_line -1
315 set highlight_commit {}
316 set total_lines 0
317 set blame_lines 0
318 array unset have_commit
321 if {[winfo exists $w.status.c]} {
322 $w.status.c coords bar 0 0 0 20
323 } else {
324 canvas $w.status.c \
325 -width 100 \
326 -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
327 -borderwidth 1 \
328 -relief groove \
329 -highlightt 0
330 $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
331 pack $w.status.c -side right
334 if {$history eq {}} {
335 $w_back conf -state disabled
336 } else {
337 $w_back conf -state normal
339 lappend history [list $commit $path]
341 # Index 0 is always empty. There is never line 0 as
342 # we use only 1 based lines, as that matches both with
343 # git-blame output and with Tk's text widget.
345 set amov_data [list [list]]
347 set status "Loading $commit:[escape_path $path]..."
348 $w_path conf -text [escape_path $path]
349 if {$commit eq {}} {
350 set fd [open $path r]
351 } else {
352 set cmd [list git cat-file blob "$commit:$path"]
353 set fd [open "| $cmd" r]
355 fconfigure $fd -blocking 0 -translation lf -encoding binary
356 fileevent $fd readable [cb _read_file $fd]
357 set current_fd $fd
360 method _history_menu {} {
361 set m $w.backmenu
362 if {[winfo exists $m]} {
363 $m delete 0 end
364 } else {
365 menu $m -tearoff 0
368 for {set i [expr {[llength $history] - 2}]
369 } {$i >= 0} {incr i -1} {
370 set e [lindex $history $i]
371 set c [lindex $e 0]
372 set f [lindex $e 1]
374 if {[regexp {^[0-9a-f]{40}$} $c]} {
375 set t [string range $c 0 8]...
376 } elseif {$c eq {}} {
377 set t {Working Directory}
378 } else {
379 set t $c
381 if {![catch {set summary $header($c,summary)}]} {
382 append t " $summary"
383 if {[string length $t] > 70} {
384 set t [string range $t 0 66]...
388 $m add command -label $t -command [cb _goback $i $c $f]
390 set X [winfo rootx $w_back]
391 set Y [expr {[winfo rooty $w_back] + [winfo height $w_back]}]
392 tk_popup $m $X $Y
395 method _goback {i c f} {
396 set history [lrange $history 0 [expr {$i - 1}]]
397 set commit $c
398 set path $f
399 _load $this
402 method _read_file {fd} {
403 if {$fd ne $current_fd} {
404 catch {close $fd}
405 return
408 foreach i $w_columns {$i conf -state normal}
409 while {[gets $fd line] >= 0} {
410 regsub "\r\$" $line {} line
411 incr total_lines
412 lappend amov_data {}
414 if {$total_lines > 1} {
415 foreach i $w_columns {$i insert end "\n"}
418 $w_line insert end "$total_lines" linenumber
419 $w_file insert end "$line"
422 set ln_wc [expr {[string length $total_lines] + 2}]
423 if {[$w_line cget -width] < $ln_wc} {
424 $w_line conf -width $ln_wc
427 foreach i $w_columns {$i conf -state disabled}
429 if {[eof $fd]} {
430 close $fd
432 _status $this
433 set cmd {nice git blame -M -C --incremental}
434 if {$commit eq {}} {
435 lappend cmd --contents $path
436 } else {
437 lappend cmd $commit
439 lappend cmd -- $path
440 set fd [open "| $cmd" r]
441 fconfigure $fd -blocking 0 -translation lf -encoding binary
442 fileevent $fd readable [cb _read_blame $fd]
443 set current_fd $fd
445 } ifdeleted { catch {close $fd} }
447 method _read_blame {fd} {
448 if {$fd ne $current_fd} {
449 catch {close $fd}
450 return
453 $w_amov conf -state normal
454 while {[gets $fd line] >= 0} {
455 if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
456 cmit original_line final_line line_count]} {
457 set r_commit $cmit
458 set r_orig_line $original_line
459 set r_final_line $final_line
460 set r_line_count $line_count
462 if {[catch {set g $have_commit($cmit)}]} {
463 set bg [lindex $group_colors 0]
464 set group_colors [lrange $group_colors 1 end]
465 lappend group_colors $bg
466 foreach i $w_columns {
467 $i tag conf g$cmit -background $bg
469 set have_commit($cmit) 1
471 } elseif {[string match {filename *} $line]} {
472 set file [string range $line 9 end]
473 set n $r_line_count
474 set lno $r_final_line
475 set cmit $r_commit
477 if {[regexp {^0{40}$} $cmit]} {
478 set commit_abbr work
479 set commit_type curr_commit
480 } elseif {$cmit eq $commit} {
481 set commit_abbr this
482 set commit_type curr_commit
483 } else {
484 set commit_type prior_commit
485 set commit_abbr [string range $cmit 0 4]
488 set author_abbr {}
489 set a_name {}
490 catch {set a_name $header($cmit,author)}
491 while {$a_name ne {}} {
492 if {![regexp {^([[:upper:]])} $a_name _a]} break
493 append author_abbr $_a
494 unset _a
495 if {![regsub \
496 {^[[:upper:]][^\s]*\s+} \
497 $a_name {} a_name ]} break
499 if {$author_abbr eq {}} {
500 set author_abbr { |}
501 } else {
502 set author_abbr [string range $author_abbr 0 3]
503 while {[string length $author_abbr] < 4} {
504 set author_abbr " $author_abbr"
507 unset a_name
509 set first_lno $lno
510 while {
511 $first_lno > 1
512 && $cmit eq [lindex $amov_data [expr {$first_lno - 1}] 0]
513 && $file eq [lindex $amov_data [expr {$first_lno - 1}] 1]
515 incr first_lno -1
518 while {$n > 0} {
519 set lno_e "$lno.0 lineend + 1c"
520 if {[lindex $amov_data $lno] ne {}} {
521 set g [lindex $amov_data $lno 0]
522 foreach i $w_columns {
523 $i tag remove g$g $lno.0 $lno_e
526 lset amov_data $lno [list $cmit $file]
528 $w_amov delete $lno.0 "$lno.0 lineend"
529 if {$lno == $first_lno} {
530 $w_amov insert $lno.0 $commit_abbr $commit_type
531 } elseif {$lno == [expr {$first_lno + 1}]} {
532 $w_amov insert $lno.0 $author_abbr
533 } else {
534 $w_amov insert $lno.0 { |}
537 foreach i $w_columns {
538 $i tag add g$cmit $lno.0 $lno_e
541 if {$highlight_line == -1} {
542 if {[lindex [$w_file yview] 0] == 0} {
543 $w_file see $lno.0
544 _showcommit $this $lno
546 } elseif {$highlight_line == $lno} {
547 _showcommit $this $lno
550 incr n -1
551 incr lno
552 incr blame_lines
555 while {
556 $cmit eq [lindex $amov_data $lno 0]
557 && $file eq [lindex $amov_data $lno 1]
559 $w_amov delete $lno.0 "$lno.0 lineend"
561 if {$lno == $first_lno} {
562 $w_amov insert $lno.0 $commit_abbr $commit_type
563 } elseif {$lno == [expr {$first_lno + 1}]} {
564 $w_amov insert $lno.0 $author_abbr
565 } else {
566 $w_amov insert $lno.0 { |}
568 incr lno
571 } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
572 set header($r_commit,$key) $data
575 $w_amov conf -state disabled
577 if {[eof $fd]} {
578 close $fd
579 set current_fd {}
580 set status {Annotation complete.}
581 destroy $w.status.c
582 } else {
583 _status $this
585 } ifdeleted { catch {close $fd} }
587 method _status {} {
588 set have $blame_lines
589 set total $total_lines
590 set pdone 0
591 if {$total} {set pdone [expr {100 * $have / $total}]}
593 set status [format \
594 "Loading annotations... %i of %i lines annotated (%2i%%)" \
595 $have $total $pdone]
596 $w.status.c coords bar 0 0 $pdone 20
599 method _click {cur_w pos} {
600 set lno [lindex [split [$cur_w index $pos] .] 0]
601 if {$lno eq {}} return
602 _showcommit $this $lno
605 method _load_commit {pos} {
606 set lno [lindex [split [$w_amov index $pos] .] 0]
607 set dat [lindex $amov_data $lno]
608 if {$dat ne {}} {
609 set commit [lindex $dat 0]
610 set path [lindex $dat 1]
611 _load $this
615 method _showcommit {lno} {
616 global repo_config
618 if {$highlight_commit ne {}} {
619 foreach i $w_columns {
620 $i tag conf g$highlight_commit -background $old_bgcolor
624 $w_cviewer conf -state normal
625 $w_cviewer delete 0.0 end
627 set dat [lindex $amov_data $lno]
628 if {$dat eq {}} {
629 set cmit {}
630 $w_cviewer insert end "Loading annotation..." still_loading
631 } else {
632 set cmit [lindex $dat 0]
633 set file [lindex $dat 1]
635 set old_bgcolor [$w_file tag cget g$cmit -background]
636 foreach i $w_columns {
637 $i tag conf g$cmit -background $active_color
640 set author_name {}
641 set author_email {}
642 set author_time {}
643 catch {set author_name $header($cmit,author)}
644 catch {set author_email $header($cmit,author-mail)}
645 catch {set author_time [clock format \
646 $header($cmit,author-time) \
647 -format {%Y-%m-%d %H:%M:%S}
650 set committer_name {}
651 set committer_email {}
652 set committer_time {}
653 catch {set committer_name $header($cmit,committer)}
654 catch {set committer_email $header($cmit,committer-mail)}
655 catch {set committer_time [clock format \
656 $header($cmit,committer-time) \
657 -format {%Y-%m-%d %H:%M:%S}
660 if {[catch {set msg $header($cmit,message)}]} {
661 set msg {}
662 catch {
663 set fd [open "| git cat-file commit $cmit" r]
664 fconfigure $fd -encoding binary -translation lf
665 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
666 set enc utf-8
668 while {[gets $fd line] > 0} {
669 if {[string match {encoding *} $line]} {
670 set enc [string tolower [string range $line 9 end]]
673 set msg [encoding convertfrom $enc [read $fd]]
674 set msg [string trim $msg]
675 close $fd
677 set author_name [encoding convertfrom $enc $author_name]
678 set committer_name [encoding convertfrom $enc $committer_name]
680 set header($cmit,author) $author_name
681 set header($cmit,committer) $committer_name
683 set header($cmit,message) $msg
686 $w_cviewer insert end "commit $cmit\n" header_key
687 $w_cviewer insert end "Author:\t" header_key
688 $w_cviewer insert end "$author_name $author_email" header_val
689 $w_cviewer insert end " $author_time\n" header_val
691 $w_cviewer insert end "Committer:\t" header_key
692 $w_cviewer insert end "$committer_name $committer_email" header_val
693 $w_cviewer insert end " $committer_time\n" header_val
695 if {$file ne $path} {
696 $w_cviewer insert end "Original File:\t" header_key
697 $w_cviewer insert end "[escape_path $file]\n" header_val
700 $w_cviewer insert end "\n$msg"
702 $w_cviewer conf -state disabled
704 set highlight_line $lno
705 set highlight_commit $cmit
707 if {$highlight_commit eq $tooltip_commit} {
708 _hide_tooltip $this
712 method _copycommit {} {
713 set pos @$::cursorX,$::cursorY
714 set lno [lindex [split [$::cursorW index $pos] .] 0]
715 set dat [lindex $amov_data $lno]
716 if {$dat ne {}} {
717 clipboard clear
718 clipboard append \
719 -format STRING \
720 -type STRING \
721 -- [lindex $dat 0]
725 method _show_tooltip {cur_w pos} {
726 set lno [lindex [split [$cur_w index $pos] .] 0]
727 set dat [lindex $amov_data $lno]
728 if {$dat eq {}} {
729 _hide_tooltip $this
730 return
732 set cmit [lindex $dat 0]
734 if {$cmit eq $highlight_commit} {
735 _hide_tooltip $this
736 return
739 if {$cmit eq $tooltip_commit} {
740 _position_tooltip $this
741 } elseif {$tooltip_wm ne {}} {
742 _open_tooltip $this $cur_w
743 } elseif {$tooltip_timer eq {}} {
744 set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
748 method _open_tooltip {cur_w} {
749 set tooltip_timer {}
750 set pos_x [winfo pointerx $cur_w]
751 set pos_y [winfo pointery $cur_w]
752 if {[winfo containing $pos_x $pos_y] ne $cur_w} {
753 _hide_tooltip $this
754 return
757 set pos @[join [list \
758 [expr {$pos_x - [winfo rootx $cur_w]}] \
759 [expr {$pos_y - [winfo rooty $cur_w]}]] ,]
760 set lno [lindex [split [$cur_w index $pos] .] 0]
761 set dat [lindex $amov_data $lno]
762 set cmit [lindex $dat 0]
763 set file [lindex $dat 1]
765 set author_name {}
766 set author_email {}
767 set author_time {}
768 catch {set author_name $header($cmit,author)}
769 catch {set author_email $header($cmit,author-mail)}
770 catch {set author_time [clock format \
771 $header($cmit,author-time) \
772 -format {%Y-%m-%d %H:%M:%S}
775 set committer_name {}
776 set committer_email {}
777 set committer_time {}
778 catch {set committer_name $header($cmit,committer)}
779 catch {set committer_email $header($cmit,committer-mail)}
780 catch {set committer_time [clock format \
781 $header($cmit,committer-time) \
782 -format {%Y-%m-%d %H:%M:%S}
785 set summary {}
786 catch {set summary $header($cmit,summary)}
788 set tooltip_commit $cmit
789 set tooltip_text "commit $cmit
790 $author_name $author_email $author_time
791 $summary"
793 if {$file ne $path} {
794 append tooltip_text "
796 Original File: $file"
799 if {$tooltip_wm ne "$cur_w.tooltip"} {
800 _hide_tooltip $this
802 set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
803 wm overrideredirect $tooltip_wm 1
804 wm transient $tooltip_wm [winfo toplevel $cur_w]
805 pack [label $tooltip_wm.label \
806 -background lightyellow \
807 -foreground black \
808 -textvariable @tooltip_text \
809 -justify left]
811 _position_tooltip $this
814 method _position_tooltip {} {
815 set req_w [winfo reqwidth $tooltip_wm.label]
816 set req_h [winfo reqheight $tooltip_wm.label]
817 set pos_x [expr {[winfo pointerx .] + 5}]
818 set pos_y [expr {[winfo pointery .] + 10}]
820 set g "${req_w}x${req_h}"
821 if {$pos_x >= 0} {append g +}
822 append g $pos_x
823 if {$pos_y >= 0} {append g +}
824 append g $pos_y
826 wm geometry $tooltip_wm $g
827 raise $tooltip_wm
830 method _hide_tooltip {} {
831 if {$tooltip_wm ne {}} {
832 destroy $tooltip_wm
833 set tooltip_wm {}
834 set tooltip_commit {}
836 if {$tooltip_timer ne {}} {
837 after cancel $tooltip_timer
838 set tooltip_timer {}
842 method _resize {new_height} {
843 set diff [expr {$new_height - $old_height}]
844 if {$diff == 0} return
846 set my [expr {[winfo height $w.file_pane] - 25}]
847 set o [$w.file_pane sash coord 0]
848 set ox [lindex $o 0]
849 set oy [expr {[lindex $o 1] + $diff}]
850 if {$oy < 0} {set oy 0}
851 if {$oy > $my} {set oy $my}
852 $w.file_pane sash place 0 $ox $oy
854 set old_height $new_height