Rebasing merge to junio/next (9c3410c)
[git/mingw/4msysgit/kblees.git] / git-gui / lib / status_bar.tcl
blob95cb44991fc5b018805d6091c4f98ce7ae0ccf52
1 # git-gui status bar mega-widget
2 # Copyright (C) 2007 Shawn Pearce
4 class status_bar {
6 field w ; # our own window path
7 field w_l ; # text widget we draw messages into
8 field w_c ; # canvas we draw a progress bar into
9 field c_pack ; # script to pack the canvas with
10 field status {}; # single line of text we show
11 field prefix {}; # text we format into status
12 field units {}; # unit of progress
13 field meter {}; # current core git progress meter (if active)
15 constructor new {path} {
16 global use_ttk NS
17 set w $path
18 set w_l $w.l
19 set w_c $w.c
21 ${NS}::frame $w
22 if {!$use_ttk} {
23 $w configure -borderwidth 1 -relief sunken
25 ${NS}::label $w_l \
26 -textvariable @status \
27 -anchor w \
28 -justify left
29 pack $w_l -side left
30 set c_pack [cb _oneline_pack]
32 bind $w <Destroy> [cb _delete %W]
33 return $this
36 method _oneline_pack {} {
37 $w_c conf -width 100
38 pack $w_c -side right
41 constructor two_line {path} {
42 global NS
43 set w $path
44 set w_l $w.l
45 set w_c $w.c
47 ${NS}::frame $w
48 ${NS}::label $w_l \
49 -textvariable @status \
50 -anchor w \
51 -justify left
52 pack $w_l -anchor w -fill x
53 set c_pack [list pack $w_c -fill x]
55 bind $w <Destroy> [cb _delete %W]
56 return $this
59 method start {msg uds} {
60 if {[winfo exists $w_c]} {
61 $w_c coords bar 0 0 0 20
62 } else {
63 canvas $w_c \
64 -height [expr {int([winfo reqheight $w_l] * 0.6)}] \
65 -borderwidth 1 \
66 -relief groove \
67 -highlightt 0
68 $w_c create rectangle 0 0 0 20 -tags bar -fill navy
69 eval $c_pack
72 set status $msg
73 set prefix $msg
74 set units $uds
75 set meter {}
78 method update {have total} {
79 set pdone 0
80 if {$total > 0} {
81 set pdone [expr {100 * $have / $total}]
82 set cdone [expr {[winfo width $w_c] * $have / $total}]
85 set prec [string length [format %i $total]]
86 set status [mc "%s ... %*i of %*i %s (%3i%%)" \
87 $prefix \
88 $prec $have \
89 $prec $total \
90 $units $pdone]
91 $w_c coords bar 0 0 $cdone 20
94 method update_meter {buf} {
95 append meter $buf
96 set r [string last "\r" $meter]
97 if {$r == -1} {
98 return
101 set prior [string range $meter 0 $r]
102 set meter [string range $meter [expr {$r + 1}] end]
103 set p "\\((\\d+)/(\\d+)\\)"
104 if {[regexp ":\\s*\\d+% $p\(?:, done.\\s*\n|\\s*\r)\$" $prior _j a b]} {
105 update $this $a $b
106 } elseif {[regexp "$p\\s+done\r\$" $prior _j a b]} {
107 update $this $a $b
111 method stop {{msg {}}} {
112 destroy $w_c
113 if {$msg ne {}} {
114 set status $msg
118 method show {msg {test {}}} {
119 if {$test eq {} || $status eq $test} {
120 set status $msg
124 method _delete {current} {
125 if {$current eq $w} {
126 delete_this