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_toplevel top w -autodelete 0
34 wm title $top "[appname] ([reponame]): $t_short"
44 -textvariable @t_long \
49 -background white -borderwidth 1 \
51 -width 80 -height 10 \
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..."] \
61 pack $w.m.l1 -side top -fill x
62 pack $w.m.s -side bottom -fill x
63 pack $w_t -side left -fill both -expand 1
64 pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
66 menu $w.ctxm -tearoff 0
67 $w.ctxm add command -label [mc "Copy"] \
68 -command "tk_textCopy $w_t"
69 $w.ctxm add command -label [mc "Select All"] \
70 -command "focus $w_t;$w_t tag add sel 0.0 end"
71 $w.ctxm add command -label [mc "Copy All"] \
73 $w_t tag add sel 0.0 end
75 $w_t tag remove sel 0.0 end
79 button $w.ok -text [mc "Close"] \
81 -command [list destroy $w]
82 pack $w.ok -side bottom -anchor e -pady 10 -padx 10
83 bind $w <Visibility> [list focus $w]
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"
91 method exec {cmd {after {}}} {
92 if {[lindex $cmd 0] eq {git}} {
93 set fd_f [eval git_read --stderr [lrange $cmd 1 end]]
96 set fd_f [_open_stdout_stderr $cmd]
98 fconfigure $fd_f -blocking 0 -translation binary
99 fileevent $fd_f readable [cb _read $fd_f $after]
102 method _read {fd after} {
105 if {![winfo exists $w_t]} {_init $this}
106 $w_t conf -state normal
108 set n [string length $buf]
110 set cr [string first "\r" $buf $c]
111 set lf [string first "\n" $buf $c]
112 if {$cr < 0} {set cr [expr {$n + 1}]}
113 if {$lf < 0} {set lf [expr {$n + 1}]}
116 $w_t insert end [string range $buf $c $lf]
117 set console_cr [$w_t index {end -1c}]
121 $w_t delete $console_cr end
123 $w_t insert end [string range $buf $c [expr {$cr - 1}]]
128 $w_t conf -state disabled
132 fconfigure $fd -blocking 1
134 if {[catch {close $fd}]} {
140 uplevel #0 $after $ok
146 fconfigure $fd -blocking 0
149 method chain {cmdlist {ok 1}} {
151 if {[llength $cmdlist] == 0} {
156 set cmd [lindex $cmdlist 0]
157 set cmdlist [lrange $cmdlist 1 end]
159 if {[lindex $cmd 0] eq {exec}} {
161 [lrange $cmd 1 end] \
164 uplevel #0 $cmd [cb chain $cmdlist]
171 method insert {txt} {
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
181 if {[winfo exists $w.m.s]} {
182 bind $w.m.s <Destroy> [list delete_this $this]
183 $w.m.s conf -background green -text [mc "Success"]
185 $w.ok conf -state normal
192 if {![winfo exists $w.m.s]} {
195 bind $w.m.s <Destroy> [list delete_this $this]
196 $w.m.s conf -background red -text [mc "Error: Command Failed"]
198 $w.ok conf -state normal
204 method _sb_set {sb orient first last} {
205 if {![winfo exists $sb]} {
206 if {$first == $last || ($first == 0 && $last == 1)} return
207 if {$orient eq {h}} {
208 scrollbar $sb -orient h -command [list $w_t xview]
209 pack $sb -fill x -side bottom -before $w_t
211 scrollbar $sb -orient v -command [list $w_t yview]
212 pack $sb -fill y -side right -before $w_t