proc mkEdit {tt at bt nam ext} {

# $Header: /home/cvsroot/tcldb/ucodb/Tlib/mkEdit,v 1.13 1999/06/16 20:09:13 de Exp $
#	global datahelping Retn

    global Script StopScript

    if {$nam == ""} {
    set w .alertbox
    } else {
    set w .$nam
    }
    catch {destroy $w}
    toplevel $w -class Dialog
    wm title $w "$tt"
    wm geometry $w "+150+150"
    wm iconname $w "SQLcmd"
    wm minsize $w 200 200
    wm maxsize $w 1000 900

    frame $w.top -relief raised -border 1 -background antiquewhite
    frame $w.bot -relief raised -border 1 -background antiquewhite
    pack $w.top -side top -fill both -expand true 
    pack $w.bot -side top -fill x -expand true

    set tl [clength $at]

#   cap the max text box height
    set hgt [expr {$tl/40 + 5}]
    if {$hgt > 40} {set hgt 40}
#   floor the min text box height
    if {$hgt < 15} {set hgt 15}

    set font [getFont $w mediumcou]
    scrollbar $w.top.vert -relief sunken -command "$w.top.txt yview"  -orient vertical
    eval text $w.top.txt -font $font -wrap word -height $hgt -border 2 -relief sunken -yscroll \"$w.top.vert set\" -background ivory
    pack $w.top.vert -side right -fill y  
    pack $w.top.txt -side left -expand true -fill both -ipadx 5 -ipady 5

    $w.top.txt insert 1.0 "$at\n"

    button $w.bot.save -text "Save as:"  -command "editFile $w.top.txt \[$w.bot.filew get\] \"$ext\" w" -padx 1 -pady 1 -background lavender -activebackground lavender -activeforeground magenta2
    entry $w.bot.filew -relief sunken -width 20 -background ivory
    button $w.bot.read -text "Read from:" -command "editFile $w.top.txt \[$w.bot.filer get\] \"$ext\" r" -padx 1 -pady 1 -background lavender -activebackground lavender -activeforeground magenta2
    entry $w.bot.filer -relief sunken -width 20  -background ivory

	
    button $w.bot.dismiss -text $bt -command "destroy $w" -padx 0 -pady 0 \
	-background white -foreground red -activebackground black -activeforeground yellow

    button $w.bot.mail -text "Mail to:" -relief raised -border 2  -command "mailText $w.top.txt \[$w.bot.recip get\]" -padx 1 -pady 1 -background lavender -activebackground lavender -activeforeground magenta2
    entry $w.bot.recip -relief sunken -border 2 -width 20 -background ivory


#	If called from fosql with ctrl-mouse-3 on genericFind, then ...

	
      case $nam in {
	{findsql} {
	upvar #0 xess_connection xess
	if {$xess == 0} {
		isXess
	}
	button $w.bot.show -text "View data"  -command "doShow {} \[$w.top.txt get 1.0 end\]" -padx 0 -pady 0
	if {$xess} {
	button $w.bot.xess -text "-> Xess" -command "doXess {} \[$w.top.txt get 1.0 end\]" -padx 0 -pady 0
        pack $w.bot.show -side left -ipadx 10 -ipady 2
        pack $w.bot.save -side left -ipadx 10 -ipady 2
  	pack $w.bot.filew -side left -ipady 2
  	pack $w.bot.read -side left -ipadx 10 -ipady 2
	pack $w.bot.filer -side left -ipady 2
 	pack $w.bot.show -side left -ipadx 20 -ipady 2
   	pack $w.bot.xess -side left -ipadx 20 -ipady 2
  	pack $w.bot.dismiss -side right -ipadx 20 -ipady 2
	} else {
	pack $w.bot.show -side left -ipadx 10 -ipady 2
 	pack $w.bot.save -side left -ipadx 10 -ipady 2
  	pack $w.bot.filew -side left -ipady 2
  	pack $w.bot.read -side left -ipadx 10 -ipady 2
 	pack $w.bot.filer -side left -ipady 2
 	pack $w.bot.dismiss -side right -ipadx 20 -ipady 2
	}
	}
	{help} {
	$w.top.txt configure -state disabled
 	pack $w.bot.save -side left -ipadx 10 -ipady 2
  	pack $w.bot.filew -side left -ipady 2
	pack $w.bot.dismiss -expand true -ipadx 15 -ipady 2
	}
	{scriptEdit} {
	button $w.bot.doit -text "GO"  \
		-command "set Script 1; set StopScript 0; doUserCmd \[$w.top.txt get 1.0 end\] $w.top.txt; set Script 0; set StopScript 0" \
		-background gold -activebackground yellow \
		-padx 0 -pady 0 
	button $w.bot.stop -text "STOP" -command "kill SIGUSR1 [id process]" \
		-background white \
		-foreground red -activebackground black -activeforeground yellow \
		-padx 0 -pady 0
	pack $w.bot.doit -side left -ipadx 10 -ipady 2
	pack $w.bot.stop -side left -ipadx 10 -ipady 2
 	pack $w.bot.save -side left -ipadx 10 -ipady 2
  	pack $w.bot.filew -side left -ipady 2
  	pack $w.bot.read -side left -ipadx 10 -ipady 2
 	pack $w.bot.filer -side left -ipady 2
 	pack $w.bot.dismiss -side right -ipadx 20 -ipady 2
	}
	{cmdEdit} {
	button $w.bot.doit -text "Execute"  -command "doUserCmd \[$w.top.txt get 1.0 end\] $w.top.txt" -padx 0 -pady 0 -background gold -activebackground yellow
	bind $w.top.txt <Control-n> "rotCmd next"
	bind $w.top.txt <Control-p> "rotCmd prev"
	bind $w.top.txt <Shift-Return> "$w.bot.doit invoke"
	pack $w.bot.doit -side left -ipadx 10 -ipady 2
 	pack $w.bot.save -side left -ipadx 10 -ipady 2
  	pack $w.bot.filew -side left -ipady 2
  	pack $w.bot.read -side left -ipadx 10 -ipady 2
 	pack $w.bot.filer -side left -ipady 2
 	pack $w.bot.dismiss -side right -ipadx 20 -ipady 2
	}
    	{default} {
	pack $w.bot.dismiss -expand true -ipadx 15 -ipady 2
	pack $w.bot.mail -side left -ipadx 10 -ipady 2
	pack $w.bot.recip -side left -ipadx 10 -ipady 2
 	pack $w.bot.save -side left -ipadx 10 -ipady 2
  	pack $w.bot.filew -side left -ipady 2
  	pack $w.bot.read -side left -ipadx 10 -ipady 2
 	pack $w.bot.filer -side left -ipady 2
 	pack $w.bot.dismiss -side right -ipadx 20 -ipady 2
	}
    }
    update

#    bind $w <Return> "destroy $w"
    focus $w

}
