git-gui: Avoid console scrollbars unless they are necessary
We shouldn't create scrollbars for the horziontal or vertical sides unless there is enough content to make it worth drawing these widgets on screen. This way users don't loose screen space to objects that won't help them navigate the display. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Sep 23, 2007 at 05:25 UTC
fbc8a93cd5b03bf15a3ebef6c0a512d2da3df7c4
1 file changed
+48
-30
lib/console.tcl
+48
-30
@@ -6,6 +6,7 @@ class console {
6
field t_short
7
field t_long
8
field w
9
+field w_t
10
field console_cr
11
field is_toplevel 1; # are we our own window?
12
@@ -36,6 +37,7 @@ method _init {} {
37
}
38
39
set console_cr 1.0
40
+ set w_t $w.m.t
41
42
frame $w.m
43
label $w.m.l1 \
@@ -43,38 +45,34 @@ method _init {} {
45
-anchor w \
46
-justify left \
47
-font font_uibold
46
- text $w.m.t \
48
+ text $w_t \
49
-background white -borderwidth 1 \
50
-relief sunken \
51
-width 80 -height 10 \
52
-wrap none \
53
-font font_diff \
54
-state disabled \
53
- -xscrollcommand [list $w.m.sbx set] \
54
- -yscrollcommand [list $w.m.sby set]
55
+ -xscrollcommand [cb _sb_set $w.m.sbx h] \
56
+ -yscrollcommand [cb _sb_set $w.m.sby v]
57
label $w.m.s -text [mc "Working... please wait..."] \
58
-anchor w \
59
-justify left \
60
-font font_uibold
59
- scrollbar $w.m.sbx -command [list $w.m.t xview] -orient h
60
- scrollbar $w.m.sby -command [list $w.m.t yview]
61
pack $w.m.l1 -side top -fill x
62
pack $w.m.s -side bottom -fill x
63
- pack $w.m.sbx -side bottom -fill x
64
- pack $w.m.sby -side right -fill y
65
- pack $w.m.t -side left -fill both -expand 1
63
+ pack $w_t -side left -fill both -expand 1
64
pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
65
66
menu $w.ctxm -tearoff 0
67
$w.ctxm add command -label [mc "Copy"] \
70
- -command "tk_textCopy $w.m.t"
68
+ -command "tk_textCopy $w_t"
69
$w.ctxm add command -label [mc "Select All"] \
72
- -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
70
+ -command "focus $w_t;$w_t tag add sel 0.0 end"
71
$w.ctxm add command -label [mc "Copy All"] \
72
-command "
75
- $w.m.t tag add sel 0.0 end
76
- tk_textCopy $w.m.t
77
- $w.m.t tag remove sel 0.0 end
73
+ $w_t tag add sel 0.0 end
74
+ tk_textCopy $w_t
75
+ $w_t tag remove sel 0.0 end
76
"
77
78
if {$is_toplevel} {
@@ -85,9 +83,9 @@ method _init {} {
83
bind $w <Visibility> [list focus $w]
84
}
85
88
- bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
89
- bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
90
- bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
86
+ bind_button3 $w_t "tk_popup $w.ctxm %X %Y"
87
+ bind $w_t <$M1B-Key-a> "$w_t tag add sel 0.0 end;break"
88
+ bind $w_t <$M1B-Key-A> "$w_t tag add sel 0.0 end;break"
89
}
90
91
method exec {cmd {after {}}} {
@@ -104,8 +102,8 @@ method exec {cmd {after {}}} {
102
method _read {fd after} {
103
set buf [read $fd]
104
if {$buf ne {}} {
107
- if {![winfo exists $w.m.t]} {_init $this}
108
- $w.m.t conf -state normal
105
+ if {![winfo exists $w_t]} {_init $this}
106
+ $w_t conf -state normal
107
set c 0
108
set n [string length $buf]
109
while {$c < $n} {
@@ -115,20 +113,20 @@ method _read {fd after} {
113
if {$lf < 0} {set lf [expr {$n + 1}]}
114
115
if {$lf < $cr} {
118
- $w.m.t insert end [string range $buf $c $lf]
119
- set console_cr [$w.m.t index {end -1c}]
116
+ $w_t insert end [string range $buf $c $lf]
117
+ set console_cr [$w_t index {end -1c}]
118
set c $lf
119
incr c
120
} else {
123
- $w.m.t delete $console_cr end
124
- $w.m.t insert end "\n"
125
- $w.m.t insert end [string range $buf $c $cr]
121
+ $w_t delete $console_cr end
122
+ $w_t insert end "\n"
123
+ $w_t insert end [string range $buf $c $cr]
124
set c $cr
125
incr c
126
}
127
}
130
- $w.m.t conf -state disabled
131
- $w.m.t see end
128
+ $w_t conf -state disabled
129
+ $w_t see end
130
}
131
132
fconfigure $fd -blocking 1
@@ -171,11 +169,11 @@ method chain {cmdlist {ok 1}} {
169
}
170
171
method insert {txt} {
174
- if {![winfo exists $w.m.t]} {_init $this}
175
- $w.m.t conf -state normal
176
- $w.m.t insert end "$txt\n"
177
- set console_cr [$w.m.t index {end -1c}]
178
- $w.m.t conf -state disabled
172
+ if {![winfo exists $w_t]} {_init $this}
173
+ $w_t conf -state normal
174
+ $w_t insert end "$txt\n"
175
+ set console_cr [$w_t index {end -1c}]
176
+ $w_t conf -state disabled
177
}
178
179
method done {ok} {
@@ -200,4 +198,24 @@ method done {ok} {
198
delete_this
199
}
200
201
+method _sb_set {sb orient first last} {
202
+ if {$first == 0 && $last == 1} {
203
+ if {[winfo exists $sb]} {
204
+ destroy $sb
205
+ }
206
+ return
207
+ }
208
+
209
+ if {![winfo exists $sb]} {
210
+ if {$orient eq {h}} {
211
+ scrollbar $sb -orient h -command [list $w_t xview]
212
+ pack $sb -fill x -side bottom -before $w_t
213
+ } else {
214
+ scrollbar $sb -orient v -command [list $w_t yview]
215
+ pack $sb -fill y -side right -before $w_t
216
+ }
217
+ }
218
+ catch {$sb set $first $last}
219
+}
220
+
221
}