git-gui: Extract blame viewer status bar into mega-widget
Our blame viewer has had a very fancy progress bar at the bottom of the window that shows the current status of the blame engine, which includes the number of lines completed as both a text and a graphical meter. I want to reuse this meter system in other places, such as during a branch switch where read-tree -v can give us a progress meter for any long-running operation. This change extracts the code and refactors it as a widget that we can take advantage of in locations other than in the blame viewer. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 8, 2007 at 22:01 UTC
b29bd5ca3b0060513b7b96380fc43f7ab4f12156
2 files changed
+87
-41
lib/blame.tcl
+11
-41
@@ -21,7 +21,7 @@ field w_amov ; # text column: annotations + move tracking
21
field w_asim ; # text column: annotations (simple computation)
22
field w_file ; # text column: actual file data
23
field w_cviewer ; # pane showing commit message
24
-field status ; # text variable bound to status bar
24
+field status ; # status mega-widget instance
25
field old_height ; # last known height of $w.file_pane
26
27
# Tk UI colors
@@ -242,14 +242,7 @@ constructor new {i_commit i_path} {
242
pack $w.file_pane.cm.sbx -side bottom -fill x
243
pack $w_cviewer -expand 1 -fill both
244
245
- frame $w.status \
246
- -borderwidth 1 \
247
- -relief sunken
248
- label $w.status.l \
249
- -textvariable @status \
250
- -anchor w \
251
- -justify left
252
- pack $w.status.l -side left
245
+ set status [::status_bar::new $w.status]
246
247
menu $w.ctxm -tearoff 0
248
$w.ctxm add command \
@@ -360,19 +353,6 @@ method _load {jump} {
353
set total_lines 0
354
}
355
363
- if {[winfo exists $w.status.c]} {
364
- $w.status.c coords bar 0 0 0 20
365
- } else {
366
- canvas $w.status.c \
367
- -width 100 \
368
- -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
369
- -borderwidth 1 \
370
- -relief groove \
371
- -highlightt 0
372
- $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
373
- pack $w.status.c -side right
374
- }
375
-
356
if {$history eq {}} {
357
$w_back conf -state disabled
358
} else {
@@ -386,7 +366,7 @@ method _load {jump} {
366
set amov_data [list [list]]
367
set asim_data [list [list]]
368
389
- set status "Loading $commit:[escape_path $path]..."
369
+ $status show "Reading $commit:[escape_path $path]..."
370
$w_path conf -text [escape_path $path]
371
if {$commit eq {}} {
372
set fd [open $path r]
@@ -510,13 +490,16 @@ method _exec_blame {cur_w cur_d options cur_s} {
490
lappend cmd -- $path
491
set fd [open "| $cmd" r]
492
fconfigure $fd -blocking 0 -translation lf -encoding binary
513
- fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d $cur_s]
493
+ fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
494
set current_fd $fd
495
set blame_lines 0
516
- _status $this $cur_s
496
+
497
+ $status start \
498
+ "Loading$cur_s annotations..." \
499
+ {lines annotated}
500
}
501
519
-method _read_blame {fd cur_w cur_d cur_s} {
502
+method _read_blame {fd cur_w cur_d} {
503
upvar #0 $cur_d line_data
504
variable group_colors
505
variable original_options
@@ -697,26 +680,13 @@ method _read_blame {fd cur_w cur_d cur_s} {
680
{ original location}
681
} else {
682
set current_fd {}
700
- set status {Annotation complete.}
701
- destroy $w.status.c
683
+ $status stop {Annotation complete.}
684
}
685
} else {
704
- _status $this $cur_s
686
+ $status update $blame_lines $total_lines
687
}
688
} ifdeleted { catch {close $fd} }
689
708
-method _status {cur_s} {
709
- set have $blame_lines
710
- set total $total_lines
711
- set pdone 0
712
- if {$total} {set pdone [expr {100 * $have / $total}]}
713
-
714
- set status [format \
715
- "Loading%s annotations... %i of %i lines annotated (%2i%%)" \
716
- $cur_s $have $total $pdone]
717
- $w.status.c coords bar 0 0 $pdone 20
718
-}
719
-
690
method _click {cur_w pos} {
691
set lno [lindex [split [$cur_w index $pos] .] 0]
692
_showcommit $this $cur_w $lno
lib/status_bar.tcl
new
+76
@@ -0,0 +1,76 @@
1
+# git-gui status bar mega-widget
2
+# Copyright (C) 2007 Shawn Pearce
3
+
4
+class status_bar {
5
+
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 status {}; # single line of text we show
10
+field prefix {}; # text we format into status
11
+field units {}; # unit of progress
12
+
13
+constructor 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
+
31
+method 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
+
50
+method 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
+
61
+method stop {msg} {
62
+ destroy $w_c
63
+ set status $msg
64
+}
65
+
66
+method show {msg} {
67
+ set status $msg
68
+}
69
+
70
+method _delete {current} {
71
+ if {$current eq $w} {
72
+ delete_this
73
+ }
74
+}
75
+
76
+}