Skip to content

Commit d698206

Browse files
committed
Add forward and back buttons and make SHA1 IDs clickable links.
When we display the commit message in the details pane, any string of 40 [0-9a-f] characters that corresponds to a SHA1 ID that we know about gets turned into a clickable link, and displayed in blue and underlined. We now keep a history of commits that we have looked at, and we have forward and back buttons for moving within the history list.
1 parent 8d858d1 commit d698206

File tree

1 file changed

+99
-10
lines changed

1 file changed

+99
-10
lines changed

gitk

Lines changed: 99 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,30 @@ proc makewindow {} {
339339
entry $sha1entry -width 40 -font $textfont -textvariable sha1string
340340
trace add variable sha1string write sha1change
341341
pack $sha1entry -side left -pady 2
342+
343+
image create bitmap bm-left -data {
344+
#define left_width 16
345+
#define left_height 16
346+
static unsigned char left_bits[] = {
347+
0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
348+
0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
349+
0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
350+
}
351+
image create bitmap bm-right -data {
352+
#define right_width 16
353+
#define right_height 16
354+
static unsigned char right_bits[] = {
355+
0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
356+
0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
357+
0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
358+
}
359+
button .ctop.top.bar.leftbut -image bm-left -command goback \
360+
-state disabled -width 26
361+
pack .ctop.top.bar.leftbut -side left -fill y
362+
button .ctop.top.bar.rightbut -image bm-right -command goforw \
363+
-state disabled -width 26
364+
pack .ctop.top.bar.rightbut -side left -fill y
365+
342366
button .ctop.top.bar.findbut -text "Find" -command dofind
343367
pack .ctop.top.bar.findbut -side left
344368
set findstring {}
@@ -1175,7 +1199,7 @@ proc drawrest {level startix} {
11751199
#puts "overall $drawmsecs ms for $numcommits commits"
11761200
if {$redisplaying} {
11771201
if {$stopped == 0 && [info exists selectedline]} {
1178-
selectline $selectedline
1202+
selectline $selectedline 0
11791203
}
11801204
if {$stopped == 1} {
11811205
set stopped 0
@@ -1274,7 +1298,7 @@ proc dofind {} {
12741298

12751299
proc findselectline {l} {
12761300
global findloc commentend ctext
1277-
selectline $l
1301+
selectline $l 1
12781302
if {$findloc == "All fields" || $findloc == "Comments"} {
12791303
# highlight the matches in the comments
12801304
set f [$ctext get 1.0 $commentend]
@@ -1665,15 +1689,17 @@ proc selcanvline {w x y} {
16651689
if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
16661690
}
16671691
unmarkmatches
1668-
selectline $l
1692+
selectline $l 1
16691693
}
16701694

1671-
proc selectline {l} {
1695+
proc selectline {l isnew} {
16721696
global canv canv2 canv3 ctext commitinfo selectedline
16731697
global lineid linehtag linentag linedtag
16741698
global canvy0 linespc parents nparents
16751699
global cflist currentid sha1entry
1676-
global commentend idtags
1700+
global commentend idtags idline
1701+
global history historyindex
1702+
16771703
$canv delete hover
16781704
if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
16791705
$canv delete secsel
@@ -1722,6 +1748,22 @@ proc selectline {l} {
17221748
}
17231749
allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
17241750
}
1751+
1752+
if {$isnew && (![info exists selectedline] || $selectedline != $l)} {
1753+
if {$historyindex < [llength $history]} {
1754+
set history [lreplace $history $historyindex end $l]
1755+
} else {
1756+
lappend history $l
1757+
}
1758+
incr historyindex
1759+
if {$historyindex > 1} {
1760+
.ctop.top.bar.leftbut conf -state normal
1761+
} else {
1762+
.ctop.top.bar.leftbut conf -state disabled
1763+
}
1764+
.ctop.top.bar.rightbut conf -state disabled
1765+
}
1766+
17251767
set selectedline $l
17261768

17271769
set id $lineid($l)
@@ -1746,8 +1788,25 @@ proc selectline {l} {
17461788
$ctext insert end "\n"
17471789
}
17481790
$ctext insert end "\n"
1749-
$ctext insert end [lindex $info 5]
1791+
set commentstart [$ctext index "end - 1c"]
1792+
set comment [lindex $info 5]
1793+
$ctext insert end $comment
17501794
$ctext insert end "\n"
1795+
1796+
# make anything that looks like a SHA1 ID be a clickable link
1797+
set links [regexp -indices -all -inline {[0-9a-f]{40}} $comment]
1798+
set i 0
1799+
foreach l $links {
1800+
set s [lindex $l 0]
1801+
set e [lindex $l 1]
1802+
set linkid [string range $comment $s $e]
1803+
if {![info exists idline($linkid)]} continue
1804+
incr e
1805+
$ctext tag conf link$i -foreground blue -underline 1
1806+
$ctext tag add link$i "$commentstart + $s c" "$commentstart + $e c"
1807+
$ctext tag bind link$i <1> [list selectline $idline($linkid) 1]
1808+
}
1809+
17511810
$ctext tag delete Comments
17521811
$ctext tag remove found 1.0 end
17531812
$ctext conf -state disabled
@@ -1767,7 +1826,34 @@ proc selnextline {dir} {
17671826
if {![info exists selectedline]} return
17681827
set l [expr $selectedline + $dir]
17691828
unmarkmatches
1770-
selectline $l
1829+
selectline $l 1
1830+
}
1831+
1832+
proc goback {} {
1833+
global history historyindex
1834+
1835+
if {$historyindex > 1} {
1836+
incr historyindex -1
1837+
selectline [lindex $history [expr {$historyindex - 1}]] 0
1838+
.ctop.top.bar.rightbut conf -state normal
1839+
}
1840+
if {$historyindex <= 1} {
1841+
.ctop.top.bar.leftbut conf -state disabled
1842+
}
1843+
}
1844+
1845+
proc goforw {} {
1846+
global history historyindex
1847+
1848+
if {$historyindex < [llength $history]} {
1849+
set l [lindex $history $historyindex]
1850+
incr historyindex
1851+
selectline $l 0
1852+
.ctop.top.bar.leftbut conf -state normal
1853+
}
1854+
if {$historyindex >= [llength $history]} {
1855+
.ctop.top.bar.rightbut conf -state disabled
1856+
}
17711857
}
17721858

17731859
proc mergediff {id} {
@@ -2590,7 +2676,7 @@ proc gotocommit {} {
25902676
}
25912677
}
25922678
if {[info exists idline($id)]} {
2593-
selectline $idline($id)
2679+
selectline $idline($id) 1
25942680
return
25952681
}
25962682
if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
@@ -2702,7 +2788,7 @@ proc lineclick {x y id} {
27022788
proc selbyid {id} {
27032789
global idline
27042790
if {[info exists idline($id)]} {
2705-
selectline $idline($id)
2791+
selectline $idline($id) 1
27062792
}
27072793
}
27082794

@@ -2906,7 +2992,7 @@ proc domktag {} {
29062992
set xt [eval drawtags $id $idpos($id)]
29072993
$canv coords $linehtag($idline($id)) $xt [lindex $idpos($id) 2]
29082994
if {[info exists selectedline] && $selectedline == $idline($id)} {
2909-
selectline $selectedline
2995+
selectline $selectedline 0
29102996
}
29112997
}
29122998

@@ -3016,6 +3102,9 @@ foreach arg $argv {
30163102
}
30173103
}
30183104

3105+
set history {}
3106+
set historyindex 0
3107+
30193108
set stopped 0
30203109
set redisplaying 0
30213110
set stuffsaved 0

0 commit comments

Comments
 (0)