#!/usr/local/bin/wish -f
# jdoc - multi-font document display
# 
# Copyright (c) 1992-1994 by Jay Sekora.  All rights reserved, except that
# this file may be redistributed without fee for personal noncommercial
# use.

## begin boiler_header

global VERSION
set VERSION {3.6/3.0}

if {[info exists env(JSTOOLS_LIB)]} {
  set jstools_library $env(JSTOOLS_LIB)
} else {
  set jstools_library /usr/local/lib/jstools
}

# add the jstools library to the library search path:

set auto_path [concat [list $jstools_library] $auto_path]

# check for ~/.tk and prepend it to the auto_path if it exists.
# that way the user can override and customise the jstools libraries.

if {[file isdirectory ~/.tk]} then {
  set auto_path [concat [list [glob ~/.tk]] $auto_path]
}

## end boiler_header

# TO DO:
#   alternate definitions of all the section, rm, tt, etc. procedures to
#     allow man pages, PostScript, and TeX to be generated from the same
#     source (in libraries)

# CHANGES
#   NO LONGER allow `jhelp edit.tk', `jhelp jlibrary', etc.; help file
#     must match exactly with '.jdoc' suffix (no longer .tkhelp)
#   list help topics if no topic specified
#   `topic' menu
#   added `tcl command' entry

### ### ##############################################################################
### ### # section - section title (stick in menu)
### ### #   this is used in the help files (scripts)
### ### ##############################################################################
### ### 
### ### proc section {title body} {
### ###   .menu.sections.m add command -label $title -command [format {
### ###     global CURRENTSECTION
### ###     set CURRENTSECTION {%s}
### ###     .t configure -state normal
### ###     j:rt text .t
### ###     hl $CURRENTSECTION
### ###     par
### ###     eval {%s}
### ###     .t configure -state disabled
### ###     j:rt:done
### ###   } $title $body]
### ### }
### ### 
### ### ##############################################################################
### ### # qsection - section title (stick in menu)
### ### #   this is used in the help files (scripts)
### ### #   this is the `quick' section command, which is less human-readable
### ### ##############################################################################
### ### 
### ### proc qsection {title text state} {
### ###   .menu.sections.m add command -label $title -command [format {
### ###     global CURRENTSECTION
### ###     .t configure -state normal
### ###     set title {%s}
### ###     set CURRENTSECTION $title
### ###     j:rt text .t
### ###     .t insert 1.0 %s
### ###     jdoc:set_state .t {%s}
### ###     .t mark set insert 1.0
### ###     hl $title
### ###     par
### ###     .t configure -state disabled
### ###     j:rt:done
### ###   } $title $text $state]
### ### }


##############################################################################
# FINAL SETUP
##############################################################################

jdoc:init


######################################################################
######################################################################
### WHY DOES THIS HAVE TO BE HERE?  IT'S CALLED IN j:jstools_init! ###
######################################################################
######################################################################

                        # set user's text bindings:
                        global J_PREFS
                        switch -exact $J_PREFS(bindings) {
                          basic {
                            j:eb:basic_bind Entry
                          }
                          emacs {
                            j:eb:emacs_bind Entry
                          }
                          vi {
                            j:eb:vi_bind Entry
                          }
                        }

# read in user's .tk/jdocrc.tcl and .tk/jdoc-defaults files:
#
j:source_config jdocrc.tcl		;# just source the file, if any
j:read_global_prefs			;# get defaults from ~/.tk/defaults
j:read_prefs -array JDOC_PREFS -file jdoc-defaults {
  {textwidth 70}
  {textheight 24}
  {textwrap char}
  {textbg white}
  {textfg black}
  {textsb black}
  {textsf white}
  {textbw 2}
  {textsbw 2}
}

jdoc:mkmenus
jdoc:mkbuttons
jdoc:mktext					;# (sets focus)
jdoc:mkbindings .t
jdoc:first_doc_file				;# read in first help file
