
proc detachCmd {} {

# $Header: /home/cvsroot/tcldb/wisql/Tlib/detachCmd,v 1.2 1998/05/20 17:16:10 de Exp $
    global CmdText execCmd

    set w .editSql
    catch {destroy $w}
    toplevel $w -class Dialog
    wm title $w "Edit SQL Query"
    wm geometry $w "+150+150"
    wm iconname $w "SQLcmd"
    wm minsize $w 200 200
    wm maxsize $w 900 900

    set ext sql
    set cc [$CmdText get 1.0 end]
    set CmdText $w.top.txt

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

    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 -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 "$cc"

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

    button $w.bot.dismiss -text Done -command "set CmdText .m.s.sql; destroy $w" -padx 0 -pady 0

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

	
	button $w.bot.doit -text "Execute" -command {eval $execCmd} -padx 0 -pady 0
	bind $w.top.txt <Control-n> "prevSql 1"
	bind $w.top.txt <Control-p> "prevSql -1"
	bind $w.top.txt <Shift-Return> "$w.bot.doit invoke"
	pack $w.bot.doit -side left -ipadx 10 -ipady 10
 	pack $w.bot.save -side left -ipadx 10 -ipady 10
  	pack $w.bot.filew -side left -ipady 10
  	pack $w.bot.read -side left -ipadx 10 -ipady 10
 	pack $w.bot.filer -side left -ipady 10
 	pack $w.bot.dismiss -side right -ipadx 20 -ipady 10

    update

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

}
