git-gui: allow Ctrl+T to toggle multiple paths
[git/git.git] / lib / status_bar.tcl
CommitLineData
b29bd5ca
SP
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
96225dbe 9field c_pack ; # script to pack the canvas with
b29bd5ca
SP
10field status {}; # single line of text we show
11field prefix {}; # text we format into status
12field units {}; # unit of progress
b7922306 13field meter {}; # current core git progress meter (if active)
b29bd5ca
SP
14
15constructor new {path} {
c80d7be5 16 global use_ttk NS
b29bd5ca
SP
17 set w $path
18 set w_l $w.l
19 set w_c $w.c
20
c80d7be5
PT
21 ${NS}::frame $w
22 if {!$use_ttk} {
23 $w configure -borderwidth 1 -relief sunken
24 }
25 ${NS}::label $w_l \
b29bd5ca
SP
26 -textvariable @status \
27 -anchor w \
28 -justify left
29 pack $w_l -side left
96225dbe
SP
30 set c_pack [cb _oneline_pack]
31
32 bind $w <Destroy> [cb _delete %W]
33 return $this
34}
35
36method _oneline_pack {} {
37 $w_c conf -width 100
38 pack $w_c -side right
39}
40
41constructor two_line {path} {
b963d118 42 global NS
96225dbe
SP
43 set w $path
44 set w_l $w.l
45 set w_c $w.c
46
c80d7be5
PT
47 ${NS}::frame $w
48 ${NS}::label $w_l \
96225dbe
SP
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]
b29bd5ca
SP
54
55 bind $w <Destroy> [cb _delete %W]
56 return $this
57}
58
59method start {msg uds} {
60 if {[winfo exists $w_c]} {
61 $w_c coords bar 0 0 0 20
62 } else {
63 canvas $w_c \
b29bd5ca
SP
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
96225dbe 69 eval $c_pack
b29bd5ca
SP
70 }
71
72 set status $msg
73 set prefix $msg
74 set units $uds
b7922306 75 set meter {}
b29bd5ca
SP
76}
77
78method update {have total} {
79 set pdone 0
ba5d445b 80 set cdone 0
b29bd5ca
SP
81 if {$total > 0} {
82 set pdone [expr {100 * $have / $total}]
96225dbe 83 set cdone [expr {[winfo width $w_c] * $have / $total}]
b29bd5ca
SP
84 }
85
96225dbe
SP
86 set prec [string length [format %i $total]]
87 set status [mc "%s ... %*i of %*i %s (%3i%%)" \
88 $prefix \
89 $prec $have \
90 $prec $total \
91 $units $pdone]
92 $w_c coords bar 0 0 $cdone 20
b29bd5ca
SP
93}
94
b7922306
SP
95method update_meter {buf} {
96 append meter $buf
97 set r [string last "\r" $meter]
98 if {$r == -1} {
99 return
100 }
101
102 set prior [string range $meter 0 $r]
103 set meter [string range $meter [expr {$r + 1}] end]
bea6878b
SP
104 set p "\\((\\d+)/(\\d+)\\)"
105 if {[regexp ":\\s*\\d+% $p\(?:, done.\\s*\n|\\s*\r)\$" $prior _j a b]} {
106 update $this $a $b
107 } elseif {[regexp "$p\\s+done\r\$" $prior _j a b]} {
b7922306
SP
108 update $this $a $b
109 }
110}
111
112method stop {{msg {}}} {
b29bd5ca 113 destroy $w_c
b7922306
SP
114 if {$msg ne {}} {
115 set status $msg
116 }
b29bd5ca
SP
117}
118
51530d17
SP
119method show {msg {test {}}} {
120 if {$test eq {} || $status eq $test} {
121 set status $msg
122 }
b29bd5ca
SP
123}
124
125method _delete {current} {
126 if {$current eq $w} {
127 delete_this
128 }
129}
130
131}