home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jedit_prefs.tcl < prev    next >
Encoding:
Text File  |  1995-02-08  |  8.9 KB  |  330 lines

  1. # jedit_prefs.tcl - preferences commands and procs for jedit
  2. #   (jedit:prefs:menus is in jedit_menus.tcl, for convenience.)
  3. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  4. # that this file may be freely redistributed in whole or in part 
  5. # for non-profit, noncommercial use.
  6.  
  7. # TO DO
  8. #   MAKE ALL THIS PER-WINDOW!
  9. #   file_modes panel
  10. #   word-end punctuation (and heuristics) sd be mode-specific
  11.  
  12. ######################################################################
  13.  
  14.  
  15.  
  16. ######################################################################
  17. # editor-wide preferences panel
  18. #   { t args } lets it be used with j:tkb:mkmap
  19. ######################################################################
  20.  
  21. proc jedit:cmd:edit_prefs { t args } {
  22.   global JEDIT_PREFS
  23.   
  24.   set w .edit_prefs
  25.   toplevel $w
  26.   wm title $w "Editor Preferences"
  27.   
  28.   j:colour_chooser $w.textbg -variable JEDIT_PREFS(textbg) \
  29.     -label "Normal Background:"
  30.   j:colour_chooser $w.textfg -variable JEDIT_PREFS(textfg) \
  31.     -label "Normal Foreground:"
  32.   j:colour_chooser $w.textsb -variable JEDIT_PREFS(textsb) \
  33.     -label "Selected Background:"
  34.   j:colour_chooser $w.textsf -variable JEDIT_PREFS(textsf) \
  35.     -label "Selected Foreground:"
  36.   
  37.   label $w.textiw-label -text "Insert Width:" -anchor w
  38.   scale $w.textiw -from 1 -to 25 -orient horizontal \
  39.     -command {set JEDIT_PREFS(textiw)}
  40.   $w.textiw set $JEDIT_PREFS(textiw)
  41.   
  42.   label $w.textsbw-label -text "Selection Border Width:" -anchor w
  43.   scale $w.textsbw -from 0 -to 25  -orient horizontal \
  44.     -command {set JEDIT_PREFS(textsbw)}
  45.   $w.textsbw set $JEDIT_PREFS(textsbw)
  46.   
  47.   label $w.textbw-label -text "Text Border Width:" -anchor w
  48.   scale $w.textbw -from 0 -to 50  -orient horizontal \
  49.     -command {set JEDIT_PREFS(textbw)}
  50.   $w.textbw set $JEDIT_PREFS(textbw)
  51.   
  52.   label $w.undolevels-label -text "Undo Levels:" -anchor w
  53.   scale $w.undolevels -from 0 -to 10  -orient horizontal \
  54.     -command {set JEDIT_PREFS(undolevels)}
  55.   $w.undolevels set $JEDIT_PREFS(undolevels)
  56.   
  57.   j:buttonbar $w.b -default save -buttons [format {
  58.     {
  59.       save Save {
  60.         j:write_prefs -array JEDIT_PREFS -directory $env(HOME)/.tk \
  61.           -file jedit-defaults
  62.         %s.b.done invoke
  63.       }
  64.     } {
  65.       done Done {
  66.         jedit:apply_all_prefs [jedit:text_to_top %s]
  67.         destroy %s
  68.       }
  69.     }
  70.   } $w $t $w]
  71.   
  72.   pack \
  73.     $w.textbg \
  74.     [j:rule $w] \
  75.     $w.textfg \
  76.     [j:rule $w] \
  77.     $w.textsb \
  78.     [j:rule $w] \
  79.     $w.textsf \
  80.     [j:rule $w] \
  81.     $w.textiw-label $w.textiw \
  82.     [j:filler $w] \
  83.     $w.textsbw-label $w.textsbw \
  84.     [j:filler $w] \
  85.     $w.textbw-label $w.textbw \
  86.     [j:rule $w] \
  87.     $w.undolevels-label $w.undolevels \
  88.     [j:rule $w] \
  89.     $w.b \
  90.     -fill x
  91.   
  92.   j:dialogue $w
  93.   j:default_button $w.b.save $w
  94.   focus $w
  95.   tkwait window $w
  96. }
  97. ######################################################################
  98. # jedit:cmd:mode_prefs - mode-specific preferences panel
  99. #   { t args } lets it be used with j:tkb:mkmap
  100. ######################################################################
  101.  
  102. proc jedit:cmd:mode_prefs { t args } {
  103.   global JEDIT_MODEPREFS env tk_strictMotif
  104.   
  105.   set mode [jedit:get_mode $t]
  106.   
  107.   set window [jedit:text_to_top $t]
  108.  
  109.   toplevel .mode_prefs
  110.   wm title .mode_prefs "Mode\255Specific Preferences"
  111.   
  112.   label .mode_prefs.mode -text "Preferences for mode \"$mode\""
  113.   
  114.   pack .mode_prefs.mode -expand y -fill x
  115.   
  116.   j:buttonbar .mode_prefs.b -default save -buttons [format {
  117.     {
  118.       save Save {
  119.         set tmp_mode %s
  120.         j:write_prefs -array JEDIT_MODEPREFS -prefix $tmp_mode \
  121.           -directory $env(HOME)/.tk/jeditmodes \
  122.           -file ${tmp_mode}-defaults
  123.         .mode_prefs.b.done invoke
  124.       }
  125.     } {
  126.       done Done {
  127.         set tmp_mode %s
  128.         if {$JEDIT_MODEPREFS($tmp_mode,textwidth) < 20} {
  129.           set JEDIT_MODEPREFS($tmp_mode,textwidth) 20
  130.         }
  131.         if {$JEDIT_MODEPREFS($tmp_mode,textheight) < 4} {
  132.           set JEDIT_MODEPREFS($tmp_mode,textheight) 4
  133.         }
  134.         jedit:apply_all_prefs %s
  135.         destroy .mode_prefs
  136.       }
  137.     }
  138.   } $mode $mode $window]
  139.   
  140.   frame .mode_prefs.ui_prefs
  141.   lower .mode_prefs.ui_prefs
  142.   frame .mode_prefs.other_prefs
  143.   lower .mode_prefs.other_prefs
  144.   pack \
  145.     [j:rule .mode_prefs] \
  146.     [jedit:prefs:menus .mode_prefs.menus $mode] \
  147.     [j:rule .mode_prefs] \
  148.     [jedit:prefs:buttonbar .mode_prefs.buttonbar $mode] \
  149.     -in .mode_prefs.ui_prefs -fill both
  150.   pack \
  151.     [j:rule .mode_prefs] \
  152.     [jedit:prefs:io .mode_prefs.io $mode] \
  153.     [j:rule .mode_prefs] \
  154.     [jedit:prefs:autokeys .mode_prefs.autokeys $mode] \
  155.     [j:rule .mode_prefs] \
  156.     [jedit:prefs:abbrevs .mode_prefs.abbrevs $mode] \
  157.     [j:rule .mode_prefs] \
  158.     [jedit:prefs:wrap .mode_prefs.wrap $mode] \
  159.     [j:rule .mode_prefs] \
  160.     [jedit:prefs:font .mode_prefs.font $mode] \
  161.     [j:rule .mode_prefs] \
  162.     [jedit:prefs:size .mode_prefs.size $mode] \
  163.     -in .mode_prefs.other_prefs -fill both
  164.   pack \
  165.     .mode_prefs.b \
  166.     [j:rule .mode_prefs] \
  167.     -fill x -side bottom
  168.   pack \
  169.     .mode_prefs.ui_prefs \
  170.     [j:rule .mode_prefs] \
  171.     .mode_prefs.other_prefs \
  172.     -side left -fill y
  173.   
  174.   j:dialogue .mode_prefs        ;# position in centre of screen
  175.  
  176.   focus .mode_prefs
  177.   j:default_button .mode_prefs.b.save \
  178.     .mode_prefs.font.bot.e \
  179.     .mode_prefs.size.we \
  180.     .mode_prefs.size.he \
  181.     .mode_prefs
  182.  
  183.   j:tab_ring \
  184.     .mode_prefs.font.bot.e \
  185.     .mode_prefs.size.we \
  186.     .mode_prefs.size.he
  187.   
  188.   bind .mode_prefs <Key-Tab> {focus .mode_prefs.font.bot.e}
  189.   tkwait window .mode_prefs
  190. }
  191.  
  192. proc jedit:prefs:buttonbar { w mode } {
  193.   global JEDIT_MODEPREFS
  194.   
  195.   frame $w
  196.   checkbutton $w.cb -relief flat -anchor w \
  197.     -text {Show button bar} \
  198.     -variable JEDIT_MODEPREFS($mode,buttonbar)
  199.   pack $w.cb -side top -expand yes -fill x
  200.   
  201.   return $w
  202. }
  203.  
  204. proc jedit:prefs:io { w mode } {
  205.   global JEDIT_MODEPREFS
  206.   
  207.   frame $w
  208.   checkbutton $w.cb -relief flat -anchor w \
  209.     -text {Save/load highlighting and position} \
  210.     -variable JEDIT_MODEPREFS($mode,savestate)
  211.   pack $w.cb -side top -expand yes -fill x
  212.   
  213.   return $w
  214. }
  215.  
  216. proc jedit:prefs:autokeys { w mode } {
  217.   global JEDIT_MODEPREFS
  218.   
  219.   frame $w
  220.   checkbutton $w.autobreak_cb -relief flat -anchor w \
  221.     -text {Break long lines with <Space>} \
  222.     -variable JEDIT_MODEPREFS($mode,autobreak)
  223.   checkbutton $w.autoindent_cb -relief flat -anchor w \
  224.     -text {Preserve indentation with <Return>} \
  225.     -variable JEDIT_MODEPREFS($mode,autoindent)
  226.   checkbutton $w.parenflash_cb -relief flat -anchor w \
  227.     -text {Flash matching braces, brackets, and parentheses} \
  228.     -variable JEDIT_MODEPREFS($mode,parenflash)
  229.   pack \
  230.     $w.autobreak_cb \
  231.     $w.autoindent_cb \
  232.     $w.parenflash_cb \
  233.     -side top -expand yes -fill x
  234.   
  235.   return $w
  236. }
  237.  
  238. proc jedit:prefs:abbrevs { w mode } {
  239.   global JEDIT_MODEPREFS
  240.   
  241.   frame $w
  242.   checkbutton $w.sabbrev_cb -relief flat -anchor w \
  243.     -text {Expand static abbreviations with <Space>} \
  244.     -variable JEDIT_MODEPREFS($mode,sabbrev)
  245.   checkbutton $w.dabbrev_cb -relief flat -anchor w \
  246.     -text {Expand dynamic abbreviations with <Tab>} \
  247.     -variable JEDIT_MODEPREFS($mode,dabbrev)
  248.   pack \
  249.     $w.sabbrev_cb \
  250.     $w.dabbrev_cb \
  251.     -side top -expand yes -fill x
  252.   
  253.   return $w
  254. }
  255.  
  256. proc jedit:prefs:wrap { w mode } {
  257.   global JEDIT_MODEPREFS
  258.   
  259.   frame $w
  260.   radiobutton $w.none -relief flat -anchor w \
  261.     -text {Don't wrap lines} \
  262.     -variable JEDIT_MODEPREFS($mode,textwrap) -value none
  263.   radiobutton $w.char -relief flat -anchor w \
  264.     -text {Wrap lines on character boundaries} \
  265.     -variable JEDIT_MODEPREFS($mode,textwrap) -value char
  266.   radiobutton $w.word -relief flat -anchor w \
  267.     -text {Wrap lines at word boundaries} \
  268.     -variable JEDIT_MODEPREFS($mode,textwrap) -value word
  269.   pack \
  270.     $w.none \
  271.     $w.char \
  272.     $w.word \
  273.     -side top -expand yes -fill x
  274.   
  275.   return $w
  276. }
  277.  
  278. proc jedit:prefs:font { w mode } {
  279.   global JEDIT_MODEPREFS
  280.   
  281.   frame $w
  282.   
  283.   frame $w.top
  284.   label $w.top.l -text {Font:}
  285.   button $w.top.default -width 8 -text {Default} -command {
  286.     set JEDIT_MODEPREFS($mode,textfont) {default}
  287.   }
  288.   button $w.top.choose -text {Choose . . .} -command {
  289.     set JEDIT_MODEPREFS($mode,textfont) [j:prompt_font]
  290.   }
  291.   
  292.   frame $w.bot
  293.   entry $w.bot.e -relief sunken -width 50 \
  294.     -textvariable JEDIT_MODEPREFS($mode,textfont)
  295.   
  296.   pack $w.top.l -side left
  297.   pack $w.top.choose -side right -padx 10 -pady 5
  298.   pack $w.top.default -side right -pady 5
  299.   
  300.   pack $w.bot.e -side left -padx 10 -pady 5
  301.   
  302.   pack \
  303.     $w.top \
  304.     $w.bot \
  305.     -side top -expand yes -fill x
  306.   
  307.   return $w
  308. }
  309.  
  310. proc jedit:prefs:size { w mode } {
  311.   global JEDIT_MODEPREFS
  312.   
  313.   frame $w
  314.   label $w.wl -text {Width:}
  315.   entry $w.we -relief sunken -width 5 \
  316.     -textvariable JEDIT_MODEPREFS($mode,textwidth)
  317.   label $w.hl -text {Height:}
  318.   entry $w.he -relief sunken -width 5 \
  319.     -textvariable JEDIT_MODEPREFS($mode,textheight)
  320.   
  321.   pack $w.wl -side left -fill x -pady 5
  322.   pack $w.we -side left -pady 5
  323.   pack $w.hl -side left -fill x -pady 5
  324.   pack $w.he -side left -pady 5
  325.   
  326.   return $w
  327. }
  328.  
  329.