#! /bin/sh -f
# The next line is executed by /bin/sh, but not Tcl \
exec guiwish -f $0 ${1+"$@"}

if [file executable guiBuilder] {
  set env(GUI_BUILDER) $env(PWD)
} else {
  set env(GUI_BUILDER) [file dirname [exec which guiBuilder]]
}

source $env(GUI_BUILDER)/hyper_text.tcl

catch "source $env(GUI_BUILDER)/help_src.tcl"
catch "source $env(GUI_BUILDER)/Private/help_src.tcl"

set general_help {/bHelp Index/m. 
Press one of the following buttons to get more help.

- /B "Creating Widgets" "show_help create_widget_help" /D
- /B "Configuring Widgets" "show_help Configure" /D
- /B "Moving Widgets" "show_help Moving" /D
- /B "Resizing Widgets" "show_help Resizing" /D
- /B "Marking Widgets" "show_help Marking" /D
- /B "Adding Procedures and Bindings" "show_help Proc_bind" /D
- /B "Changing Defaults" "show_help defaults" /D
- /B "Saving/Loading and Testing" "show_help save_load" /D
- /B "Creating Menus" "show_help menus" /D
- /B "Composite Widgets" "show_help composites" /D
- /B "Ask Sean Halliday" "show_help mail_sean" -background green -activebackground lightgreen /D
- /B "Ask the Mailing List" "show_help mail_list" -background green -activebackground lightgreen /D

- /B "Making your own help like this." "show_help help_this"
}

if ![info exists in_help] {
  source $env(GUI_BUILDER)/Help.tcl
  set index 0
  set max 0
  .top0.f8.b3 config -state disabled -text "Back" -command back
  .top0.f8.b4 config -state disabled -text "Forward" -command forward
  .top0.f8.b5 config -text "Reload" -command {uplevel #0 {
     source guiHelp
     eval "set help $$stack($index)"
     parse_hyper_text .top0.t1 $help
  }}
}

proc back {} {
  global index stack max
  if {$index > 0} {
    set index [expr $index-1]
    if {$index == 1} {.top0.f8.b3 config -state disabled}
    .top0.f8.b4 config -state normal
    global $stack($index)
    eval "set help $$stack($index)"
    parse_hyper_text .top0.t1 $help
  }
}

proc forward {} {
  global index stack max
  if {$index < $max} {
    incr index
    if {$index == $max} {.top0.f8.b4 config -state disabled}
    global $stack($index)
    eval "set help $$stack($index)"
    parse_hyper_text .top0.t1 $help
    .top0.f8.b3 config -state normal
  }
}

set user "______"
catch "set user \[exec whoami\]"

set get_help "	GuiBuilder will continue to be /bFREE/m software.  GuiBuilder Help and GuiBuilder Tutorial are available in English for \$50 Canadian.  Send E-mail to /bhalliday@cs.sfu.ca/m for details and exceptions. 

You can edit this text and send it to Sean Halliday.

	Sean,

		(your text here)

Your's truly, $user

/B \"Send Mail\" mail_me /D

/B \"Help Index\" \"show_help general_help\" -background #8080ff -activebackground #a0a0ff /D"

set mail_sean "
You can edit this text and send it to Sean Halliday.

Sean,

        How do you ... ?

Your's truly, $user

/B \"Send Mail\" mail_me /D

/B \"Help Index\" \"show_help general_help\" -background #8080ff -activebackground #a0a0ff /D"

set mail_sent {Mail sent!

/B "Help Index" "show_help general_help" -background #8080ff -activebackground #a0a0ff /D}

set mail_list "You can edit this text and send it to GuiBuilder Mailing list.

Someone,

        How do you ... ?
Your's truly, $user

/B \"Send Mail\" mail_the_list /D

/B \"Help Index\" \"show_help general_help\" -background #8080ff -activebackground #a0a0ff /D"

proc mail_me {} {
  set file [open "/tmp/mail_sean" "w"]
  puts $file "Mail sent from guiHelp"
  puts $file [.top0.t1 get 0.0 end]
  close $file
  exec mail halliday@cs.sfu.ca < /tmp/mail_sean &
  show_help mail_sent
  exec rm /tmp/mail_sean
}

proc mail_the_list {} {
  set file [open "/tmp/mail_tclgui" "w"]
  puts $file "Mail sent from guiHelp"
  puts $file [.top0.t1 get 0.0 end]
  close $file
  exec mail tclgui@banffcentre.ab.ca < /tmp/mail_tclgui &
  exec rm /tmp/mail_tclgui
  show_help mail_sent
}



proc show_help {help} {
  global $help index stack max get_help
  incr index
  set stack($index) $help
  if {$index > 1} {.top0.f8.b3 config -state normal}
  if {$index < $max} {.top0.f8.b4 config -state normal}
  if {$index > $max} {set max $index}
  set C [catch "set help $$help"]
  if {$C == 1} {
    parse_hyper_text .top0.t1 $get_help
  } else {
    parse_hyper_text .top0.t1 $help
  }
}

if ![info exists in_help] {show_help general_help}
set in_help 1
