git-gui: Display tooltips in blame viewer
When the mouse is over a particular line and we have blame data for that line, but its not the active commit, we should show the user information about that commit like who the author was and what the subject (first line) was. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jun 1, 2007 at 03:01 UTC
41bf23d6cc58c229e5e966a98c1b2c9cd06e95f7
1 file changed
+125
-1
lib/blame.tcl
+125
-1
@@ -31,6 +31,11 @@ field r_orig_line ; # original line number
31
field r_final_line ; # final line number
32
field r_line_count ; # lines in this region
33
34
+field tooltip_wm {} ; # Current tooltip toplevel, if open
35
+field tooltip_timer {} ; # Current timer event for our tooltip
36
+field tooltip_commit {} ; # Commit in tooltip
37
+field tooltip_text {} ; # Text in current tooltip
38
+
39
variable active_color #98e1a0
40
variable group_colors {
41
#cbcbcb
@@ -159,8 +164,16 @@ constructor new {i_commit i_path} {
164
$w_line \
165
$w_file \
166
] yview $w.out.sby]
162
- bind $i <Button-1> "[cb _click $i @%x,%y]; focus $i"
167
+ bind $i <Button-1> "
168
+ [cb _hide_tooltip]
169
+ [cb _click $i @%x,%y]
170
+ focus $i
171
+ "
172
+ bind $i <Any-Motion> [cb _show_tooltip $i @%x,%y]
173
+ bind $i <Any-Enter> [cb _hide_tooltip]
174
+ bind $i <Any-Leave> [cb _hide_tooltip]
175
bind_button3 $i "
176
+ [cb _hide_tooltip]
177
set cursorX %x
178
set cursorY %y
179
set cursorW %W
@@ -447,6 +460,10 @@ $msg"
460
461
set highlight_line $lno
462
set highlight_commit $cmit
463
+
464
+ if {$highlight_commit eq $tooltip_commit} {
465
+ _hide_tooltip $this
466
+ }
467
}
468
469
method _copycommit {} {
@@ -461,4 +478,111 @@ method _copycommit {} {
478
}
479
}
480
481
+method _show_tooltip {cur_w pos} {
482
+ set lno [lindex [split [$cur_w index $pos] .] 0]
483
+ if {[catch {set cmit $line_commit($lno)}]} {
484
+ _hide_tooltip $this
485
+ return
486
+ }
487
+
488
+ if {$cmit eq $highlight_commit} {
489
+ _hide_tooltip $this
490
+ return
491
+ }
492
+
493
+ if {$cmit eq $tooltip_commit} {
494
+ _position_tooltip $this
495
+ } elseif {$tooltip_wm ne {}} {
496
+ _open_tooltip $this $cur_w
497
+ } elseif {$tooltip_timer eq {}} {
498
+ set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
499
+ }
500
+}
501
+
502
+method _open_tooltip {cur_w} {
503
+ set tooltip_timer {}
504
+ set pos_x [winfo pointerx $cur_w]
505
+ set pos_y [winfo pointery $cur_w]
506
+ if {[winfo containing $pos_x $pos_y] ne $cur_w} {
507
+ _hide_tooltip $this
508
+ return
509
+ }
510
+
511
+ set pos @[join [list \
512
+ [expr {$pos_x - [winfo rootx $cur_w]}] \
513
+ [expr {$pos_y - [winfo rooty $cur_w]}]] ,]
514
+ set lno [lindex [split [$cur_w index $pos] .] 0]
515
+ set cmit $line_commit($lno)
516
+
517
+ set author_name {}
518
+ set author_email {}
519
+ set author_time {}
520
+ catch {set author_name $header($cmit,author)}
521
+ catch {set author_email $header($cmit,author-mail)}
522
+ catch {set author_time [clock format \
523
+ $header($cmit,author-time) \
524
+ -format {%Y-%m-%d %H:%M:%S}
525
+ ]}
526
+
527
+ set committer_name {}
528
+ set committer_email {}
529
+ set committer_time {}
530
+ catch {set committer_name $header($cmit,committer)}
531
+ catch {set committer_email $header($cmit,committer-mail)}
532
+ catch {set committer_time [clock format \
533
+ $header($cmit,committer-time) \
534
+ -format {%Y-%m-%d %H:%M:%S}
535
+ ]}
536
+
537
+ set summary {}
538
+ catch {set summary $header($cmit,summary)}
539
+
540
+ set tooltip_commit $cmit
541
+ set tooltip_text "commit $cmit
542
+$author_name $author_email $author_time
543
+$summary"
544
+
545
+ if {$tooltip_wm ne "$cur_w.tooltip"} {
546
+ _hide_tooltip $this
547
+
548
+ set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
549
+ wm overrideredirect $tooltip_wm 1
550
+ wm transient $tooltip_wm [winfo toplevel $cur_w]
551
+ pack [label $tooltip_wm.label \
552
+ -background lightyellow \
553
+ -foreground black \
554
+ -textvariable @tooltip_text \
555
+ -justify left]
556
+ }
557
+ _position_tooltip $this
558
+}
559
+
560
+method _position_tooltip {} {
561
+ set req_w [winfo reqwidth $tooltip_wm.label]
562
+ set req_h [winfo reqheight $tooltip_wm.label]
563
+ set pos_x [expr {[winfo pointerx .] + 5}]
564
+ set pos_y [expr {[winfo pointery .] + 10}]
565
+
566
+ set g "${req_w}x${req_h}"
567
+ if {$pos_x >= 0} {append g +}
568
+ append g $pos_x
569
+ if {$pos_y >= 0} {append g +}
570
+ append g $pos_y
571
+
572
+ wm geometry $tooltip_wm $g
573
+ raise $tooltip_wm
574
+}
575
+
576
+method _hide_tooltip {} {
577
+ if {$tooltip_wm ne {}} {
578
+ destroy $tooltip_wm
579
+ set tooltip_wm {}
580
+ set tooltip_commit {}
581
+ }
582
+ if {$tooltip_timer ne {}} {
583
+ after cancel $tooltip_timer
584
+ set tooltip_timer {}
585
+ }
586
+}
587
+
588
}