@matheusbsbs / matheus-bagliano / commits / 97645683bf
Fork 0

gitk: Fix some problems with the display of ids as links

First, this fixes the problem where a SHA1 id wouldn't be displayed as a link if it wasn't in the part of the graph that had been laid out at the time the details pane was filled in, even if that commit later became part of the graph. This arranges for us to turn the SHA1 id into a link when we get to that id in laying out the graph. Secondly, there was a problem where the cursor wouldn't always turn to a hand when over a link, because the areas for two links could overlap slightly. This fixes that by using a counter rather than always reverting to a counter when we leave the region of a link (which can happen just after we've entered a different link). Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Aug 23, 2007 at 22:24 UTC 97645683bff498e369c1c24ce10e78b51cdaf468
1 file changed +55 -32
gitk
+55 -32
@@ -1959,7 +1959,7 @@ proc showview {n} {
1959 global commfd
1960 global selectedview selectfirst
1961 global vparentlist vdisporder vcmitlisted
1962 - global hlview selectedhlview
1962 + global hlview selectedhlview commitinterest
1963
1964 if {$n == $curview} return
1965 set selid {}
@@ -2000,6 +2000,7 @@ proc showview {n} {
2000 unset hlview
2001 set selectedhlview None
2002 }
2003 + catch {unset commitinterest}
2004
2005 set curview $n
2006 set selectedview $n
@@ -4322,7 +4323,7 @@ proc commit_descriptor {p} {
4323 # append some text to the ctext widget, and make any SHA1 ID
4324 # that we know about be a clickable link.
4325 proc appendwithlinks {text tags} {
4325 - global ctext commitrow linknum curview
4326 + global ctext commitrow linknum curview pendinglinks
4327
4328 set start [$ctext index "end - 1c"]
4329 $ctext insert end $text $tags
@@ -4331,17 +4332,48 @@ proc appendwithlinks {text tags} {
4332 set s [lindex $l 0]
4333 set e [lindex $l 1]
4334 set linkid [string range $text $s $e]
4334 - if {![info exists commitrow($curview,$linkid)]} continue
4335 incr e
4336 - $ctext tag add link "$start + $s c" "$start + $e c"
4336 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
4338 - $ctext tag bind link$linknum <1> \
4339 - [list selectline $commitrow($curview,$linkid) 1]
4337 + setlink $linkid link$linknum
4338 incr linknum
4339 }
4342 - $ctext tag conf link -foreground blue -underline 1
4343 - $ctext tag bind link <Enter> { %W configure -cursor hand2 }
4344 - $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
4340 +}
4341 +
4342 +proc setlink {id lk} {
4343 + global curview commitrow ctext pendinglinks commitinterest
4344 +
4345 + if {[info exists commitrow($curview,$id)]} {
4346 + $ctext tag conf $lk -foreground blue -underline 1
4347 + $ctext tag bind $lk <1> [list selectline $commitrow($curview,$id) 1]
4348 + $ctext tag bind $lk <Enter> {linkcursor %W 1}
4349 + $ctext tag bind $lk <Leave> {linkcursor %W -1}
4350 + } else {
4351 + lappend pendinglinks($id) $lk
4352 + lappend commitinterest($id) {makelink %I}
4353 + }
4354 +}
4355 +
4356 +proc makelink {id} {
4357 + global pendinglinks
4358 +
4359 + if {![info exists pendinglinks($id)]} return
4360 + foreach lk $pendinglinks($id) {
4361 + setlink $id $lk
4362 + }
4363 + unset pendinglinks($id)
4364 +}
4365 +
4366 +proc linkcursor {w inc} {
4367 + global linkentercount curtextcursor
4368 +
4369 + if {[incr linkentercount $inc] > 0} {
4370 + $w configure -cursor hand2
4371 + } else {
4372 + $w configure -cursor $curtextcursor
4373 + if {$linkentercount < 0} {
4374 + set linkentercount 0
4375 + }
4376 + }
4377 }
4378
4379 proc viewnextline {dir} {
@@ -4388,15 +4420,7 @@ proc appendrefs {pos ids var} {
4420 $ctext tag delete $lk
4421 $ctext insert $pos $sep
4422 $ctext insert $pos [lindex $ti 0] $lk
4391 - if {[info exists commitrow($curview,$id)]} {
4392 - $ctext tag conf $lk -foreground blue
4393 - $ctext tag bind $lk <1> \
4394 - [list selectline $commitrow($curview,$id) 1]
4395 - $ctext tag conf $lk -underline 1
4396 - $ctext tag bind $lk <Enter> { %W configure -cursor hand2 }
4397 - $ctext tag bind $lk <Leave> \
4398 - { %W configure -cursor $curtextcursor }
4399 - }
4423 + setlink $id $lk
4424 set sep ", "
4425 }
4426 }
@@ -5237,6 +5261,7 @@ proc nextfile {} {
5261
5262 proc clear_ctext {{first 1.0}} {
5263 global ctext smarktop smarkbot
5264 + global pendinglinks
5265
5266 set l [lindex [split $first .] 0]
5267 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
@@ -5246,6 +5271,9 @@ proc clear_ctext {{first 1.0}} {
5271 set smarkbot $l
5272 }
5273 $ctext delete $first end
5274 + if {$first eq "1.0"} {
5275 + catch {unset pendinglinks}
5276 + }
5277 }
5278
5279 proc incrsearch {name ix op} {
@@ -5609,12 +5637,9 @@ proc lineclick {x y id isnew} {
5637 # fill the details pane with info about this line
5638 $ctext conf -state normal
5639 clear_ctext
5612 - $ctext tag conf link -foreground blue -underline 1
5613 - $ctext tag bind link <Enter> { %W configure -cursor hand2 }
5614 - $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
5640 $ctext insert end "Parent:\t"
5616 - $ctext insert end $id [list link link0]
5617 - $ctext tag bind link0 <1> [list selbyid $id]
5641 + $ctext insert end $id link0
5642 + setlink $id link0
5643 set info $commitinfo($id)
5644 $ctext insert end "\n\t[lindex $info 0]\n"
5645 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
@@ -5629,8 +5654,8 @@ proc lineclick {x y id isnew} {
5654 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
5655 set info $commitinfo($child)
5656 $ctext insert end "\n\t"
5632 - $ctext insert end $child [list link link$i]
5633 - $ctext tag bind link$i <1> [list selbyid $child]
5657 + $ctext insert end $child link$i
5658 + setlink $child link$i
5659 $ctext insert end "\n\t[lindex $info 0]"
5660 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
5661 set date [formatdate [lindex $info 2]]
@@ -5711,16 +5736,13 @@ proc doseldiff {oldid newid} {
5736 clear_ctext
5737 init_flist "Top"
5738 $ctext insert end "From "
5714 - $ctext tag conf link -foreground blue -underline 1
5715 - $ctext tag bind link <Enter> { %W configure -cursor hand2 }
5716 - $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
5717 - $ctext tag bind link0 <1> [list selbyid $oldid]
5718 - $ctext insert end $oldid [list link link0]
5739 + $ctext insert end $oldid link0
5740 + setlink $oldid link0
5741 $ctext insert end "\n "
5742 $ctext insert end [lindex $commitinfo($oldid) 0]
5743 $ctext insert end "\n\nTo "
5722 - $ctext tag bind link1 <1> [list selbyid $newid]
5723 - $ctext insert end $newid [list link link1]
5744 + $ctext insert end $newid link1
5745 + setlink $newid link1
5746 $ctext insert end "\n "
5747 $ctext insert end [lindex $commitinfo($newid) 0]
5748 $ctext insert end "\n"
@@ -7892,6 +7914,7 @@ set boldrows {}
7914 set boldnamerows {}
7915 set diffelide {0 0}
7916 set markingmatches 0
7917 +set linkentercount 0
7918
7919 set optim_delay 16
7920