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>
This commit is contained in:
@ -6,6 +6,7 @@ class console {
|
|||||||
field t_short
|
field t_short
|
||||||
field t_long
|
field t_long
|
||||||
field w
|
field w
|
||||||
|
field w_t
|
||||||
field console_cr
|
field console_cr
|
||||||
field is_toplevel 1; # are we our own window?
|
field is_toplevel 1; # are we our own window?
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ method _init {} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set console_cr 1.0
|
set console_cr 1.0
|
||||||
|
set w_t $w.m.t
|
||||||
|
|
||||||
frame $w.m
|
frame $w.m
|
||||||
label $w.m.l1 \
|
label $w.m.l1 \
|
||||||
@ -43,38 +45,34 @@ method _init {} {
|
|||||||
-anchor w \
|
-anchor w \
|
||||||
-justify left \
|
-justify left \
|
||||||
-font font_uibold
|
-font font_uibold
|
||||||
text $w.m.t \
|
text $w_t \
|
||||||
-background white -borderwidth 1 \
|
-background white -borderwidth 1 \
|
||||||
-relief sunken \
|
-relief sunken \
|
||||||
-width 80 -height 10 \
|
-width 80 -height 10 \
|
||||||
-wrap none \
|
-wrap none \
|
||||||
-font font_diff \
|
-font font_diff \
|
||||||
-state disabled \
|
-state disabled \
|
||||||
-xscrollcommand [list $w.m.sbx set] \
|
-xscrollcommand [cb _sb_set $w.m.sbx h] \
|
||||||
-yscrollcommand [list $w.m.sby set]
|
-yscrollcommand [cb _sb_set $w.m.sby v]
|
||||||
label $w.m.s -text [mc "Working... please wait..."] \
|
label $w.m.s -text [mc "Working... please wait..."] \
|
||||||
-anchor w \
|
-anchor w \
|
||||||
-justify left \
|
-justify left \
|
||||||
-font font_uibold
|
-font font_uibold
|
||||||
scrollbar $w.m.sbx -command [list $w.m.t xview] -orient h
|
|
||||||
scrollbar $w.m.sby -command [list $w.m.t yview]
|
|
||||||
pack $w.m.l1 -side top -fill x
|
pack $w.m.l1 -side top -fill x
|
||||||
pack $w.m.s -side bottom -fill x
|
pack $w.m.s -side bottom -fill x
|
||||||
pack $w.m.sbx -side bottom -fill x
|
pack $w_t -side left -fill both -expand 1
|
||||||
pack $w.m.sby -side right -fill y
|
|
||||||
pack $w.m.t -side left -fill both -expand 1
|
|
||||||
pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
|
pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
|
||||||
|
|
||||||
menu $w.ctxm -tearoff 0
|
menu $w.ctxm -tearoff 0
|
||||||
$w.ctxm add command -label [mc "Copy"] \
|
$w.ctxm add command -label [mc "Copy"] \
|
||||||
-command "tk_textCopy $w.m.t"
|
-command "tk_textCopy $w_t"
|
||||||
$w.ctxm add command -label [mc "Select All"] \
|
$w.ctxm add command -label [mc "Select All"] \
|
||||||
-command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
|
-command "focus $w_t;$w_t tag add sel 0.0 end"
|
||||||
$w.ctxm add command -label [mc "Copy All"] \
|
$w.ctxm add command -label [mc "Copy All"] \
|
||||||
-command "
|
-command "
|
||||||
$w.m.t tag add sel 0.0 end
|
$w_t tag add sel 0.0 end
|
||||||
tk_textCopy $w.m.t
|
tk_textCopy $w_t
|
||||||
$w.m.t tag remove sel 0.0 end
|
$w_t tag remove sel 0.0 end
|
||||||
"
|
"
|
||||||
|
|
||||||
if {$is_toplevel} {
|
if {$is_toplevel} {
|
||||||
@ -85,9 +83,9 @@ method _init {} {
|
|||||||
bind $w <Visibility> [list focus $w]
|
bind $w <Visibility> [list focus $w]
|
||||||
}
|
}
|
||||||
|
|
||||||
bind_button3 $w.m.t "tk_popup $w.ctxm %X %Y"
|
bind_button3 $w_t "tk_popup $w.ctxm %X %Y"
|
||||||
bind $w.m.t <$M1B-Key-a> "$w.m.t tag add sel 0.0 end;break"
|
bind $w_t <$M1B-Key-a> "$w_t tag add sel 0.0 end;break"
|
||||||
bind $w.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
|
bind $w_t <$M1B-Key-A> "$w_t tag add sel 0.0 end;break"
|
||||||
}
|
}
|
||||||
|
|
||||||
method exec {cmd {after {}}} {
|
method exec {cmd {after {}}} {
|
||||||
@ -104,8 +102,8 @@ method exec {cmd {after {}}} {
|
|||||||
method _read {fd after} {
|
method _read {fd after} {
|
||||||
set buf [read $fd]
|
set buf [read $fd]
|
||||||
if {$buf ne {}} {
|
if {$buf ne {}} {
|
||||||
if {![winfo exists $w.m.t]} {_init $this}
|
if {![winfo exists $w_t]} {_init $this}
|
||||||
$w.m.t conf -state normal
|
$w_t conf -state normal
|
||||||
set c 0
|
set c 0
|
||||||
set n [string length $buf]
|
set n [string length $buf]
|
||||||
while {$c < $n} {
|
while {$c < $n} {
|
||||||
@ -115,20 +113,20 @@ method _read {fd after} {
|
|||||||
if {$lf < 0} {set lf [expr {$n + 1}]}
|
if {$lf < 0} {set lf [expr {$n + 1}]}
|
||||||
|
|
||||||
if {$lf < $cr} {
|
if {$lf < $cr} {
|
||||||
$w.m.t insert end [string range $buf $c $lf]
|
$w_t insert end [string range $buf $c $lf]
|
||||||
set console_cr [$w.m.t index {end -1c}]
|
set console_cr [$w_t index {end -1c}]
|
||||||
set c $lf
|
set c $lf
|
||||||
incr c
|
incr c
|
||||||
} else {
|
} else {
|
||||||
$w.m.t delete $console_cr end
|
$w_t delete $console_cr end
|
||||||
$w.m.t insert end "\n"
|
$w_t insert end "\n"
|
||||||
$w.m.t insert end [string range $buf $c $cr]
|
$w_t insert end [string range $buf $c $cr]
|
||||||
set c $cr
|
set c $cr
|
||||||
incr c
|
incr c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$w.m.t conf -state disabled
|
$w_t conf -state disabled
|
||||||
$w.m.t see end
|
$w_t see end
|
||||||
}
|
}
|
||||||
|
|
||||||
fconfigure $fd -blocking 1
|
fconfigure $fd -blocking 1
|
||||||
@ -171,11 +169,11 @@ method chain {cmdlist {ok 1}} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
method insert {txt} {
|
method insert {txt} {
|
||||||
if {![winfo exists $w.m.t]} {_init $this}
|
if {![winfo exists $w_t]} {_init $this}
|
||||||
$w.m.t conf -state normal
|
$w_t conf -state normal
|
||||||
$w.m.t insert end "$txt\n"
|
$w_t insert end "$txt\n"
|
||||||
set console_cr [$w.m.t index {end -1c}]
|
set console_cr [$w_t index {end -1c}]
|
||||||
$w.m.t conf -state disabled
|
$w_t conf -state disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
method done {ok} {
|
method done {ok} {
|
||||||
@ -200,4 +198,24 @@ method done {ok} {
|
|||||||
delete_this
|
delete_this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
method _sb_set {sb orient first last} {
|
||||||
|
if {$first == 0 && $last == 1} {
|
||||||
|
if {[winfo exists $sb]} {
|
||||||
|
destroy $sb
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if {![winfo exists $sb]} {
|
||||||
|
if {$orient eq {h}} {
|
||||||
|
scrollbar $sb -orient h -command [list $w_t xview]
|
||||||
|
pack $sb -fill x -side bottom -before $w_t
|
||||||
|
} else {
|
||||||
|
scrollbar $sb -orient v -command [list $w_t yview]
|
||||||
|
pack $sb -fill y -side right -before $w_t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {$sb set $first $last}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user