#!/afs/ece/usr/tcl/bin/wish -f

set Bind_Keyword [file tail [info script]]
source "[file dirname [info script]]/../aux/frame.tcl"

# Help text.
set Help "" ; append Help {Commandeth -- Add command execution capability to an application

This program teaches widgets how to execute wish or shell commands. They can
take the input and give the output back to the Text or Entry widget of any
program.

} $TH_Bindings_Help {

Widgets of Commandeth

Temporary File Entry

The command module uses a temporary file to do exec commands. This specifies a
good name to use for this temporary file.


Print Command

This specifies the default command value for the print command. Note that in
the default form, the user should enter a string to be the title of the
printout.


Mail Command

This specifies the default command value for the mail command. Note that in the
default form, the user should enter a string to be the subject of the message,
and then add one or more recipients for the message to be mailed to.

} $TH_Frame_Help {
The print command takes the raw text as input...any tags in the text will be
ignored.
}


# Gives app all the code necessary to do our functions.
proc teach_code {app widget} {
  set class [send $app winfo class $widget]
  if {[widget_bindings $app $widget] == ""} {return}

  include_files $app {command.tcl th_cmd_wish} \
	[list "edit.$class.tcl" "th_[set class]_undoable_insert"] \
	[list "browse.$class.tcl" "th_[set class]_goto"]
  teach_frame_code $app $widget

  global Tmpfile Print Mail
  do_cmd $app "set TH(Cmd,Default,Print) \"$Print\"\n" 0
  do_cmd $app "set TH(Cmd,Default,Mail) \"$Mail\"\n" 0
  do_cmd $app "set TH(Tmpfile) \"$Tmpfile\"\n" 0
}

# For a widget, returns the appropriate bindings. (They will depend on the
# widget)
proc widget_bindings {app w} {
  global Bindings
  if {[lsearch {Entry Text} [send $app winfo class $w]] == -1} {return ""}
  set bindings $Bindings(Cmd)
  return [widget_frame_bindings $bindings]
}


create_form_entry .cmdtmp "Temporary File" Tmpfile "/tmp/th.cmd.tmp"
bind .cmdtmp.e <Tab> "th_Entry_complete_multiple %W [list [concat \
       {{th_line_complete th_filter_glob none}} $Entry_Completions]]"
create_form_entry .cmdprint "Print Command" Print "| lpr -m -p -T "
create_form_entry .cmdmail "Mail Command" Mail "| mail -s "


