Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4399fe3

Browse files
committed
gitk: Tag display improvements
When a commit has many tags, the tag icons in the graph display can easily become so wide as to push the commit message off the right-hand edge of the graph display pane. This changes the display so that if there are more than 3 tags or they would take up more than a quarter of the width of the pane, we instead display a single tag icon with a legend inside it like "4 tags...". If the user clicks on the tag icon, gitk then displays all the tags in the diff display pane. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 9aa66a0 commit 4399fe3

File tree

1 file changed

+83
-13
lines changed

1 file changed

+83
-13
lines changed

gitk

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,7 @@ proc makewindow {} {
23852385
$ctext tag conf found -back $foundbgcolor
23862386
$ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
23872387
$ctext tag conf wwrap -wrap word
2388+
$ctext tag conf bold -font textfontbold
23882389

23892390
.pwbottom add .bleft
23902391
if {!$use_ttk} {
@@ -6387,6 +6388,25 @@ proc bindline {t id} {
63876388
$canv bind $t <Button-1> "lineclick %x %y $id 1"
63886389
}
63896390

6391+
proc graph_pane_width {} {
6392+
global use_ttk
6393+
6394+
if {$use_ttk} {
6395+
set g [.tf.histframe.pwclist sashpos 0]
6396+
} else {
6397+
set g [.tf.histframe.pwclist sash coord 0]
6398+
}
6399+
return [lindex $g 0]
6400+
}
6401+
6402+
proc totalwidth {l font extra} {
6403+
set tot 0
6404+
foreach str $l {
6405+
set tot [expr {$tot + [font measure $font $str] + $extra}]
6406+
}
6407+
return $tot
6408+
}
6409+
63906410
proc drawtags {id x xt y1} {
63916411
global idtags idheads idotherrefs mainhead
63926412
global linespc lthickness
@@ -6398,9 +6418,27 @@ proc drawtags {id x xt y1} {
63986418
set marks {}
63996419
set ntags 0
64006420
set nheads 0
6421+
set singletag 0
6422+
set maxtags 3
6423+
set maxtagpct 25
6424+
set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6425+
set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6426+
set extra [expr {$delta + $lthickness + $linespc}]
6427+
64016428
if {[info exists idtags($id)]} {
64026429
set marks $idtags($id)
64036430
set ntags [llength $marks]
6431+
if {$ntags > $maxtags ||
6432+
[totalwidth $marks mainfont $extra] > $maxwidth} {
6433+
# show just a single "n tags..." tag
6434+
set singletag 1
6435+
if {$ntags == 1} {
6436+
set marks [list "tag..."]
6437+
} else {
6438+
set marks [list [format "%d tags..." $ntags]]
6439+
}
6440+
set ntags 1
6441+
}
64046442
}
64056443
if {[info exists idheads($id)]} {
64066444
set marks [concat $marks $idheads($id)]
@@ -6413,7 +6451,6 @@ proc drawtags {id x xt y1} {
64136451
return $xt
64146452
}
64156453

6416-
set delta [expr {int(0.5 * ($linespc - $lthickness))}]
64176454
set yt [expr {$y1 - 0.5 * $linespc}]
64186455
set yb [expr {$yt + $linespc - 1}]
64196456
set xvals {}
@@ -6428,7 +6465,7 @@ proc drawtags {id x xt y1} {
64286465
}
64296466
lappend xvals $xt
64306467
lappend wvals $wid
6431-
set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6468+
set xt [expr {$xt + $wid + $extra}]
64326469
}
64336470
set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
64346471
-width $lthickness -fill $reflinecolor -tags tag.$id]
@@ -6444,7 +6481,12 @@ proc drawtags {id x xt y1} {
64446481
$xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
64456482
-width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
64466483
-tags tag.$id]
6447-
$canv bind $t <1> [list showtag $tag_quoted 1]
6484+
if {$singletag} {
6485+
set tagclick [list showtags $id 1]
6486+
} else {
6487+
set tagclick [list showtag $tag_quoted 1]
6488+
}
6489+
$canv bind $t <1> $tagclick
64486490
set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
64496491
} else {
64506492
# draw a head or other ref
@@ -6471,7 +6513,7 @@ proc drawtags {id x xt y1} {
64716513
set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
64726514
-font $font -tags [list tag.$id text]]
64736515
if {$ntags >= 0} {
6474-
$canv bind $t <1> [list showtag $tag_quoted 1]
6516+
$canv bind $t <1> $tagclick
64756517
} elseif {$nheads >= 0} {
64766518
$canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
64776519
}
@@ -10878,6 +10920,23 @@ proc listrefs {id} {
1087810920
return [list $x $y $z]
1087910921
}
1088010922

10923+
proc add_tag_ctext {tag} {
10924+
global ctext cached_tagcontent tagids
10925+
10926+
if {![info exists cached_tagcontent($tag)]} {
10927+
catch {
10928+
set cached_tagcontent($tag) [exec git cat-file -p $tag]
10929+
}
10930+
}
10931+
$ctext insert end "[mc "Tag"]: $tag\n" bold
10932+
if {[info exists cached_tagcontent($tag)]} {
10933+
set text $cached_tagcontent($tag)
10934+
} else {
10935+
set text "[mc "Id"]: $tagids($tag)"
10936+
}
10937+
appendwithlinks $text {}
10938+
}
10939+
1088110940
proc showtag {tag isnew} {
1088210941
global ctext cached_tagcontent tagids linknum tagobjid
1088310942

@@ -10888,17 +10947,28 @@ proc showtag {tag isnew} {
1088810947
clear_ctext
1088910948
settabs 0
1089010949
set linknum 0
10891-
if {![info exists cached_tagcontent($tag)]} {
10892-
catch {
10893-
set cached_tagcontent($tag) [exec git cat-file -p $tag]
10894-
}
10950+
add_tag_ctext $tag
10951+
maybe_scroll_ctext 1
10952+
$ctext conf -state disabled
10953+
init_flist {}
10954+
}
10955+
10956+
proc showtags {id isnew} {
10957+
global idtags ctext linknum
10958+
10959+
if {$isnew} {
10960+
addtohistory [list showtags $id 0] savectextpos
1089510961
}
10896-
if {[info exists cached_tagcontent($tag)]} {
10897-
set text $cached_tagcontent($tag)
10898-
} else {
10899-
set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10962+
$ctext conf -state normal
10963+
clear_ctext
10964+
settabs 0
10965+
set linknum 0
10966+
set sep {}
10967+
foreach tag $idtags($id) {
10968+
$ctext insert end $sep
10969+
add_tag_ctext $tag
10970+
set sep "\n\n"
1090010971
}
10901-
appendwithlinks $text {}
1090210972
maybe_scroll_ctext 1
1090310973
$ctext conf -state disabled
1090410974
init_flist {}

0 commit comments

Comments
 (0)