@matheusbsbs / matheus-bagliano / commits / 7fcceed7a0
Fork 0

gitk: Use a text widget for the file list

This lets us do things like highlighting all the entries for which the corresponding part of the diff is at least partly visible in the commit/patch display window, and in future it will let us display the file list in a hierarchical form rather than as a flat file list. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Apr 27, 2006 at 19:21 UTC 7fcceed7a024f5e2868c123c4ace5b7894ea3423
1 file changed +131 -59
gitk
+131 -59
@@ -481,7 +481,7 @@ proc makewindow {} {
481 set ctext .ctop.cdet.left.ctext
482 text $ctext -bg white -state disabled -font $textfont \
483 -width $geometry(ctextw) -height $geometry(ctexth) \
484 - -yscrollcommand ".ctop.cdet.left.sb set" -wrap none
484 + -yscrollcommand scrolltext -wrap none
485 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
486 pack .ctop.cdet.left.sb -side right -fill y
487 pack $ctext -side left -fill both -expand 1
@@ -515,11 +515,16 @@ proc makewindow {} {
515
516 frame .ctop.cdet.right
517 set cflist .ctop.cdet.right.cfiles
518 - listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \
519 - -yscrollcommand ".ctop.cdet.right.sb set" -font $mainfont
518 + set indent [font measure $mainfont "nn"]
519 + text $cflist -width $geometry(cflistw) -background white -font $mainfont \
520 + -tabs [list $indent [expr {2 * $indent}]] \
521 + -yscrollcommand ".ctop.cdet.right.sb set" \
522 + -cursor [. cget -cursor] \
523 + -spacing1 1 -spacing3 1
524 scrollbar .ctop.cdet.right.sb -command "$cflist yview"
525 pack .ctop.cdet.right.sb -side right -fill y
526 pack $cflist -side left -fill both -expand 1
527 + $cflist tag configure highlight -background yellow
528 .ctop.cdet add .ctop.cdet.right
529 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
530
@@ -571,12 +576,13 @@ proc makewindow {} {
576 bind . <Control-KP_Add> {incrfont 1}
577 bind . <Control-minus> {incrfont -1}
578 bind . <Control-KP_Subtract> {incrfont -1}
574 - bind $cflist <<ListboxSelect>> listboxsel
579 bind . <Destroy> {savestuff %W}
580 bind . <Button-1> "click %W"
581 bind $fstring <Key-Return> dofind
582 bind $sha1entry <Key-Return> gotocommit
583 bind $sha1entry <<PasteSelection>> clearsha1
584 + bind $cflist <1> {sel_flist %W %x %y; break}
585 + bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
586
587 set maincursor [. cget -cursor]
588 set textcursor [$ctext cget -cursor]
@@ -812,6 +818,101 @@ f Scroll diff view to next file
818 pack $w.ok -side bottom
819 }
820
821 +# Procedures for manipulating the file list window at the
822 +# bottom right of the overall window.
823 +proc init_flist {first} {
824 + global cflist cflist_top cflist_bot selectedline difffilestart
825 +
826 + $cflist conf -state normal
827 + $cflist delete 0.0 end
828 + if {$first ne {}} {
829 + $cflist insert end $first
830 + set cflist_top 1
831 + set cflist_bot 1
832 + $cflist tag add highlight 1.0 "1.0 lineend"
833 + } else {
834 + catch {unset cflist_top}
835 + }
836 + $cflist conf -state disabled
837 + set difffilestart {}
838 +}
839 +
840 +proc add_flist {f} {
841 + global flistmode cflist
842 +
843 + $cflist conf -state normal
844 + if {$flistmode eq "flat"} {
845 + $cflist insert end "\n$f"
846 + }
847 + $cflist conf -state disabled
848 +}
849 +
850 +proc sel_flist {w x y} {
851 + global flistmode ctext difffilestart cflist cflist_top
852 +
853 + if {![info exists cflist_top]} return
854 + set l [lindex [split [$w index "@$x,$y"] "."] 0]
855 + if {$flistmode eq "flat"} {
856 + if {$l == 1} {
857 + $ctext yview 1.0
858 + } else {
859 + catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
860 + }
861 + highlight_flist $l
862 + }
863 +}
864 +
865 +proc scrolltext {f0 f1} {
866 + global cflist_top
867 +
868 + .ctop.cdet.left.sb set $f0 $f1
869 + if {[info exists cflist_top]} {
870 + highlight_flist $cflist_top
871 + }
872 +}
873 +
874 +# Given an index $tl in the $ctext window, this works out which line
875 +# of the $cflist window displays the filename whose patch is shown
876 +# at the given point in the $ctext window. $ll is a hint about which
877 +# line it might be, and is used as the starting point of the search.
878 +proc ctext_index {tl ll} {
879 + global ctext difffilestart
880 +
881 + while {$ll >= 2 && [$ctext compare $tl < \
882 + [lindex $difffilestart [expr {$ll - 2}]]]} {
883 + incr ll -1
884 + }
885 + set nfiles [llength $difffilestart]
886 + while {$ll - 1 < $nfiles && [$ctext compare $tl >= \
887 + [lindex $difffilestart [expr {$ll - 1}]]]} {
888 + incr ll
889 + }
890 + return $ll
891 +}
892 +
893 +proc highlight_flist {ll} {
894 + global ctext cflist cflist_top cflist_bot difffilestart
895 +
896 + if {![info exists difffilestart] || [llength $difffilestart] == 0} return
897 + set ll [ctext_index [$ctext index @0,1] $ll]
898 + set lb $cflist_bot
899 + if {$lb < $ll} {
900 + set lb $ll
901 + }
902 + set y [expr {[winfo height $ctext] - 2}]
903 + set lb [ctext_index [$ctext index @0,$y] $lb]
904 + if {$ll != $cflist_top || $lb != $cflist_bot} {
905 + $cflist tag remove highlight $cflist_top.0 "$cflist_bot.0 lineend"
906 + for {set l $ll} {$l <= $lb} {incr l} {
907 + $cflist tag add highlight $l.0 "$l.0 lineend"
908 + }
909 + set cflist_top $ll
910 + set cflist_bot $lb
911 + }
912 +}
913 +
914 +# Code to implement multiple views
915 +
916 proc newview {} {
917 global nextviewnum newviewname newviewperm uifont
918
@@ -2718,7 +2819,7 @@ proc selectline {l isnew} {
2819 global canv canv2 canv3 ctext commitinfo selectedline
2820 global displayorder linehtag linentag linedtag
2821 global canvy0 linespc parentlist childlist
2721 - global cflist currentid sha1entry
2822 + global currentid sha1entry
2823 global commentend idtags linknum
2824 global mergemax numcommits pending_select
2825
@@ -2841,8 +2942,7 @@ proc selectline {l isnew} {
2942 $ctext conf -state disabled
2943 set commentend [$ctext index "end - 1c"]
2944
2844 - $cflist delete 0 end
2845 - $cflist insert end "Comments"
2945 + init_flist "Comments"
2946 if {[llength $olds] <= 1} {
2947 startdiff $id
2948 } else {
@@ -2960,12 +3060,11 @@ proc goforw {} {
3060
3061 proc mergediff {id l} {
3062 global diffmergeid diffopts mdifffd
2963 - global difffilestart diffids
3063 + global diffids
3064 global parentlist
3065
3066 set diffmergeid $id
3067 set diffids $id
2968 - catch {unset difffilestart}
3068 # this doesn't seem to actually affect anything...
3069 set env(GIT_DIFF_OPTS) $diffopts
3070 set cmd [concat | git-diff-tree --no-commit-id --cc $id]
@@ -3000,11 +3099,10 @@ proc getmergediffline {mdf id np} {
3099 # start of a new file
3100 $ctext insert end "\n"
3101 set here [$ctext index "end - 1c"]
3003 - set i [$cflist index end]
3004 - $ctext mark set fmark.$i $here
3005 - $ctext mark gravity fmark.$i left
3006 - set difffilestart([expr {$i-1}]) $here
3007 - $cflist insert end $fname
3102 + $ctext mark set f:$fname $here
3103 + $ctext mark gravity f:$fname left
3104 + lappend difffilestart $here
3105 + add_flist $fname
3106 set l [expr {(78 - [string length $fname]) / 2}]
3107 set pad [string range "----------------------------------------" 1 $l]
3108 $ctext insert end "$pad $fname $pad\n" filesep
@@ -3075,7 +3173,7 @@ proc startdiff {ids} {
3173 proc addtocflist {ids} {
3174 global treediffs cflist
3175 foreach f $treediffs($ids) {
3078 - $cflist insert end $f
3176 + add_flist $f
3177 }
3178 getblobdiffs $ids
3179 }
@@ -3115,7 +3213,7 @@ proc gettreediffline {gdtf ids} {
3213
3214 proc getblobdiffs {ids} {
3215 global diffopts blobdifffd diffids env curdifftag curtagstart
3118 - global difffilestart nextupdate diffinhdr treediffs
3216 + global nextupdate diffinhdr treediffs
3217
3218 set env(GIT_DIFF_OPTS) $diffopts
3219 set cmd [concat | git-diff-tree --no-commit-id -r -p -C $ids]
@@ -3128,7 +3226,6 @@ proc getblobdiffs {ids} {
3226 set blobdifffd($ids) $bdf
3227 set curdifftag Comments
3228 set curtagstart 0.0
3131 - catch {unset difffilestart}
3229 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
3230 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
3231 }
@@ -3156,24 +3253,15 @@ proc getblobdiffline {bdf ids} {
3253 # start of a new file
3254 $ctext insert end "\n"
3255 $ctext tag add $curdifftag $curtagstart end
3159 - set curtagstart [$ctext index "end - 1c"]
3160 - set header $newname
3256 set here [$ctext index "end - 1c"]
3162 - set i [lsearch -exact $treediffs($diffids) $fname]
3163 - if {$i >= 0} {
3164 - set difffilestart($i) $here
3165 - incr i
3166 - $ctext mark set fmark.$i $here
3167 - $ctext mark gravity fmark.$i left
3168 - }
3257 + set curtagstart $here
3258 + set header $newname
3259 + lappend difffilestart $here
3260 + $ctext mark set f:$fname $here
3261 + $ctext mark gravity f:$fname left
3262 if {$newname != $fname} {
3170 - set i [lsearch -exact $treediffs($diffids) $newname]
3171 - if {$i >= 0} {
3172 - set difffilestart($i) $here
3173 - incr i
3174 - $ctext mark set fmark.$i $here
3175 - $ctext mark gravity fmark.$i left
3176 - }
3263 + $ctext mark set f:$newfname $here
3264 + $ctext mark gravity f:$newfname left
3265 }
3266 set curdifftag "f:$fname"
3267 $ctext tag delete $curdifftag
@@ -3222,26 +3310,11 @@ proc getblobdiffline {bdf ids} {
3310 proc nextfile {} {
3311 global difffilestart ctext
3312 set here [$ctext index @0,0]
3225 - for {set i 0} {[info exists difffilestart($i)]} {incr i} {
3226 - if {[$ctext compare $difffilestart($i) > $here]} {
3227 - if {![info exists pos]
3228 - || [$ctext compare $difffilestart($i) < $pos]} {
3229 - set pos $difffilestart($i)
3230 - }
3313 + foreach loc $difffilestart {
3314 + if {[$ctext compare $loc > $here]} {
3315 + $ctext yview $loc
3316 }
3317 }
3233 - if {[info exists pos]} {
3234 - $ctext yview $pos
3235 - }
3236 -}
3237 -
3238 -proc listboxsel {} {
3239 - global ctext cflist currentid
3240 - if {![info exists currentid]} return
3241 - set sel [lsort [$cflist curselection]]
3242 - if {$sel eq {}} return
3243 - set first [lindex $sel 0]
3244 - catch {$ctext yview fmark.$first}
3318 }
3319
3320 proc setcoords {} {
@@ -3452,7 +3525,7 @@ proc arrowjump {id n y} {
3525 }
3526
3527 proc lineclick {x y id isnew} {
3455 - global ctext commitinfo childlist commitrow cflist canv thickerline
3528 + global ctext commitinfo childlist commitrow canv thickerline
3529
3530 if {![info exists commitinfo($id)] && ![getcommit $id]} return
3531 unmarkmatches
@@ -3509,8 +3582,7 @@ proc lineclick {x y id isnew} {
3582 }
3583 }
3584 $ctext conf -state disabled
3512 -
3513 - $cflist delete 0 end
3585 + init_flist {}
3586 }
3587
3588 proc normalline {} {
@@ -3568,15 +3640,14 @@ proc diffvssel {dirn} {
3640 }
3641
3642 proc doseldiff {oldid newid} {
3571 - global ctext cflist
3643 + global ctext
3644 global commitinfo
3645
3646 $ctext conf -state normal
3647 $ctext delete 0.0 end
3648 $ctext mark set fmark.0 0.0
3649 $ctext mark gravity fmark.0 left
3578 - $cflist delete 0 end
3579 - $cflist insert end "Top"
3650 + init_flist "Top"
3651 $ctext insert end "From "
3652 $ctext tag conf link -foreground blue -underline 1
3653 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
@@ -3862,7 +3933,7 @@ proc rereadrefs {} {
3933 }
3934
3935 proc showtag {tag isnew} {
3865 - global ctext cflist tagcontents tagids linknum
3936 + global ctext tagcontents tagids linknum
3937
3938 if {$isnew} {
3939 addtohistory [list showtag $tag 0]
@@ -3877,7 +3948,7 @@ proc showtag {tag isnew} {
3948 }
3949 appendwithlinks $text
3950 $ctext conf -state disabled
3880 - $cflist delete 0 end
3951 + init_flist {}
3952 }
3953
3954 proc doquit {} {
@@ -4259,6 +4330,7 @@ set fastdate 0
4330 set uparrowlen 7
4331 set downarrowlen 7
4332 set mingaplen 30
4333 +set flistmode "flat"
4334
4335 set colors {green red blue magenta darkgrey brown orange}
4336