More fixes for geometry restoration

Make up/down/pgup/pgdn work again
Return in find string entry does find
Scale circles and lines with font size
Fix scrolling to make entire selected line visible
Use white circle for commits not listed but put in to terminate lines
Fix diff parsing for created and deleted files
This commit is contained in:
Paul Mackerras 2005-05-18 22:51:00 +00:00
Родитель df3d83b143
Коммит 173860663e
1 изменённых файлов: 66 добавлений и 35 удалений

101
gitk
Просмотреть файл

@ -7,7 +7,7 @@ exec wish "$0" -- "${1+$@}"
# and distributed under the terms of the GNU General Public Licence, # and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version. # either version 2, or (at your option) any later version.
# CVS $Revision: 1.14 $ # CVS $Revision: 1.15 $
proc getcommits {rargs} { proc getcommits {rargs} {
global commits commfd phase canv mainfont global commits commfd phase canv mainfont
@ -160,6 +160,9 @@ proc makewindow {} {
panedwindow .ctop -orient vertical panedwindow .ctop -orient vertical
if {[info exists geometry(width)]} { if {[info exists geometry(width)]} {
.ctop conf -width $geometry(width) -height $geometry(height) .ctop conf -width $geometry(width) -height $geometry(height)
set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
set geometry(ctexth) [expr {($texth - 8) /
[font metrics $textfont -linespace]}]
} }
frame .ctop.top frame .ctop.top
frame .ctop.top.bar frame .ctop.top.bar
@ -195,8 +198,6 @@ proc makewindow {} {
set findstring {} set findstring {}
set fstring .ctop.top.bar.findstring set fstring .ctop.top.bar.findstring
entry $fstring -width 30 -font $textfont -textvariable findstring entry $fstring -width 30 -font $textfont -textvariable findstring
# stop the toplevel events from firing on key presses
bind $fstring <Key> "[bind Entry <Key>]; break"
pack $fstring -side left -expand 1 -fill x pack $fstring -side left -expand 1 -fill x
set findtype Exact set findtype Exact
tk_optionMenu .ctop.top.bar.findtype findtype Exact IgnCase Regexp tk_optionMenu .ctop.top.bar.findtype findtype Exact IgnCase Regexp
@ -226,7 +227,7 @@ proc makewindow {} {
frame .ctop.cdet.right frame .ctop.cdet.right
set cflist .ctop.cdet.right.cfiles set cflist .ctop.cdet.right.cfiles
listbox $cflist -width $geometry(cflistw) -bg white -selectmode extended \ listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \
-yscrollcommand ".ctop.cdet.right.sb set" -yscrollcommand ".ctop.cdet.right.sb set"
scrollbar .ctop.cdet.right.sb -command "$cflist yview" scrollbar .ctop.cdet.right.sb -command "$cflist yview"
pack .ctop.cdet.right.sb -side right -fill y pack .ctop.cdet.right.sb -side right -fill y
@ -242,10 +243,10 @@ proc makewindow {} {
bindall <ButtonRelease-5> "allcanvs yview scroll 5 u" bindall <ButtonRelease-5> "allcanvs yview scroll 5 u"
bindall <2> "allcanvs scan mark 0 %y" bindall <2> "allcanvs scan mark 0 %y"
bindall <B2-Motion> "allcanvs scan dragto 0 %y" bindall <B2-Motion> "allcanvs scan dragto 0 %y"
bindall <Key-Up> "selnextline -1" bind . <Key-Up> "selnextline -1"
bindall <Key-Down> "selnextline 1" bind . <Key-Down> "selnextline 1"
bindall <Key-Prior> "allcanvs yview scroll -1 p" bind . <Key-Prior> "allcanvs yview scroll -1 p"
bindall <Key-Next> "allcanvs yview scroll 1 p" bind . <Key-Next> "allcanvs yview scroll 1 p"
bindkey <Key-Delete> "$ctext yview scroll -1 p" bindkey <Key-Delete> "$ctext yview scroll -1 p"
bindkey <Key-BackSpace> "$ctext yview scroll -1 p" bindkey <Key-BackSpace> "$ctext yview scroll -1 p"
bindkey <Key-space> "$ctext yview scroll 1 p" bindkey <Key-space> "$ctext yview scroll 1 p"
@ -267,6 +268,7 @@ proc makewindow {} {
bind $cflist <<ListboxSelect>> listboxsel bind $cflist <<ListboxSelect>> listboxsel
bind . <Destroy> {savestuff %W} bind . <Destroy> {savestuff %W}
bind . <Button-1> "click %W" bind . <Button-1> "click %W"
bind $fstring <Key-Return> dofind
} }
# when we make a key binding for the toplevel, make sure # when we make a key binding for the toplevel, make sure
@ -306,13 +308,9 @@ proc savestuff {w} {
puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]" puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]"
puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]" puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]"
puts $f "set geometry(canvh) [expr [winfo height $canv]-2]" puts $f "set geometry(canvh) [expr [winfo height $canv]-2]"
puts $f "set geometry(csash) {[.ctop sash coord 0]}"
set wid [expr {([winfo width $ctext] - 8) \ set wid [expr {([winfo width $ctext] - 8) \
/ [font measure $textfont "0"]}] / [font measure $textfont "0"]}]
set ht [expr {([winfo height $ctext] - 8) \
/ [font metrics $textfont -linespace]}]
puts $f "set geometry(ctextw) $wid" puts $f "set geometry(ctextw) $wid"
puts $f "set geometry(ctexth) $ht"
set wid [expr {([winfo width $cflist] - 11) \ set wid [expr {([winfo width $cflist] - 11) \
/ [font measure [$cflist cget -font] "0"]}] / [font measure [$cflist cget -font] "0"]}]
puts $f "set geometry(cflistw) $wid" puts $f "set geometry(cflistw) $wid"
@ -403,7 +401,7 @@ Copyright
Use and redistribute under the terms of the GNU General Public License Use and redistribute under the terms of the GNU General Public License
(CVS $Revision: 1.14 $)} \ (CVS $Revision: 1.15 $)} \
-justify center -aspect 400 -justify center -aspect 400
pack $w.m -side top -fill x -padx 20 -pady 20 pack $w.m -side top -fill x -padx 20 -pady 20
button $w.ok -text Close -command "destroy $w" button $w.ok -text Close -command "destroy $w"
@ -520,9 +518,11 @@ proc drawgraph {} {
set lineno -1 set lineno -1
set numcommits 0 set numcommits 0
set phase drawgraph set phase drawgraph
set lthickness [expr {($linespc / 9) + 1}]
while 1 { while 1 {
set canvy $y2 set canvy $y2
allcanvs conf -scrollregion [list 0 0 0 $canvy] allcanvs conf -scrollregion \
[list 0 0 0 [expr $canvy + 0.5 * $linespc + 2]]
update update
if {$stopped} break if {$stopped} break
incr numcommits incr numcommits
@ -551,13 +551,15 @@ proc drawgraph {} {
set y2 [expr $canvy + $linespc] set y2 [expr $canvy + $linespc]
if {[info exists linestarty($level)] && $linestarty($level) < $canvy} { if {[info exists linestarty($level)] && $linestarty($level) < $canvy} {
set t [$canv create line $x $linestarty($level) $x $canvy \ set t [$canv create line $x $linestarty($level) $x $canvy \
-width 2 -fill $colormap($id)] -width $lthickness -fill $colormap($id)]
$canv lower $t $canv lower $t
} }
set linestarty($level) $canvy set linestarty($level) $canvy
set t [$canv create oval [expr $x - 4] [expr $canvy - 4] \ set ofill [expr {[info exists parents($id)]? "blue": "white"}]
[expr $x + 3] [expr $canvy + 3] \ set orad [expr {$linespc / 3}]
-fill blue -outline black -width 1] set t [$canv create oval [expr $x - $orad] [expr $canvy - $orad] \
[expr $x + $orad - 1] [expr $canvy + $orad - 1] \
-fill $ofill -outline black -width 1]
$canv raise $t $canv raise $t
set xt [expr $canvx0 + $nlines * $linespc] set xt [expr $canvx0 + $nlines * $linespc]
set headline [lindex $commitinfo($id) 0] set headline [lindex $commitinfo($id) 0]
@ -694,7 +696,8 @@ proc drawgraph {} {
lappend coords [expr $xj - $linespc] $canvy lappend coords [expr $xj - $linespc] $canvy
} }
lappend coords $xj $y2 lappend coords $xj $y2
set t [$canv create line $coords -width 2 -fill $colormap($dst)] set t [$canv create line $coords -width $lthickness \
-fill $colormap($dst)]
$canv lower $t $canv lower $t
if {![info exists linestarty($j)]} { if {![info exists linestarty($j)]} {
set linestarty($j) $y2 set linestarty($j) $y2
@ -882,9 +885,9 @@ proc selcanvline {x y} {
proc selectline {l} { proc selectline {l} {
global canv canv2 canv3 ctext commitinfo selectedline global canv canv2 canv3 ctext commitinfo selectedline
global lineid linehtag linentag linedtag global lineid linehtag linentag linedtag
global canvy canvy0 linespc nparents treepending global canvy0 linespc nparents treepending
global cflist treediffs currentid sha1entry global cflist treediffs currentid sha1entry
global commentend global commentend seenfile numcommits
if {![info exists lineid($l)] || ![info exists linehtag($l)]} return if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
$canv delete secsel $canv delete secsel
set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \ set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
@ -899,14 +902,24 @@ proc selectline {l} {
-tags secsel -fill [$canv3 cget -selectbackground]] -tags secsel -fill [$canv3 cget -selectbackground]]
$canv3 lower $t $canv3 lower $t
set y [expr {$canvy0 + $l * $linespc}] set y [expr {$canvy0 + $l * $linespc}]
set ytop [expr {($y - $linespc / 2.0) / $canvy}] set ymax [lindex [$canv cget -scrollregion] 3]
set ybot [expr {($y + $linespc / 2.0) / $canvy}] set ytop [expr {($y - $linespc / 2.0 - 1) / $ymax}]
set ybot [expr {($y + $linespc / 2.0 + 1) / $ymax}]
set wnow [$canv yview] set wnow [$canv yview]
if {$ytop < [lindex $wnow 0]} { set scrincr [expr {$linespc * 1.0 / $ymax}]
set wtop [lindex $wnow 0]
if {$ytop < $wtop} {
if {$ytop > $wtop - $scrincr} {
set ytop [expr {$wtop - $scrincr}]
}
allcanvs yview moveto $ytop allcanvs yview moveto $ytop
} elseif {$ybot > [lindex $wnow 1]} { } elseif {$ybot > [lindex $wnow 1]} {
set wh [expr {[lindex $wnow 1] - [lindex $wnow 0]}] set wh [expr {[lindex $wnow 1] - $wtop}]
allcanvs yview moveto [expr {$ybot - $wh}] set ytop [expr {$ybot - $wh}]
if {$ytop < $wtop + $scrincr} {
set ytop [expr {$wtop + $scrincr}]
}
allcanvs yview moveto $ytop
} }
set selectedline $l set selectedline $l
@ -942,6 +955,7 @@ proc selectline {l} {
addtocflist $id addtocflist $id
} }
} }
catch {unset seenfile}
} }
proc selnextline {dir} { proc selnextline {dir} {
@ -1008,13 +1022,15 @@ proc getblobdiffs {id} {
} }
proc getblobdiffline {bdf id} { proc getblobdiffline {bdf id} {
global currentid blobdifffd ctext curdifftag curtagstart global currentid blobdifffd ctext curdifftag curtagstart seenfile
global diffnexthead
set n [gets $bdf line] set n [gets $bdf line]
if {$n < 0} { if {$n < 0} {
if {[eof $bdf]} { if {[eof $bdf]} {
close $bdf close $bdf
if {$id == $currentid && $bdf == $blobdifffd($id)} { if {$id == $currentid && $bdf == $blobdifffd($id)} {
$ctext tag add $curdifftag $curtagstart end $ctext tag add $curdifftag $curtagstart end
set seenfile($curdifftag) 1
} }
} }
return return
@ -1023,11 +1039,16 @@ proc getblobdiffline {bdf id} {
return return
} }
$ctext conf -state normal $ctext conf -state normal
if {[regexp {^---[ \t]+([^/])+/(.*)} $line match s1 fname]} { if {[regexp {^---[ \t]+([^/])*/(.*)} $line match s1 fname]} {
# start of a new file # start of a new file
$ctext insert end "\n" $ctext insert end "\n"
$ctext tag add $curdifftag $curtagstart end $ctext tag add $curdifftag $curtagstart end
set seenfile($curdifftag) 1
set curtagstart [$ctext index "end - 1c"] set curtagstart [$ctext index "end - 1c"]
if {[info exists diffnexthead]} {
set fname $diffnexthead
unset diffnexthead
}
set curdifftag "f:$fname" set curdifftag "f:$fname"
$ctext tag delete $curdifftag $ctext tag delete $curdifftag
set l [expr {(78 - [string length $fname]) / 2}] set l [expr {(78 - [string length $fname]) / 2}]
@ -1035,6 +1056,10 @@ proc getblobdiffline {bdf id} {
$ctext insert end "$pad $fname $pad\n" filesep $ctext insert end "$pad $fname $pad\n" filesep
} elseif {[string range $line 0 2] == "+++"} { } elseif {[string range $line 0 2] == "+++"} {
# no need to do anything with this # no need to do anything with this
} elseif {[regexp {^Created: (.*) \(mode: *[0-7]*\)} $line match fn]} {
set diffnexthead $fn
} elseif {[string range $line 0 8] == "Deleted: "} {
set diffnexthead [string range $line 9 end]
} elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \ } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
$line match f1l f1c f2l f2c rest]} { $line match f1l f1c f2l f2c rest]} {
$ctext insert end "\t" hunksep $ctext insert end "\t" hunksep
@ -1054,6 +1079,7 @@ proc getblobdiffline {bdf id} {
if {$curdifftag != "Comments"} { if {$curdifftag != "Comments"} {
$ctext insert end "\n" $ctext insert end "\n"
$ctext tag add $curdifftag $curtagstart end $ctext tag add $curdifftag $curtagstart end
set seenfile($curdifftag) 1
set curtagstart [$ctext index "end - 1c"] set curtagstart [$ctext index "end - 1c"]
set curdifftag Comments set curdifftag Comments
} }
@ -1064,14 +1090,16 @@ proc getblobdiffline {bdf id} {
} }
proc listboxsel {} { proc listboxsel {} {
global ctext cflist currentid treediffs global ctext cflist currentid treediffs seenfile
if {![info exists currentid]} return if {![info exists currentid]} return
set sel [$cflist curselection] set sel [$cflist curselection]
if {$sel == {} || [lsearch -exact $sel 0] >= 0} { if {$sel == {} || [lsearch -exact $sel 0] >= 0} {
# show everything # show everything
$ctext tag conf Comments -elide 0 $ctext tag conf Comments -elide 0
foreach f $treediffs($currentid) { foreach f $treediffs($currentid) {
$ctext tag conf "f:$f" -elide 0 if [info exists seenfile(f:$f)] {
$ctext tag conf "f:$f" -elide 0
}
} }
} else { } else {
# just show selected files # just show selected files
@ -1079,7 +1107,9 @@ proc listboxsel {} {
set i 1 set i 1
foreach f $treediffs($currentid) { foreach f $treediffs($currentid) {
set elide [expr {[lsearch -exact $sel $i] < 0}] set elide [expr {[lsearch -exact $sel $i] < 0}]
$ctext tag conf "f:$f" -elide $elide if [info exists seenfile(f:$f)] {
$ctext tag conf "f:$f" -elide $elide
}
incr i incr i
} }
} }
@ -1133,17 +1163,18 @@ set boldnames 0
set diffopts "-U 5 -p" set diffopts "-U 5 -p"
set mainfont {Helvetica 9} set mainfont {Helvetica 9}
set namefont $mainfont
set textfont {Courier 9} set textfont {Courier 9}
if {$boldnames} {
lappend namefont bold
}
set colors {green red blue magenta darkgrey brown orange} set colors {green red blue magenta darkgrey brown orange}
set colorbycommitter false set colorbycommitter false
catch {source ~/.gitk} catch {source ~/.gitk}
set namefont $mainfont
if {$boldnames} {
lappend namefont bold
}
set revtreeargs {} set revtreeargs {}
foreach arg $argv { foreach arg $argv {
switch -regexp -- $arg { switch -regexp -- $arg {