1# git-gui status bar mega-widget
2# Copyright (C) 2007 Shawn Pearce
3
4class status_bar {
5
6field w ; # our own window path
7field w_l ; # text widget we draw messages into
8field w_c ; # canvas we draw a progress bar into
9field status {}; # single line of text we show
10field prefix {}; # text we format into status
11field units {}; # unit of progress
12
13constructor new {path} {
14 set w $path
15 set w_l $w.l
16 set w_c $w.c
17
18 frame $w \
19 -borderwidth 1 \
20 -relief sunken
21 label $w_l \
22 -textvariable @status \
23 -anchor w \
24 -justify left
25 pack $w_l -side left
26
27 bind $w <Destroy> [cb _delete %W]
28 return $this
29}
30
31method start {msg uds} {
32 if {[winfo exists $w_c]} {
33 $w_c coords bar 0 0 0 20
34 } else {
35 canvas $w_c \
36 -width 100 \
37 -height [expr {int([winfo reqheight $w_l] * 0.6)}] \
38 -borderwidth 1 \
39 -relief groove \
40 -highlightt 0
41 $w_c create rectangle 0 0 0 20 -tags bar -fill navy
42 pack $w_c -side right
43 }
44
45 set status $msg
46 set prefix $msg
47 set units $uds
48}
49
50method update {have total} {
51 set pdone 0
52 if {$total > 0} {
53 set pdone [expr {100 * $have / $total}]
54 }
55
56 set status [format "%s ... %i of %i %s (%2i%%)" \
57 $prefix $have $total $units $pdone]
58 $w_c coords bar 0 0 $pdone 20
59}
60
61method stop {msg} {
62 destroy $w_c
63 set status $msg
64}
65
66method show {msg} {
67 set status $msg
68}
69
70method _delete {current} {
71 if {$current eq $w} {
72 delete_this
73 }
74}
75
76}