2007-07-09 04:01:47 +02:00
|
|
|
# git-gui status bar mega-widget
|
|
|
|
# Copyright (C) 2007 Shawn Pearce
|
|
|
|
|
|
|
|
class status_bar {
|
|
|
|
|
|
|
|
field w ; # our own window path
|
|
|
|
field w_l ; # text widget we draw messages into
|
|
|
|
field w_c ; # canvas we draw a progress bar into
|
2007-09-26 21:31:42 +02:00
|
|
|
field c_pack ; # script to pack the canvas with
|
2007-07-09 04:01:47 +02:00
|
|
|
field status {}; # single line of text we show
|
|
|
|
field prefix {}; # text we format into status
|
|
|
|
field units {}; # unit of progress
|
2007-07-09 04:48:19 +02:00
|
|
|
field meter {}; # current core git progress meter (if active)
|
2007-07-09 04:01:47 +02:00
|
|
|
|
|
|
|
constructor new {path} {
|
2010-01-26 01:05:31 +01:00
|
|
|
global use_ttk NS
|
2007-07-09 04:01:47 +02:00
|
|
|
set w $path
|
|
|
|
set w_l $w.l
|
|
|
|
set w_c $w.c
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::frame $w
|
|
|
|
if {!$use_ttk} {
|
|
|
|
$w configure -borderwidth 1 -relief sunken
|
|
|
|
}
|
|
|
|
${NS}::label $w_l \
|
2007-07-09 04:01:47 +02:00
|
|
|
-textvariable @status \
|
|
|
|
-anchor w \
|
|
|
|
-justify left
|
|
|
|
pack $w_l -side left
|
2007-09-26 21:31:42 +02:00
|
|
|
set c_pack [cb _oneline_pack]
|
|
|
|
|
|
|
|
bind $w <Destroy> [cb _delete %W]
|
|
|
|
return $this
|
|
|
|
}
|
|
|
|
|
|
|
|
method _oneline_pack {} {
|
|
|
|
$w_c conf -width 100
|
|
|
|
pack $w_c -side right
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor two_line {path} {
|
2010-02-20 14:38:38 +01:00
|
|
|
global NS
|
2007-09-26 21:31:42 +02:00
|
|
|
set w $path
|
|
|
|
set w_l $w.l
|
|
|
|
set w_c $w.c
|
|
|
|
|
2010-01-26 01:05:31 +01:00
|
|
|
${NS}::frame $w
|
|
|
|
${NS}::label $w_l \
|
2007-09-26 21:31:42 +02:00
|
|
|
-textvariable @status \
|
|
|
|
-anchor w \
|
|
|
|
-justify left
|
|
|
|
pack $w_l -anchor w -fill x
|
|
|
|
set c_pack [list pack $w_c -fill x]
|
2007-07-09 04:01:47 +02:00
|
|
|
|
|
|
|
bind $w <Destroy> [cb _delete %W]
|
|
|
|
return $this
|
|
|
|
}
|
|
|
|
|
|
|
|
method start {msg uds} {
|
|
|
|
if {[winfo exists $w_c]} {
|
|
|
|
$w_c coords bar 0 0 0 20
|
|
|
|
} else {
|
|
|
|
canvas $w_c \
|
|
|
|
-height [expr {int([winfo reqheight $w_l] * 0.6)}] \
|
|
|
|
-borderwidth 1 \
|
|
|
|
-relief groove \
|
|
|
|
-highlightt 0
|
|
|
|
$w_c create rectangle 0 0 0 20 -tags bar -fill navy
|
2007-09-26 21:31:42 +02:00
|
|
|
eval $c_pack
|
2007-07-09 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set status $msg
|
|
|
|
set prefix $msg
|
|
|
|
set units $uds
|
2007-07-09 04:48:19 +02:00
|
|
|
set meter {}
|
2007-07-09 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
method update {have total} {
|
|
|
|
set pdone 0
|
2012-01-21 18:57:28 +01:00
|
|
|
set cdone 0
|
2007-07-09 04:01:47 +02:00
|
|
|
if {$total > 0} {
|
|
|
|
set pdone [expr {100 * $have / $total}]
|
2007-09-26 21:31:42 +02:00
|
|
|
set cdone [expr {[winfo width $w_c] * $have / $total}]
|
2007-07-09 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
2007-09-26 21:31:42 +02:00
|
|
|
set prec [string length [format %i $total]]
|
|
|
|
set status [mc "%s ... %*i of %*i %s (%3i%%)" \
|
|
|
|
$prefix \
|
|
|
|
$prec $have \
|
|
|
|
$prec $total \
|
|
|
|
$units $pdone]
|
|
|
|
$w_c coords bar 0 0 $cdone 20
|
2007-07-09 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
2007-07-09 04:48:19 +02:00
|
|
|
method update_meter {buf} {
|
|
|
|
append meter $buf
|
|
|
|
set r [string last "\r" $meter]
|
|
|
|
if {$r == -1} {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
set prior [string range $meter 0 $r]
|
|
|
|
set meter [string range $meter [expr {$r + 1}] end]
|
2007-10-20 20:16:15 +02:00
|
|
|
set p "\\((\\d+)/(\\d+)\\)"
|
|
|
|
if {[regexp ":\\s*\\d+% $p\(?:, done.\\s*\n|\\s*\r)\$" $prior _j a b]} {
|
|
|
|
update $this $a $b
|
|
|
|
} elseif {[regexp "$p\\s+done\r\$" $prior _j a b]} {
|
2007-07-09 04:48:19 +02:00
|
|
|
update $this $a $b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
method stop {{msg {}}} {
|
2007-07-09 04:01:47 +02:00
|
|
|
destroy $w_c
|
2007-07-09 04:48:19 +02:00
|
|
|
if {$msg ne {}} {
|
|
|
|
set status $msg
|
|
|
|
}
|
2007-07-09 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
2007-07-09 04:06:33 +02:00
|
|
|
method show {msg {test {}}} {
|
|
|
|
if {$test eq {} || $status eq $test} {
|
|
|
|
set status $msg
|
|
|
|
}
|
2007-07-09 04:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
method _delete {current} {
|
|
|
|
if {$current eq $w} {
|
|
|
|
delete_this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|