1 # git-gui console support
2 # Copyright (C) 2006, 2007 Shawn Pearce
11 field is_toplevel
1; # are we our own window?
13 constructor new
{short_title long_title
} {
14 set t_short
$short_title
15 set t_long
$long_title
20 constructor embed
{path title
} {
33 make_dialog top w
-autodelete 0
34 wm title
$top "[appname] ([reponame]): $t_short"
43 ${NS
}::label $w.m.l1
\
44 -textvariable @t_long
\
53 -width 80 -height 10 \
57 -xscrollcommand [cb _sb_set
$w.m.sbx h
] \
58 -yscrollcommand [cb _sb_set
$w.m.sby v
]
59 label $w.m.s
-text [mc
"Working... please wait..."] \
63 pack $w.m.l1
-side top
-fill x
64 pack $w.m.s
-side bottom
-fill x
65 pack $w_t -side left
-fill both
-expand 1
66 pack $w.m
-side top
-fill both
-expand 1 -padx 5 -pady 10
68 menu $w.ctxm
-tearoff 0
69 $w.ctxm add command
-label [mc
"Copy"] \
70 -command "tk_textCopy $w_t"
71 $w.ctxm add command
-label [mc
"Select All"] \
72 -command "focus $w_t;$w_t tag add sel 0.0 end"
73 $w.ctxm add command
-label [mc
"Copy All"] \
75 $w_t tag add sel 0.0 end
77 $w_t tag remove sel 0.0 end
81 ${NS
}::button $w.ok
-text [mc
"Close"] \
83 -command [list destroy $w]
84 pack $w.ok
-side bottom
-anchor e
-pady 10 -padx 10
85 bind $w <Visibility
> [list focus $w]
88 bind_button3
$w_t "tk_popup $w.ctxm %X %Y"
89 bind $w_t <$M1B-Key
-a
> "$w_t tag add sel 0.0 end;break"
90 bind $w_t <$M1B-Key
-A
> "$w_t tag add sel 0.0 end;break"
93 method
exec {cmd
{after {}}} {
94 if {[lindex $cmd 0] eq
{git
}} {
95 set fd_f
[eval git_read
--stderr [lrange $cmd 1 end
]]
98 set fd_f
[_open_stdout_stderr
$cmd]
100 fconfigure $fd_f -blocking 0 -translation binary
101 fileevent $fd_f readable
[cb _read
$fd_f $after]
104 method _read
{fd
after} {
107 if {![winfo exists
$w_t]} {_init
$this}
108 $w_t conf
-state normal
110 set n
[string length
$buf]
112 set cr
[string first
"\r" $buf $c]
113 set lf
[string first
"\n" $buf $c]
114 if {$cr < 0} {set cr
[expr {$n + 1}]}
115 if {$lf < 0} {set lf
[expr {$n + 1}]}
118 $w_t insert end
[string range
$buf $c $lf]
119 set console_cr
[$w_t index
{end
-1c}]
123 $w_t delete
$console_cr end
125 $w_t insert end
[string range
$buf $c [expr {$cr - 1}]]
130 $w_t conf
-state disabled
134 fconfigure $fd -blocking 1
136 if {[catch {close $fd}]} {
142 uplevel #0 $after $ok
148 fconfigure $fd -blocking 0
151 method chain
{cmdlist
{ok
1}} {
153 if {[llength $cmdlist] == 0} {
158 set cmd
[lindex $cmdlist 0]
159 set cmdlist
[lrange $cmdlist 1 end
]
161 if {[lindex $cmd 0] eq
{exec}} {
163 [lrange $cmd 1 end
] \
166 uplevel #0 $cmd [cb chain $cmdlist]
173 method insert
{txt
} {
174 if {![winfo exists
$w_t]} {_init
$this}
175 $w_t conf
-state normal
176 $w_t insert end
"$txt\n"
177 set console_cr
[$w_t index
{end
-1c}]
178 $w_t conf
-state disabled
183 if {[winfo exists
$w.m.s
]} {
184 bind $w.m.s
<Destroy
> [list delete_this
$this]
185 $w.m.s conf
-background green
-foreground black
\
188 $w.ok conf
-state normal
195 if {![winfo exists
$w.m.s
]} {
198 bind $w.m.s
<Destroy
> [list delete_this
$this]
199 $w.m.s conf
-background red
-foreground black
\
200 -text [mc
"Error: Command Failed"]
202 $w.ok conf
-state normal
207 bind $w <Key-Escape
> "destroy $w;break"
210 method _sb_set
{sb orient first last
} {
212 if {![winfo exists
$sb]} {
213 if {$first == $last ||
($first == 0 && $last == 1)} return
214 if {$orient eq
{h
}} {
215 ${NS
}::scrollbar $sb -orient h
-command [list $w_t xview
]
216 pack $sb -fill x
-side bottom
-before $w_t
218 ${NS
}::scrollbar $sb -orient v
-command [list $w_t yview
]
219 pack $sb -fill y
-side right
-before $w_t