@matheusbsbs / matheus-bagliano / commits / 32f1b3e4a4
Fork 0

gitk: Fix the tab setting in the diff display window

This fixes the bug where we were using the wrong font to calculate the width of the tab stops in the diff display window. If we're running on Tk 8.5 we also use the new -tabstyle wordprocessor option that makes tabs work as expected, i.e. a tab moves the cursor to the right until the next tab stop is reached. On Tk 8.5 we also get fancy and set the first tab stop at column 1 for a normal diff or column N for a merge diff with N parents. On Tk8.4 we can't do that because the tabs work in the "tabular" style, i.e. the nth tab character moves to the location of the nth tab position, *unless* you ask for the default tab setting, which gives 8-column tabs that work in the "wordprocessor" mode. So on Tk8.4 if the tab setting is 8 we ask for default tabs. This means that a tab setting of 7 or 9 can look quite different to 8 in some cases. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Sep 28, 2007 at 21:27 UTC 32f1b3e4a4baa3fe3e1acbb75f8134d822a09d58
1 file changed +31 -6
gitk
+31 -6
@@ -626,6 +626,7 @@ proc makewindow {} {
626 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
627 global headctxmenu progresscanv progressitem progresscoords statusw
628 global fprogitem fprogcoord lastprogupdate progupdatepending
629 + global have_tk85
630
631 menu .bar
632 .bar add cascade -label "File" -menu .bar.file
@@ -845,9 +846,11 @@ proc makewindow {} {
846 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
847 set ctext .bleft.ctext
848 text $ctext -background $bgcolor -foreground $fgcolor \
848 - -tabs "[expr {$tabstop * $charspc}]" \
849 -state disabled -font $textfont \
850 -yscrollcommand scrolltext -wrap none
851 + if {$have_tk85} {
852 + $ctext conf -tabstyle wordprocessor
853 + }
854 scrollbar .bleft.sb -command "$ctext yview"
855 pack .bleft.top -side top -fill x
856 pack .bleft.mid -side top -fill x
@@ -1135,7 +1138,7 @@ proc doprogupdate {} {
1138 }
1139
1140 proc savestuff {w} {
1138 - global canv canv2 canv3 ctext cflist mainfont textfont uifont tabstop
1141 + global canv canv2 canv3 mainfont textfont uifont tabstop
1142 global stuffsaved findmergefiles maxgraphpct
1143 global maxwidth showneartags showlocalchanges
1144 global viewname viewfiles viewargs viewperm nextviewnum
@@ -5092,6 +5095,7 @@ proc showfile {f} {
5095 $ctext insert end "$f\n" filesep
5096 $ctext config -state disabled
5097 $ctext yview $commentend
5098 + settabs 0
5099 }
5100
5101 proc getblobline {bf id} {
@@ -5133,6 +5137,7 @@ proc mergediff {id l} {
5137 fconfigure $mdf -blocking 0
5138 set mdifffd($id) $mdf
5139 set np [llength [lindex $parentlist $l]]
5140 + settabs $np
5141 filerun $mdf [list getmergediffline $mdf $id $np]
5142 }
5143
@@ -5210,6 +5215,7 @@ proc getmergediffline {mdf id np} {
5215 proc startdiff {ids} {
5216 global treediffs diffids treepending diffmergeid nullid nullid2
5217
5218 + settabs 1
5219 set diffids $ids
5220 catch {unset diffmergeid}
5221 if {![info exists treediffs($ids)] ||
@@ -5515,6 +5521,23 @@ proc clear_ctext {{first 1.0}} {
5521 }
5522 }
5523
5524 +proc settabs {{firstab {}}} {
5525 + global firsttabstop tabstop textfont ctext have_tk85
5526 +
5527 + if {$firstab ne {} && $have_tk85} {
5528 + set firsttabstop $firstab
5529 + }
5530 + set w [font measure $textfont "0"]
5531 + if {$firsttabstop != 0} {
5532 + $ctext conf -tabs [list [expr {$firsttabstop * $w}] \
5533 + [expr {($firsttabstop + $tabstop) * $w}]]
5534 + } elseif {$have_tk85 || $tabstop != 8} {
5535 + $ctext conf -tabs [expr {$tabstop * $w}]
5536 + } else {
5537 + $ctext conf -tabs {}
5538 + }
5539 +}
5540 +
5541 proc incrsearch {name ix op} {
5542 global ctext searchstring searchdirn
5543
@@ -5666,13 +5689,12 @@ proc redisplay {} {
5689
5690 proc incrfont {inc} {
5691 global mainfont textfont ctext canv phase cflist showrefstop
5669 - global charspc tabstop
5692 global stopped entries
5693 unmarkmatches
5694 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
5695 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
5696 setcoords
5675 - $ctext conf -font $textfont -tabs "[expr {$tabstop * $charspc}]"
5697 + settabs
5698 $cflist conf -font $textfont
5699 $ctext tag conf filesep -font [concat $textfont bold]
5700 foreach e $entries {
@@ -5876,6 +5898,7 @@ proc lineclick {x y id isnew} {
5898 # fill the details pane with info about this line
5899 $ctext conf -state normal
5900 clear_ctext
5901 + settabs 0
5902 $ctext insert end "Parent:\t"
5903 $ctext insert end $id link0
5904 setlink $id link0
@@ -7780,6 +7803,7 @@ proc showtag {tag isnew} {
7803 }
7804 $ctext conf -state normal
7805 clear_ctext
7806 + settabs 0
7807 set linknum 0
7808 if {![info exists tagcontents($tag)]} {
7809 catch {
@@ -7951,11 +7975,10 @@ proc prefscan {} {
7975 proc prefsok {} {
7976 global maxwidth maxgraphpct
7977 global oldprefs prefstop showneartags showlocalchanges
7954 - global charspc ctext tabstop
7978
7979 catch {destroy $prefstop}
7980 unset prefstop
7958 - $ctext configure -tabs "[expr {$tabstop * $charspc}]"
7981 + settabs
7982 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
7983 if {$showlocalchanges} {
7984 doshowlocalchanges
@@ -8360,6 +8383,7 @@ if {$i >= [llength $argv] && $revtreeargs ne {}} {
8383 set nullid "0000000000000000000000000000000000000000"
8384 set nullid2 "0000000000000000000000000000000000000001"
8385
8386 +set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
8387
8388 set runq {}
8389 set history {}
@@ -8376,6 +8400,7 @@ set markingmatches 0
8400 set linkentercount 0
8401 set need_redisplay 0
8402 set nrows_drawn 0
8403 +set firsttabstop 0
8404
8405 set nextviewnum 1
8406 set curview 0