]> asedeno.scripts.mit.edu Git - git.git/blobdiff - lib/console.tcl
Merge branch 'maint'
[git.git] / lib / console.tcl
index 34de5d48593be91fed3b97e66f1a8d9dc06acfdf..e5f9ba429b0f0ba15d922aa26624493502d1da27 100644 (file)
@@ -7,6 +7,7 @@ field t_short
 field t_long
 field w
 field console_cr
+field is_toplevel    1; # are we our own window?
 
 constructor new {short_title long_title} {
        set t_short $short_title
@@ -15,10 +16,25 @@ constructor new {short_title long_title} {
        return $this
 }
 
+constructor embed {path title} {
+       set t_short {}
+       set t_long $title
+       set w $path
+       set is_toplevel 0
+       _init $this
+       return $this
+}
+
 method _init {} {
        global M1B
-       make_toplevel top w -autodelete 0
-       wm title $top "[appname] ([reponame]): $t_short"
+
+       if {$is_toplevel} {
+               make_toplevel top w -autodelete 0
+               wm title $top "[appname] ([reponame]): $t_short"
+       } else {
+               frame $w
+       }
+
        set console_cr 1.0
 
        frame $w.m
@@ -36,7 +52,7 @@ method _init {} {
                -state disabled \
                -xscrollcommand [list $w.m.sbx set] \
                -yscrollcommand [list $w.m.sby set]
-       label $w.m.s -text {Working... please wait...} \
+       label $w.m.s -text [mc "Working... please wait..."] \
                -anchor w \
                -justify left \
                -font font_uibold
@@ -50,42 +66,37 @@ method _init {} {
        pack $w.m -side top -fill both -expand 1 -padx 5 -pady 10
 
        menu $w.ctxm -tearoff 0
-       $w.ctxm add command -label "Copy" \
+       $w.ctxm add command -label [mc "Copy"] \
                -command "tk_textCopy $w.m.t"
-       $w.ctxm add command -label "Select All" \
+       $w.ctxm add command -label [mc "Select All"] \
                -command "focus $w.m.t;$w.m.t tag add sel 0.0 end"
-       $w.ctxm add command -label "Copy All" \
+       $w.ctxm add command -label [mc "Copy All"] \
                -command "
                        $w.m.t tag add sel 0.0 end
                        tk_textCopy $w.m.t
                        $w.m.t tag remove sel 0.0 end
                "
 
-       button $w.ok -text {Close} \
-               -state disabled \
-               -command "destroy $w"
-       pack $w.ok -side bottom -anchor e -pady 10 -padx 10
+       if {$is_toplevel} {
+               button $w.ok -text [mc "Close"] \
+                       -state disabled \
+                       -command [list destroy $w]
+               pack $w.ok -side bottom -anchor e -pady 10 -padx 10
+               bind $w <Visibility> [list focus $w]
+       }
 
        bind_button3 $w.m.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.m.t <$M1B-Key-A> "$w.m.t tag add sel 0.0 end;break"
-       bind $w <Visibility> "focus $w"
 }
 
 method exec {cmd {after {}}} {
-       # -- Cygwin's Tcl tosses the enviroment when we exec our child.
-       #    But most users need that so we have to relogin. :-(
-       #
-       if {[is_Cygwin]} {
-               set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
+       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]
        }
-
-       # -- Tcl won't let us redirect both stdout and stderr to
-       #    the same pipe.  So pass it through cat...
-       #
-       set cmd [concat | $cmd |& cat]
-
-       set fd_f [open $cmd r]
        fconfigure $fd_f -blocking 0 -translation binary
        fileevent $fd_f readable [cb _read $fd_f $after]
 }
@@ -159,20 +170,32 @@ method chain {cmdlist {ok 1}} {
        }
 }
 
+method insert {txt} {
+       if {![winfo exists $w.m.t]} {_init $this}
+       $w.m.t conf -state normal
+       $w.m.t insert end "$txt\n"
+       set console_cr [$w.m.t index {end -1c}]
+       $w.m.t conf -state disabled
+}
+
 method done {ok} {
        if {$ok} {
                if {[winfo exists $w.m.s]} {
-                       $w.m.s conf -background green -text {Success}
-                       $w.ok conf -state normal
-                       focus $w.ok
+                       $w.m.s conf -background green -text [mc "Success"]
+                       if {$is_toplevel} {
+                               $w.ok conf -state normal
+                               focus $w.ok
+                       }
                }
        } else {
                if {![winfo exists $w.m.s]} {
                        _init $this
                }
-               $w.m.s conf -background red -text {Error: Command Failed}
-               $w.ok conf -state normal
-               focus $w.ok
+               $w.m.s conf -background red -text [mc "Error: Command Failed"]
+               if {$is_toplevel} {
+                       $w.ok conf -state normal
+                       focus $w.ok
+               }
        }
        delete_this
 }