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 <paulus@samba.org>
Paul Mackerras committed
Jan 3, 2013 at 10:10 UTC
4399fe337218ebad0c47e9f4edcd83defbb4733d
1 file changed
+83
-13
gitk
+83
-13
@@ -2385,6 +2385,7 @@ proc makewindow {} {
2385
$ctext tag conf found -back $foundbgcolor
2386
$ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2387
$ctext tag conf wwrap -wrap word
2388
+ $ctext tag conf bold -font textfontbold
2389
2390
.pwbottom add .bleft
2391
if {!$use_ttk} {
@@ -6387,6 +6388,25 @@ proc bindline {t id} {
6388
$canv bind $t <Button-1> "lineclick %x %y $id 1"
6389
}
6390
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
+
6410
proc drawtags {id x xt y1} {
6411
global idtags idheads idotherrefs mainhead
6412
global linespc lthickness
@@ -6398,9 +6418,27 @@ proc drawtags {id x xt y1} {
6418
set marks {}
6419
set ntags 0
6420
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
+
6428
if {[info exists idtags($id)]} {
6429
set marks $idtags($id)
6430
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
+ }
6442
}
6443
if {[info exists idheads($id)]} {
6444
set marks [concat $marks $idheads($id)]
@@ -6413,7 +6451,6 @@ proc drawtags {id x xt y1} {
6451
return $xt
6452
}
6453
6416
- set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6454
set yt [expr {$y1 - 0.5 * $linespc}]
6455
set yb [expr {$yt + $linespc - 1}]
6456
set xvals {}
@@ -6428,7 +6465,7 @@ proc drawtags {id x xt y1} {
6465
}
6466
lappend xvals $xt
6467
lappend wvals $wid
6431
- set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6468
+ set xt [expr {$xt + $wid + $extra}]
6469
}
6470
set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6471
-width $lthickness -fill $reflinecolor -tags tag.$id]
@@ -6444,7 +6481,12 @@ proc drawtags {id x xt y1} {
6481
$xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6482
-width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6483
-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
6490
set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6491
} else {
6492
# draw a head or other ref
@@ -6471,7 +6513,7 @@ proc drawtags {id x xt y1} {
6513
set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6514
-font $font -tags [list tag.$id text]]
6515
if {$ntags >= 0} {
6474
- $canv bind $t <1> [list showtag $tag_quoted 1]
6516
+ $canv bind $t <1> $tagclick
6517
} elseif {$nheads >= 0} {
6518
$canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6519
}
@@ -10878,6 +10920,23 @@ proc listrefs {id} {
10920
return [list $x $y $z]
10921
}
10922
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
+
10940
proc showtag {tag isnew} {
10941
global ctext cached_tagcontent tagids linknum tagobjid
10942
@@ -10888,17 +10947,28 @@ proc showtag {tag isnew} {
10947
clear_ctext
10948
settabs 0
10949
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
10961
}
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"
10971
}
10901
- appendwithlinks $text {}
10972
maybe_scroll_ctext 1
10973
$ctext conf -state disabled
10974
init_flist {}