2007-05-08 11:35:48 +08:00
|
|
|
# git-gui console support
|
|
|
|
# Copyright (C) 2006, 2007 Shawn Pearce
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
class console {
|
|
|
|
|
|
|
|
field t_short
|
|
|
|
field t_long
|
|
|
|
field w
|
2007-09-23 17:25:13 +08:00
|
|
|
field w_t
|
2007-05-09 08:33:47 +08:00
|
|
|
field console_cr
|
2007-07-05 14:23:53 +08:00
|
|
|
field is_toplevel 1; # are we our own window?
|
2007-05-09 08:33:47 +08:00
|
|
|
|
|
|
|
constructor new {short_title long_title} {
|
|
|
|
set t_short $short_title
|
|
|
|
set t_long $long_title
|
|
|
|
_init $this
|
|
|
|
return $this
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
|
2007-07-05 14:23:53 +08:00
|
|
|
constructor embed {path title} {
|
|
|
|
set t_short {}
|
|
|
|
set t_long $title
|
|
|
|
set w $path
|
|
|
|
set is_toplevel 0
|
|
|
|
_init $this
|
|
|
|
return $this
|
|
|
|
}
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
method _init {} {
|
2007-05-01 14:59:53 +08:00
|
|
|
global M1B
|
2007-07-05 14:23:53 +08:00
|
|
|
|
|
|
|
if {$is_toplevel} {
|
|
|
|
make_toplevel top w -autodelete 0
|
|
|
|
wm title $top "[appname] ([reponame]): $t_short"
|
|
|
|
} else {
|
|
|
|
frame $w
|
|
|
|
}
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
set console_cr 1.0
|
2007-09-23 17:25:13 +08:00
|
|
|
set w_t $w.m.t
|
2007-05-08 11:35:48 +08:00
|
|
|
|
|
|
|
frame $w.m
|
2007-05-09 08:33:47 +08:00
|
|
|
label $w.m.l1 \
|
|
|
|
-textvariable @t_long \
|
2007-05-08 11:35:48 +08:00
|
|
|
-anchor w \
|
|
|
|
-justify left \
|
|
|
|
-font font_uibold
|
2007-09-23 17:25:13 +08:00
|
|
|
text $w_t \
|
2008-03-06 00:54:22 +08:00
|
|
|
-background white \
|
|
|
|
-foreground black \
|
|
|
|
-borderwidth 1 \
|
2007-05-08 11:35:48 +08:00
|
|
|
-relief sunken \
|
|
|
|
-width 80 -height 10 \
|
2007-07-09 23:14:00 +08:00
|
|
|
-wrap none \
|
2007-05-08 11:35:48 +08:00
|
|
|
-font font_diff \
|
|
|
|
-state disabled \
|
2007-09-23 17:25:13 +08:00
|
|
|
-xscrollcommand [cb _sb_set $w.m.sbx h] \
|
|
|
|
-yscrollcommand [cb _sb_set $w.m.sby v]
|
2007-07-21 20:21:34 +08:00
|
|
|
label $w.m.s -text [mc "Working... please wait..."] \
|
2007-05-08 11:35:48 +08:00
|
|
|
-anchor w \
|
|
|
|
-justify left \
|
|
|
|
-font font_uibold
|
|
|
|
pack $w.m.l1 -side top -fill x
|
|
|
|
pack $w.m.s -side bottom -fill x
|
2007-09-23 17:25:13 +08:00
|
|
|
pack $w_t -side left -fill both -expand 1
|
2007-05-08 11:35:48 +08:00
|
|
|
pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
|
|
|
|
|
|
|
|
menu $w.ctxm -tearoff 0
|
2007-07-21 20:21:34 +08:00
|
|
|
$w.ctxm add command -label [mc "Copy"] \
|
2007-09-23 17:25:13 +08:00
|
|
|
-command "tk_textCopy $w_t"
|
2007-07-21 20:21:34 +08:00
|
|
|
$w.ctxm add command -label [mc "Select All"] \
|
2007-09-23 17:25:13 +08:00
|
|
|
-command "focus $w_t;$w_t tag add sel 0.0 end"
|
2007-07-21 20:21:34 +08:00
|
|
|
$w.ctxm add command -label [mc "Copy All"] \
|
2007-05-08 11:35:48 +08:00
|
|
|
-command "
|
2007-09-23 17:25:13 +08:00
|
|
|
$w_t tag add sel 0.0 end
|
|
|
|
tk_textCopy $w_t
|
|
|
|
$w_t tag remove sel 0.0 end
|
2007-05-08 11:35:48 +08:00
|
|
|
"
|
|
|
|
|
2007-07-05 14:23:53 +08:00
|
|
|
if {$is_toplevel} {
|
2007-07-21 20:21:34 +08:00
|
|
|
button $w.ok -text [mc "Close"] \
|
2007-07-05 14:23:53 +08:00
|
|
|
-state disabled \
|
|
|
|
-command [list destroy $w]
|
|
|
|
pack $w.ok -side bottom -anchor e -pady 10 -padx 10
|
|
|
|
bind $w <Visibility> [list focus $w]
|
|
|
|
}
|
2007-05-08 11:35:48 +08:00
|
|
|
|
2007-09-23 17:25:13 +08:00
|
|
|
bind_button3 $w_t "tk_popup $w.ctxm %X %Y"
|
|
|
|
bind $w_t <$M1B-Key-a> "$w_t tag add sel 0.0 end;break"
|
|
|
|
bind $w_t <$M1B-Key-A> "$w_t tag add sel 0.0 end;break"
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
method exec {cmd {after {}}} {
|
2007-07-09 15:07:05 +08:00
|
|
|
if {[lindex $cmd 0] eq {git}} {
|
|
|
|
set fd_f [eval git_read --stderr [lrange $cmd 1 end]]
|
|
|
|
} else {
|
|
|
|
lappend cmd 2>@1
|
|
|
|
set fd_f [_open_stdout_stderr $cmd]
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
fconfigure $fd_f -blocking 0 -translation binary
|
2007-05-09 08:33:47 +08:00
|
|
|
fileevent $fd_f readable [cb _read $fd_f $after]
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
method _read {fd after} {
|
2007-05-08 11:35:48 +08:00
|
|
|
set buf [read $fd]
|
|
|
|
if {$buf ne {}} {
|
2007-09-23 17:25:13 +08:00
|
|
|
if {![winfo exists $w_t]} {_init $this}
|
|
|
|
$w_t conf -state normal
|
2007-05-08 11:35:48 +08:00
|
|
|
set c 0
|
|
|
|
set n [string length $buf]
|
|
|
|
while {$c < $n} {
|
|
|
|
set cr [string first "\r" $buf $c]
|
|
|
|
set lf [string first "\n" $buf $c]
|
|
|
|
if {$cr < 0} {set cr [expr {$n + 1}]}
|
|
|
|
if {$lf < 0} {set lf [expr {$n + 1}]}
|
|
|
|
|
|
|
|
if {$lf < $cr} {
|
2007-09-23 17:25:13 +08:00
|
|
|
$w_t insert end [string range $buf $c $lf]
|
|
|
|
set console_cr [$w_t index {end -1c}]
|
2007-05-08 11:35:48 +08:00
|
|
|
set c $lf
|
|
|
|
incr c
|
|
|
|
} else {
|
2007-09-23 17:25:13 +08:00
|
|
|
$w_t delete $console_cr end
|
|
|
|
$w_t insert end "\n"
|
2007-10-21 08:43:36 +08:00
|
|
|
$w_t insert end [string range $buf $c [expr {$cr - 1}]]
|
2007-05-08 11:35:48 +08:00
|
|
|
set c $cr
|
|
|
|
incr c
|
|
|
|
}
|
|
|
|
}
|
2007-09-23 17:25:13 +08:00
|
|
|
$w_t conf -state disabled
|
|
|
|
$w_t see end
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fconfigure $fd -blocking 1
|
|
|
|
if {[eof $fd]} {
|
|
|
|
if {[catch {close $fd}]} {
|
|
|
|
set ok 0
|
|
|
|
} else {
|
|
|
|
set ok 1
|
|
|
|
}
|
2007-05-01 14:59:53 +08:00
|
|
|
if {$after ne {}} {
|
2007-05-09 08:33:47 +08:00
|
|
|
uplevel #0 $after $ok
|
2007-05-01 14:59:53 +08:00
|
|
|
} else {
|
2007-05-09 08:33:47 +08:00
|
|
|
done $this $ok
|
2007-05-01 14:59:53 +08:00
|
|
|
}
|
2007-05-08 11:35:48 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
fconfigure $fd -blocking 0
|
|
|
|
}
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
method chain {cmdlist {ok 1}} {
|
2007-05-08 11:35:48 +08:00
|
|
|
if {$ok} {
|
|
|
|
if {[llength $cmdlist] == 0} {
|
2007-05-09 08:33:47 +08:00
|
|
|
done $this $ok
|
2007-05-08 11:35:48 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
set cmd [lindex $cmdlist 0]
|
|
|
|
set cmdlist [lrange $cmdlist 1 end]
|
|
|
|
|
2007-05-01 14:59:53 +08:00
|
|
|
if {[lindex $cmd 0] eq {exec}} {
|
2007-05-09 08:33:47 +08:00
|
|
|
exec $this \
|
|
|
|
[lrange $cmd 1 end] \
|
|
|
|
[cb chain $cmdlist]
|
2007-05-08 11:35:48 +08:00
|
|
|
} else {
|
2007-05-09 08:33:47 +08:00
|
|
|
uplevel #0 $cmd [cb chain $cmdlist]
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
2007-05-09 08:33:47 +08:00
|
|
|
done $this $ok
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-09 06:40:56 +08:00
|
|
|
method insert {txt} {
|
2007-09-23 17:25:13 +08:00
|
|
|
if {![winfo exists $w_t]} {_init $this}
|
|
|
|
$w_t conf -state normal
|
|
|
|
$w_t insert end "$txt\n"
|
|
|
|
set console_cr [$w_t index {end -1c}]
|
|
|
|
$w_t conf -state disabled
|
2007-07-09 06:40:56 +08:00
|
|
|
}
|
|
|
|
|
2007-05-09 08:33:47 +08:00
|
|
|
method done {ok} {
|
2007-05-08 11:35:48 +08:00
|
|
|
if {$ok} {
|
2007-05-09 08:33:47 +08:00
|
|
|
if {[winfo exists $w.m.s]} {
|
2007-09-27 02:05:54 +08:00
|
|
|
bind $w.m.s <Destroy> [list delete_this $this]
|
2008-03-06 00:54:22 +08:00
|
|
|
$w.m.s conf -background green -foreground black \
|
|
|
|
-text [mc "Success"]
|
2007-07-05 14:23:53 +08:00
|
|
|
if {$is_toplevel} {
|
|
|
|
$w.ok conf -state normal
|
|
|
|
focus $w.ok
|
|
|
|
}
|
2007-09-27 02:05:54 +08:00
|
|
|
} else {
|
|
|
|
delete_this
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
2007-05-09 08:33:47 +08:00
|
|
|
if {![winfo exists $w.m.s]} {
|
|
|
|
_init $this
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
2007-09-27 02:05:54 +08:00
|
|
|
bind $w.m.s <Destroy> [list delete_this $this]
|
2008-03-06 00:54:22 +08:00
|
|
|
$w.m.s conf -background red -foreground black \
|
|
|
|
-text [mc "Error: Command Failed"]
|
2007-07-05 14:23:53 +08:00
|
|
|
if {$is_toplevel} {
|
|
|
|
$w.ok conf -state normal
|
|
|
|
focus $w.ok
|
|
|
|
}
|
2007-05-08 11:35:48 +08:00
|
|
|
}
|
|
|
|
}
|
2007-05-01 14:59:53 +08:00
|
|
|
|
2007-09-23 17:25:13 +08:00
|
|
|
method _sb_set {sb orient first last} {
|
|
|
|
if {![winfo exists $sb]} {
|
2007-09-27 02:16:45 +08:00
|
|
|
if {$first == $last || ($first == 0 && $last == 1)} return
|
2007-09-23 17:25:13 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2007-09-27 02:16:45 +08:00
|
|
|
$sb set $first $last
|
2007-09-23 17:25:13 +08:00
|
|
|
}
|
|
|
|
|
2007-05-01 14:59:53 +08:00
|
|
|
}
|