@matheusbsbs / matheus-bagliano / commits / bb3edc8b04
Fork 0

gitk: Add progress bars for reading in stuff and for finding

This uses the space formerly occupied by the find string entry field to make a status label (unused for now) and a canvas to display a couple of progress bars. The bar for reading in commits is a short green bar that oscillates back and forth as commits come in. The bar for showing the progress of a Find operation is yellow and advances from left to right. This also arranges to stop a Find operation if the user selects another commit or pops up a context menu, and fixes the "highlight this" popup menu items in the file list window. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Sep 27, 2007 at 11:00 UTC bb3edc8b0473192da11bf7f9e961ea0fcc444c63
1 file changed +153 -33
gitk
+153 -33
@@ -84,6 +84,7 @@ proc start_rev_list {view} {
84 global commfd leftover tclencoding datemode
85 global viewargs viewfiles commitidx viewcomplete vnextroot
86 global showlocalchanges commitinterest mainheadid
87 + global progressdirn progresscoords proglastnc curview
88
89 set startmsecs [clock clicks -milliseconds]
90 set commitidx($view) 0
@@ -111,6 +112,11 @@ proc start_rev_list {view} {
112 }
113 filerun $fd [list getcommitlines $fd $view]
114 nowbusy $view
115 + if {$view == $curview} {
116 + set progressdirn 1
117 + set progresscoords {0 0}
118 + set proglastnc 0
119 + }
120 }
121
122 proc stop_rev_list {} {
@@ -183,9 +189,11 @@ proc getcommitlines {fd view} {
189 }
190 }
191 set viewcomplete($view) 1
186 - global viewname
192 + global viewname progresscoords
193 unset commfd($view)
194 notbusy $view
195 + set progresscoords {0 0}
196 + adjustprogress
197 # set it blocking so we wait for the process to terminate
198 fconfigure $fd -blocking 1
199 if {[catch {close $fd} err]} {
@@ -315,6 +323,33 @@ proc getcommitlines {fd view} {
323 }
324 if {$gotsome} {
325 run chewcommits $view
326 + if {$view == $curview} {
327 + # update progress bar
328 + global progressdirn progresscoords proglastnc
329 + set inc [expr {($commitidx($view) - $proglastnc) * 0.0002}]
330 + set proglastnc $commitidx($view)
331 + set l [lindex $progresscoords 0]
332 + set r [lindex $progresscoords 1]
333 + if {$progressdirn} {
334 + set r [expr {$r + $inc}]
335 + if {$r >= 1.0} {
336 + set r 1.0
337 + set progressdirn 0
338 + }
339 + if {$r > 0.2} {
340 + set l [expr {$r - 0.2}]
341 + }
342 + } else {
343 + set l [expr {$l - $inc}]
344 + if {$l <= 0.0} {
345 + set l 0.0
346 + set progressdirn 1
347 + }
348 + set r [expr {$l + 0.2}]
349 + }
350 + set progresscoords [list $l $r]
351 + adjustprogress
352 + }
353 }
354 return 2
355 }
@@ -589,7 +624,8 @@ proc makewindow {} {
624 global highlight_files gdttype
625 global searchstring sstring
626 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
592 - global headctxmenu
627 + global headctxmenu progresscanv progressitem progresscoords statusw
628 + global fprogitem fprogcoord lastprogupdate progupdatepending
629
630 menu .bar
631 .bar add cascade -label "File" -menu .bar.file
@@ -706,6 +742,22 @@ proc makewindow {} {
742 -state disabled -width 26
743 pack .tf.bar.rightbut -side left -fill y
744
745 + # Status label and progress bar
746 + set statusw .tf.bar.status
747 + label $statusw -width 15 -relief sunken -font $uifont
748 + pack $statusw -side left -padx 5
749 + set h [expr {[font metrics $uifont -linespace] + 2}]
750 + set progresscanv .tf.bar.progress
751 + canvas $progresscanv -relief sunken -height $h -borderwidth 2
752 + set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
753 + set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
754 + pack $progresscanv -side right -expand 1 -fill x
755 + set progresscoords {0 0}
756 + set fprogcoord 0
757 + bind $progresscanv <Configure> adjustprogress
758 + set lastprogupdate [clock clicks -milliseconds]
759 + set progupdatepending 0
760 +
761 # build up the bottom bar of upper window
762 label .tf.lbar.flabel -text "Find " -font $uifont
763 button .tf.lbar.fnext -text "next" -command dofind -font $uifont
@@ -1051,6 +1103,37 @@ proc click {w} {
1103 focus .
1104 }
1105
1106 +# Adjust the progress bar for a change in requested extent or canvas size
1107 +proc adjustprogress {} {
1108 + global progresscanv progressitem progresscoords
1109 + global fprogitem fprogcoord lastprogupdate progupdatepending
1110 +
1111 + set w [expr {[winfo width $progresscanv] - 4}]
1112 + set x0 [expr {$w * [lindex $progresscoords 0]}]
1113 + set x1 [expr {$w * [lindex $progresscoords 1]}]
1114 + set h [winfo height $progresscanv]
1115 + $progresscanv coords $progressitem $x0 0 $x1 $h
1116 + $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
1117 + set now [clock clicks -milliseconds]
1118 + if {$now >= $lastprogupdate + 100} {
1119 + set progupdatepending 0
1120 + update
1121 + } elseif {!$progupdatepending} {
1122 + set progupdatepending 1
1123 + after [expr {$lastprogupdate + 100 - $now}] doprogupdate
1124 + }
1125 +}
1126 +
1127 +proc doprogupdate {} {
1128 + global lastprogupdate progupdatepending
1129 +
1130 + if {$progupdatepending} {
1131 + set progupdatepending 0
1132 + set lastprogupdate [clock clicks -milliseconds]
1133 + update
1134 + }
1135 +}
1136 +
1137 proc savestuff {w} {
1138 global canv canv2 canv3 ctext cflist mainfont textfont uifont tabstop
1139 global stuffsaved findmergefiles maxgraphpct
@@ -1626,6 +1709,7 @@ proc pop_flist_menu {w X Y x y} {
1709 global ctext cflist cmitmode flist_menu flist_menu_file
1710 global treediffs diffids
1711
1712 + stopfinding
1713 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1714 if {$l <= 1} return
1715 if {$cmitmode eq "tree"} {
@@ -1639,14 +1723,15 @@ proc pop_flist_menu {w X Y x y} {
1723 }
1724
1725 proc flist_hl {only} {
1642 - global flist_menu_file highlight_files
1726 + global flist_menu_file findstring gdttype
1727
1728 set x [shellquote $flist_menu_file]
1645 - if {$only || $highlight_files eq {}} {
1646 - set highlight_files $x
1729 + if {$only || $findstring eq {} || $gdttype ne "touching paths:"} {
1730 + set findstring $x
1731 } else {
1648 - append highlight_files " " $x
1732 + append findstring " " $x
1733 }
1734 + set gdttype "touching paths:"
1735 }
1736
1737 # Functions for adding and removing shell-type quoting
@@ -2210,6 +2295,7 @@ proc hfiles_change {} {
2295 proc gdttype_change {name ix op} {
2296 global gdttype highlight_files findstring findpattern
2297
2298 + stopfinding
2299 if {$findstring ne {}} {
2300 if {$gdttype eq "containing:"} {
2301 if {$highlight_files ne {}} {
@@ -2233,6 +2319,7 @@ proc gdttype_change {name ix op} {
2319 proc find_change {name ix op} {
2320 global gdttype findstring highlight_files
2321
2322 + stopfinding
2323 if {$gdttype eq "containing:"} {
2324 findcom_change
2325 } else {
@@ -2248,6 +2335,7 @@ proc findcom_change {} {
2335 global nhighlights mainfont boldnamerows
2336 global findpattern findtype findstring gdttype
2337
2338 + stopfinding
2339 # delete previous highlights, if any
2340 foreach row $boldnamerows {
2341 bolden_name $row $mainfont
@@ -4174,6 +4262,18 @@ proc dofind {{rev 0}} {
4262 }
4263 }
4264
4265 +proc stopfinding {} {
4266 + global find_dirn findcurline fprogcoord
4267 +
4268 + if {[info exists find_dirn]} {
4269 + unset find_dirn
4270 + unset findcurline
4271 + notbusy finding
4272 + set fprogcoord 0
4273 + adjustprogress
4274 + }
4275 +}
4276 +
4277 proc findnext {restart} {
4278 global findcurline find_dirn
4279
@@ -4207,8 +4307,11 @@ proc findprev {} {
4307 proc findmore {} {
4308 global commitdata commitinfo numcommits findpattern findloc
4309 global findstartline findcurline displayorder
4210 - global find_dirn gdttype fhighlights
4310 + global find_dirn gdttype fhighlights fprogcoord
4311
4312 + if {![info exists find_dirn]} {
4313 + return 0
4314 + }
4315 set fldtypes {Headline Author Date Committer CDate Comments}
4316 set l [expr {$findcurline + 1}]
4317 if {$l >= $numcommits} {
@@ -4258,32 +4361,41 @@ proc findmore {} {
4361 }
4362 }
4363 }
4261 - if {$found} {
4364 + if {$found || ($domore && $l == $findstartline + 1)} {
4365 + unset findcurline
4366 unset find_dirn
4263 - findselectline $l
4367 notbusy finding
4368 + set fprogcoord 0
4369 + adjustprogress
4370 + if {$found} {
4371 + findselectline $l
4372 + } else {
4373 + bell
4374 + }
4375 return 0
4376 }
4377 if {!$domore} {
4378 flushhighlights
4269 - return 0
4379 + } else {
4380 + set findcurline [expr {$l - 1}]
4381 }
4271 - if {$l == $findstartline + 1} {
4272 - bell
4273 - unset findcurline
4274 - unset find_dirn
4275 - notbusy finding
4276 - return 0
4382 + set n [expr {$findcurline - ($findstartline + 1)}]
4383 + if {$n < 0} {
4384 + incr n $numcommits
4385 }
4278 - set findcurline [expr {$l - 1}]
4279 - return 1
4386 + set fprogcoord [expr {$n * 1.0 / $numcommits}]
4387 + adjustprogress
4388 + return $domore
4389 }
4390
4391 proc findmorerev {} {
4392 global commitdata commitinfo numcommits findpattern findloc
4393 global findstartline findcurline displayorder
4285 - global find_dirn gdttype fhighlights
4394 + global find_dirn gdttype fhighlights fprogcoord
4395
4396 + if {![info exists find_dirn]} {
4397 + return 0
4398 + }
4399 set fldtypes {Headline Author Date Committer CDate Comments}
4400 set l $findcurline
4401 if {$l == 0} {
@@ -4333,25 +4445,31 @@ proc findmorerev {} {
4445 }
4446 }
4447 }
4336 - if {$found} {
4448 + if {$found || ($domore && $l == $findstartline - 1)} {
4449 + unset findcurline
4450 unset find_dirn
4338 - findselectline $l
4451 notbusy finding
4452 + set fprogcoord 0
4453 + adjustprogress
4454 + if {$found} {
4455 + findselectline $l
4456 + } else {
4457 + bell
4458 + }
4459 return 0
4460 }
4461 if {!$domore} {
4462 flushhighlights
4344 - return 0
4463 + } else {
4464 + set findcurline [expr {$l + 1}]
4465 }
4346 - if {$l == -1} {
4347 - bell
4348 - unset findcurline
4349 - unset find_dirn
4350 - notbusy finding
4351 - return 0
4466 + set n [expr {($findstartline - 1) - $findcurline}]
4467 + if {$n < 0} {
4468 + incr n $numcommits
4469 }
4353 - set findcurline [expr {$l + 1}]
4354 - return 1
4470 + set fprogcoord [expr {$n * 1.0 / $numcommits}]
4471 + adjustprogress
4472 + return $domore
4473 }
4474
4475 proc findselectline {l} {
@@ -4398,12 +4516,11 @@ proc markmatches {canv l str tag matches font row} {
4516 }
4517
4518 proc unmarkmatches {} {
4401 - global findids markingmatches findcurline
4519 + global markingmatches
4520
4521 allcanvs delete matches
4404 - catch {unset findids}
4522 set markingmatches 0
4406 - catch {unset findcurline}
4523 + stopfinding
4524 }
4525
4526 proc selcanvline {w x y} {
@@ -4626,6 +4743,7 @@ proc selectline {l isnew} {
4743 $canv delete hover
4744 normalline
4745 unsel_reflist
4746 + stopfinding
4747 if {$l < 0 || $l >= $numcommits} return
4748 set y [expr {$canvy0 + $l * $linespc}]
4749 set ymax [lindex [$canv cget -scrollregion] 3]
@@ -5815,6 +5933,7 @@ proc rowmenu {x y id} {
5933 global rowctxmenu commitrow selectedline rowmenuid curview
5934 global nullid nullid2 fakerowmenu mainhead
5935
5936 + stopfinding
5937 set rowmenuid $id
5938 if {![info exists selectedline]
5939 || $commitrow($curview,$id) eq $selectedline} {
@@ -6293,6 +6412,7 @@ proc readresetstat {fd w} {
6412 proc headmenu {x y id head} {
6413 global headmenuid headmenuhead headctxmenu mainhead
6414
6415 + stopfinding
6416 set headmenuid $id
6417 set headmenuhead $head
6418 set state normal