home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / HTML and CSS Modes / htmlPreferences.tcl < prev    next >
Encoding:
Text File  |  2001-01-14  |  34.1 KB  |  850 lines

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  HTML mode - tools for editing HTML documents
  4.  # 
  5.  #  FILE: "htmlPreferences.tcl"
  6.  #                                    created: 99-07-18 00.29.30 
  7.  #                                last update: 01-01-14 18.34.47 
  8.  #  Author: Johan Linde
  9.  #  E-mail: <alpha_www_tools@go.to>
  10.  #     www: <http://go.to/alpha_www_tools>
  11.  #  
  12.  # Version: 3.0
  13.  # 
  14.  # Copyright 1996-2001 by Johan Linde
  15.  #  
  16.  # This program is free software; you can redistribute it and/or modify
  17.  # it under the terms of the GNU General Public License as published by
  18.  # the Free Software Foundation; either version 2 of the License, or
  19.  # (at your option) any later version.
  20.  # 
  21.  # This program is distributed in the hope that it will be useful,
  22.  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.  # GNU General Public License for more details.
  25.  # 
  26.  # You should have received a copy of the GNU General Public License
  27.  # along with this program; if not, write to the Free Software
  28.  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  # 
  30.  # ###################################################################
  31.  ##
  32.  
  33. #===============================================================================
  34. # This file contains procs for settings preferences in HTML mode.
  35. #===============================================================================
  36.  
  37. # Dialog to set HTML mode variables.
  38. proc html::modifyFlags {{which General}} {
  39.     global HTMLmodeVars htmlIconTxt htmlIcons htmlMenu htmlUtilsMenu mode::features global::features mode
  40.     
  41.     set box [eval html::${which}PrefsBox]
  42.     set allFlags [eval html::${which}Flags]
  43.  
  44.     set attrTxt {"status bar" "dialog boxes"}
  45.     set manTxt {"first page in manual" "table of contents without frames" "table of contents with frames"}
  46.     set coltxt {"Simple coloring" "Complex coloring"}
  47.     set eh 0
  48.     if {$which == "Coloring"} {set eh 25}
  49.     set values [eval [concat dialog -w 465 -h [expr {315 + $eh}] -b OK 20 [expr {285 + $eh}] 85 [expr {305 + $eh}] \
  50.       -b Cancel 110 [expr {285 +$eh}] 175 [expr {305 + $eh}] $box]]
  51.     if {[lindex $values 1]} {return}
  52.     if {$which == "General" && [lindex $values 19] == [lindex $values 20]} {
  53.         alertnote "You can't use the same menu icon for both menus. Menu icon changes are ignored."
  54.         set allFlags [lrange $allFlags 0 15]
  55.     }
  56.     set i 1
  57.     if {$which == "General"} {incr i}
  58.     set haveShownColorAlert 0
  59.     foreach flag $allFlags {
  60.         global $flag
  61.         incr i
  62.         set val [lindex $values $i]
  63.         if {$flag == "useBigWindows" || $flag == "changeInBigWindows"} {set val [lsearch -exact $attrTxt $val]}
  64.         if {$flag == "manualStartPage"} {set val [lsearch -exact $manTxt $val]}
  65.         if {$flag == "simpleColoring"} {set val [expr {![lsearch -exact $coltxt $val]}]}
  66.         if {$flag == "dummyflag"} {continue}
  67.         if {[string match "*Icon" $flag]} {set val [lindex $htmlIcons [lsearch $htmlIconTxt $val]]}
  68.         if {$HTMLmodeVars($flag) != $val} {
  69.             if {$which == "Word"} {
  70.                 set $flag $val
  71.             }
  72.             set HTMLmodeVars($flag) $val
  73.             prefs::modifiedModeVar $flag HTML
  74.             if {[string match "*Color*" $flag]} {set haveShownColorAlert [html::ChangeColorizing $flag $haveShownColorAlert]}
  75.             if {[string match "*Icon" $flag]} {
  76.                 set themenu [string trim $flag "Icon"]
  77.                 catch {removeMenu [set $themenu]}
  78.                 set $themenu $val
  79.                 menu::buildSome $themenu
  80.                 if {[info exists mode::features($mode)] && [lcontains mode::features($mode) $themenu] || \
  81.                   [info exists global::features] && [lcontains global::features $themenu]} {insertMenu [set $themenu]}
  82.             }
  83.         }
  84.     }
  85. }
  86.  
  87. proc html::GeneralPrefsBox {} {
  88.     global HTMLmodeVars htmlIconTxt htmlIcons alpha::colors elecStopMarker
  89.     
  90.     set attrTxt {"status bar" "dialog boxes"}
  91.     set manTxt {"first page in manual" "table of contents without frames" "table of contents with frames"}
  92.  
  93.     set box "-t {General HTML mode Preferences} 100 10 450 30 \
  94.       -m {{Page 1 of preferences} {Page 1 of preferences} {Page 2 of preferences} {Page 3 of preferences}} 100 35 300 55 \
  95.       -n {Page 1 of preferences} \
  96.       -c {Bring browser to front when sending a window to it} $HTMLmodeVars(browseInForeground) 10 65 450 80\
  97.       -c {Save window without asking when sending it to the browser} $HTMLmodeVars(saveWithoutAsking) 10 85 450 100 \
  98.       -c {Set tags in lower case} $HTMLmodeVars(useLowerCase) 10 105 450 120 \
  99.       -c {Use template stops ($elecStopMarker)} $HTMLmodeVars(useTabMarks) 10 125 450 140 \
  100.       -c {Update META tags with NAME=\"DATE\" attribute when saving} $HTMLmodeVars(updateMetaDate) 10 145 450 160 \
  101.       -t {Give attributes in}  10 185 150 200\
  102.       -m {[list [lindex $attrTxt $HTMLmodeVars(useBigWindows)]] {dialog boxes} {status bar}} 155 185 450 205 \
  103.       -t {Change attributes in} 10 210 150 225 \
  104.       -m {[list [lindex $attrTxt $HTMLmodeVars(changeInBigWindows)]] {dialog boxes} {status bar}} 155 210 450 230 \
  105.       -c {Beep for first attribute (applies only if you use the status bar)} $HTMLmodeVars(promptNoisily) 10 235 450 250 \
  106.       -c {Flash status bar for first attribute} $HTMLmodeVars(flashStatusBar) 10 255 450 270 \
  107.       -n {Page 2 of preferences} \
  108.       -c {Auto-indent when typing > of a tag} $HTMLmodeVars(electricGreater) 10 85 450 100 \
  109.       -t {'Help' opens} 10 115 95 130 \
  110.       -m {[concat [list [lindex $manTxt $HTMLmodeVars(manualStartPage)]] $manTxt]} 100 115 450 135 \
  111.       -c {Create missing file without asking when cmd-double-clicking a link} $HTMLmodeVars(createWithoutAsking) 10 145 460 160 \
  112.       -c {Cmd-double-clicking on non-text file link opens file} $HTMLmodeVars(openNonTextFile) 10 165 450 180 \
  113.       -c {Return on non-text file in home page window opens file} $HTMLmodeVars(homeOpenNonTextFile) 10 185 450 200 \
  114.       -c {'Insert include tags' only inserts tags} $HTMLmodeVars(includeOnlyTags) 10 205 450 220 \
  115.       -t {'Last modified' text} 10 230 150 245 -e [list $HTMLmodeVars(lastModified)] 160 230 450 245 \
  116.       -n {Page 3 of preferences} \
  117.       -t {HTML menu icon:} 10 80 170 95 \
  118.       -m [list [concat [list [lindex $htmlIconTxt [lsearch $htmlIcons $HTMLmodeVars(htmlMenuIcon)]]] $htmlIconTxt]] 180 80 450 100 \
  119.       -t {HTML Utilities menu icon:} 10 105 170 120 \
  120.       -m [list [concat [list [lindex $htmlIconTxt [lsearch $htmlIcons $HTMLmodeVars(htmlUtilsMenuIcon)]]] $htmlIconTxt]] 180 105 450 125"
  121.     
  122.     return $box
  123. }
  124.  
  125. proc html::GeneralFlags {} {
  126.     return [list browseInForeground saveWithoutAsking useLowerCase useTabMarks updateMetaDate\
  127.     useBigWindows changeInBigWindows promptNoisily flashStatusBar electricGreater \
  128.     manualStartPage createWithoutAsking openNonTextFile \
  129.     homeOpenNonTextFile includeOnlyTags lastModified htmlMenuIcon htmlUtilsMenuIcon]
  130. }
  131.  
  132. proc html::ColoringPrefsBox {} {
  133.     global HTMLmodeVars alpha::colors
  134.     set coltxt {"Simple coloring" "Complex coloring"}
  135.     set box "-t {HTML mode Coloring Preferences} 100 10 450 30 \
  136.       -m {[concat [list [lindex $coltxt [expr {!$HTMLmodeVars(simpleColoring)}]]] $coltxt]} 100 35 450 55 \
  137.       -t {Color of HTML tags:} 10 65 150 80 \
  138.       -m [list [concat $HTMLmodeVars(tagColor) ${alpha::colors}]] 160 65 310 85 \
  139.       -n {Complex coloring} \
  140.       -t {Color of attributes:} 10 90 150 105 \
  141.       -m [list [concat $HTMLmodeVars(attributeColor) ${alpha::colors}]] 160 90 310 110 \
  142.       -t {Color of strings:} 10 115 150 130 \
  143.       -m [list [concat $HTMLmodeVars(stringColor) ${alpha::colors}]] 160 115 310 135 \
  144.       -r {Always color immediately when typing} $HTMLmodeVars(ColorImmediately) 10 140 300 155 \
  145.       -r {Coloring of best quality} [expr {!$HTMLmodeVars(ColorImmediately)}] 10 160 300 175 \
  146.       -c {Color JavaScript keywords} $HTMLmodeVars(JavaScriptColoring) 10 185 450 200\
  147.       -t {Color of JavaScript keywords:} 10 205 215 220 \
  148.       -m [list [concat $HTMLmodeVars(JavaScriptColor) ${alpha::colors}]] 220 205 360 225 \
  149.       -c {Color CSS keywords} $HTMLmodeVars(CSSColoring) 10 235 450 250\
  150.       -t {Color of CSS keywords:} 10 255 215 270 \
  151.       -m [list [concat $HTMLmodeVars(CSSColor) ${alpha::colors}]] 220 255 360 275 \
  152.       -t {Color of JavaScript and CSS comments:} 10 285 270 300 \
  153.       -m [list [concat $HTMLmodeVars(JavaCommentColor) ${alpha::colors}]] 275 285 420 305"
  154.  
  155.     return $box    
  156. }
  157.  
  158. proc html::ColoringFlags {} {
  159.     return [list simpleColoring tagColor attributeColor stringColor ColorImmediately dummyflag \
  160.       JavaScriptColoring JavaScriptColor CSSColoring CSSColor JavaCommentColor]
  161. }
  162.  
  163. proc html::CheckingPrefsBox {} {
  164.     global HTMLmodeVars
  165.     set box "-t {HTML mode Checking Links Preferences} 100 10 450 30 \
  166.       -t {These settings apply when you check links with Alpha:} 10 40 450 55 \
  167.       -c {Check anchors} $HTMLmodeVars(checkAnchors) 10 60 450 75 \
  168.       -c {Case sensitive checking (slower)} $HTMLmodeVars(caseSensitive) 10 80 450 95 \
  169.       -t {These settings apply when you check links with Big Brother:} 10 105 450 120\
  170.       -c {Bring Big Brother to front when checking links} $HTMLmodeVars(checkInFront) 10 125 450 140\
  171.       -c {Use Big Brother's link check options} $HTMLmodeVars(useBBoptions) 10 145 450 160\
  172.       -c {Ignore remote links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreRemote) 30 165 450 180\
  173.       -c {Ignore local links (if you don't use Big Brother's option)} $HTMLmodeVars(ignoreLocal) 30 185 450 200"
  174.     return $box
  175. }
  176.  
  177. proc html::CheckingFlags {} {
  178.     return [list checkAnchors caseSensitive checkInFront useBBoptions ignoreRemote ignoreLocal]
  179. }
  180.  
  181. proc html::WordPrefsBox {} {
  182.     global HTMLmodeVars
  183.     set box "-t {HTML mode Word Wrapping Preferences} 100 10 450 30 \
  184.       -t {Line width:} 10 40 90 55 -e [list $HTMLmodeVars(fillColumn)] 100 40 140 55 \
  185.       -t characters 145 40 300 55 \
  186.       -t {The variables below determine which characters build up words, and the word wrapping. Normally\
  187.       there is no need to change them. Read about them in general manual if you want to change them.} \
  188.       10 70 450 130 \
  189.       -t wordBreak: 10 140 150 155 -e [list $HTMLmodeVars(wordBreak)] 155 140 450 155 \
  190.       -t wordBreakPreface: 10 165 150 180 -e [list $HTMLmodeVars(wordBreakPreface)] 155 165 450 180 \
  191.       -t wrapBreak: 10 190 150 205 -e [list $HTMLmodeVars(wrapBreak)] 155 190 450 205 \
  192.       -t wrapBreakPreface: 10 215 150 230 -e [list $HTMLmodeVars(wrapBreakPreface)] 155 215 450 230"
  193. }
  194.  
  195. proc html::WordFlags {} {
  196.     return [list fillColumn wordBreak wordBreakPreface wrapBreak wrapBreakPreface]
  197. }
  198.  
  199. proc html::GlobalAttrsPrefs {} {
  200.     global HTMLmodeVars
  201.     set attrs " ID= CLASS= STYLE= TITLE= LANG= DIR= onClick= onDblClick= \
  202.      onMouseDown= onMouseUp= onMouseOver= onMouseMove= onMouseOut= onKeyPress= onKeyDown= onKeyUp="
  203.     set alwaysask $HTMLmodeVars(alwaysaskforAttributes)
  204.     set dontask $HTMLmodeVars(dontaskforAttributes)
  205.     set hidden $HTMLmodeVars(neveraskforAttributes)
  206.     html::UseAttrsDialog "HTML mode Attributes Preferences" $attrs alwaysask hidden dontask 1
  207.     set HTMLmodeVars(alwaysaskforAttributes) $alwaysask
  208.     set HTMLmodeVars(dontaskforAttributes) $dontask
  209.     set HTMLmodeVars(neveraskforAttributes) $hidden
  210.     prefs::modifiedModeVar alwaysaskforAttributes HTML
  211.     prefs::modifiedModeVar dontaskforAttributes HTML
  212.     prefs::modifiedModeVar neveraskforAttributes HTML
  213. }
  214.  
  215. # Choose an item from Use Attributes menu.
  216. proc html::UseAttributes {} {
  217.     global html::ElemAttrOptional
  218.     foreach a [array names html::ElemAttrOptional] {
  219.         if {[llength [set html::ElemAttrOptional($a)]]} {lappend htmlPossibleToUse $a}
  220.     }
  221.     regsub " S " $htmlPossibleToUse " " htmlPossibleToUse
  222.     if {![catch {listpick -p "Choose HTML element" [lsort $htmlPossibleToUse]} elem] &&
  223.     $elem != ""} {html::UseAttributes2 $elem}
  224. }
  225.  
  226. # Customize list of attributes which get asked about
  227. proc html::UseAttributes2 {item} {
  228.     global html::ElemAttrUsed html::ElemAttrHidden html::ElemAttrOverride
  229.     set reqattrs [html::GetRequired $item]
  230.     set optatts [html::GetOptional $item 1]
  231.     set used [html::GetUsed $item $reqattrs $optatts 1]
  232.     set hidden [html::GetHidden $item]
  233.     set override [html::GetOverride $item]
  234.     html::UseAttrsDialog "Attributes for $item" $optatts used hidden
  235.     set html::ElemAttrUsed($item) $used
  236.     set html::ElemAttrHidden($item) $hidden
  237.     set html::ElemAttrOverride($item) $override
  238.     prefs::modifiedArrayElement $item html::ElemAttrUsed
  239.     prefs::modifiedArrayElement $item html::ElemAttrHidden
  240.     prefs::modifiedArrayElement $item html::ElemAttrOverride
  241. }
  242.  
  243. proc html::UseAttrsDialog {txt optatts us hi {do ""} {isGlobal 0}} {
  244.     global HTMLmodeVars
  245.     upvar $us used $hi hidden
  246.     if {$do != ""} {upvar $do dont}
  247.     if {!$isGlobal} {upvar override over}
  248.     set hideExtensions $HTMLmodeVars(hideExtensions)
  249.     set hideDeprecated $HTMLmodeVars(hideDeprecated)
  250.     set alwaysask $HTMLmodeVars(alwaysaskforAttributes)
  251.     set dontask $HTMLmodeVars(dontaskforAttributes)
  252.     set neverask $HTMLmodeVars(neveraskforAttributes)
  253.     set page 0
  254.     set attrnumber [llength $optatts]
  255.     set options {"Always ask about" "Don't ask about at first" "Never ask about"}
  256.     set len 10
  257.     if {$isGlobal} {
  258.         set options "{Use individual settings} $options"
  259.         set len 8
  260.     }
  261.     foreach a $optatts {
  262.         if {[lcontains used $a]} {
  263.             lappend uh $isGlobal
  264.         } elseif {[lcontains hidden $a]} {
  265.             lappend uh [expr {2 + $isGlobal}]
  266.         } elseif {!$isGlobal || [lcontains dont $a]} {
  267.             lappend uh [expr {1 + $isGlobal}]
  268.         } else {
  269.             lappend uh 0
  270.         }
  271.     }
  272.     set start(0) 0
  273.     set end(0) -1
  274.     while {1} {
  275.         set box "-t [list $txt] 100 10 370 25"
  276.         if {!$isGlobal} {append box " -t {Global settings} 370 10 540 25"}
  277.         set h 35
  278.         if {$isGlobal && !$page} {
  279.             append box " -c {Don't use extensions to HTML 4.01} $hideExtensions 10 $h 370 [expr {$h + 20}]"
  280.             append box " -c {Don't use deprecated elements and attributes} $hideDeprecated 10 [expr {$h + 25}] 370 [expr {$h + 45}]"
  281.             incr h 50
  282.         }
  283.         set n 0
  284.         set g 0
  285.         set g1 ""
  286.         set end($page) [expr {$end($page) == -1 ? $start($page) + $len - 1 : $end($page)}]
  287.         foreach a [lrange $optatts $start($page) $end($page)] {
  288.             set m [lindex $uh [expr {$start($page) + $n}]]
  289.             append box " -t [string trimright $a =] 10 $h 150 [expr {$h + 20}] -m {[lrange $options $m $m] $options} 160 $h 360 [expr {$h + 20}]"
  290.             if {!$isGlobal} {
  291.                 if {[lcontains neverask $a]} {append box " -t {Never ask about} 370 $h 540 [expr {$h + 20}]"}
  292.                 if {[lcontains dontask $a]} {append box " -t {Don't ask about at first} 370 $h 540 [expr {$h + 20}]"}
  293.                 if {[lcontains alwaysask $a]} {append box " -t {Always ask about} 370 $h 540 [expr {$h + 20}]"}
  294.                 if {[lcontains alwaysask $a] || [lcontains dontask $a] || [lcontains neverask $a]} {
  295.                     incr h 20
  296.                     append box " -c {Override global setting} [lcontains over $a] 370 $h 540 [expr {$h + 20}]"
  297.                     incr h 5
  298.                     incr g
  299.                     lappend g1 1
  300.                 } else {
  301.                     lappend g1 0
  302.                 }
  303.             } else {
  304.                 lappend g1 0
  305.             }
  306.             incr h 25
  307.             incr n
  308.             if {$h > 300} {
  309.                 set end($page) [expr {$start($page) + $n - 1}]
  310.                 break
  311.             }
  312.         }
  313.         incr h 10
  314.         set h1 [expr {$h + 20}]
  315.         if {$page > 0} {append box " -b {<< Prev} 200 $h 265 $h1"}
  316.         if {[expr {$start($page) + $len}] < $attrnumber} {append box " -b {Next >>} 290 $h 355 $h1"}
  317.         set values [eval [concat dialog -w [expr {$isGlobal ? 380 : 550}] -h [expr {$h + 30}] -b OK 20 $h 85 $h1 -b Cancel 110 $h 175 $h1 $box]]
  318.         if {$isGlobal && !$page} {
  319.             set hideExtensions [lindex $values 2]
  320.             set hideDeprecated [lindex $values 3]
  321.             set values [lreplace $values 2 3]
  322.         }
  323.         if {[lindex $values 1]} {error "Cancel"}
  324.         set uh1 ""
  325.         set g2 0
  326.         for {set i 0} {$i < $n} {incr i} {
  327.             set v [lindex $values [expr {$i + $g2 + 2}]]
  328.             if {[lindex $g1 $i]} {
  329.                 if {[lindex $values [expr {$i + $g2 + 3}]]} {
  330.                     lappend over [lindex $optatts [expr {$start($page) + $i}]]
  331.                     set over [lunique $over]
  332.                 } else {
  333.                     set over [lremove $over [lindex $optatts [expr {$start($page) + $i}]]]
  334.                 }
  335.                 incr g2
  336.             }
  337.             lappend uh1 [lsearch -exact $options $v]
  338.         }
  339.         set uh [eval [concat lreplace [list $uh] $start($page) $end($page) $uh1]]
  340.         if {[lindex $values 0]} {break}
  341.         if {$page > 0 && [lindex $values [expr {$n + $g + 2}]]} {
  342.             incr page -1
  343.         } else {
  344.             incr page
  345.             if {![info exists start($page)]} {set start($page) [expr {$end([expr {$page - 1}]) + 1}]}
  346.             if {![info exists end($page)]} {set end($page) -1}
  347.         }
  348.     }
  349.     set used ""
  350.     set hidden ""
  351.     set dont ""
  352.     for {set i 0} {$i < $attrnumber} {incr i} {
  353.         if {[lindex $uh $i] == $isGlobal} {lappend used [lindex $optatts $i]}
  354.         if {$isGlobal && [lindex $uh $i] == 2} {lappend dont [lindex $optatts $i]}
  355.         if {[lindex $uh $i] == [expr {2 + $isGlobal}]} {lappend hidden [lindex $optatts $i]}
  356.     }
  357.     foreach h {hideExtensions hideDeprecated} {
  358.         if {[set $h] != $HTMLmodeVars($h)} {
  359.             set HTMLmodeVars($h) [set $h]
  360.             prefs::modifiedModeVar $h HTML
  361.             html::Hide
  362.         }
  363.     }
  364. }
  365.  
  366. proc html::IndentationPrefs {} {
  367.     global HTMLmodeVars html::ElemLayout
  368.     set indent $HTMLmodeVars(indentElements)
  369.     set box "-t {HTML mode Indentation Preferences} 100 10 450 30 \
  370.     -t {Indent the content of} 10 40 150 55"
  371.     set ww 70; set hh 10
  372.     set elements ""
  373.     foreach elem [lsort [array names html::ElemLayout]] {
  374.         if {[set html::ElemLayout($elem)] == "cr2"} {
  375.             lappend elements $elem
  376.         }
  377.     }
  378.     if {[llength $elements] > 40} {
  379.         for {set i 1} {$i <= [expr {[llength $elements]/40 + 1}]} {incr i} {
  380.             lappend mtxt "Page $i of preferences"
  381.         }
  382.         append box " -m [list [concat {{Page 1 of preferences}} $mtxt]] 250 40 450 60"
  383.         append box " -n {Page 1 of preferences}"
  384.     }
  385.     set i 1
  386.     foreach elem $elements {
  387.         append box " -c $elem [lcontains indent $elem] $hh $ww [expr {$hh + 100}] [expr {$ww + 15}]"
  388.         incr ww 20
  389.         if {$ww > 250} {
  390.             set ww 70
  391.             incr hh 110
  392.             if {$hh > 440} {
  393.                 set hh 10
  394.                 append box " -n {Page [incr i] of preferences}"
  395.             }
  396.         }
  397.     }
  398.     
  399.     if {![llength $elements]} {alertnote "No elements can be indented."; return}
  400.     set val [eval [concat dialog -w 460 -h 315 -b OK 20 285 85 305 -b Cancel 110 285 175 305 $box]]
  401.     if {[lindex $val 1]} {return}
  402.     set indent ""
  403.     set ex [expr {[llength $elements] > 40}]
  404.     for {set i 0} {$i < [llength $elements]} {incr i} {
  405.         if {[lindex $val [expr {$i + 2 + $ex}]]} {
  406.             lappend indent [lindex $elements $i]
  407.         }
  408.     }
  409.     set HTMLmodeVars(indentElements) $indent
  410.     prefs::modifiedModeVar indentElements HTML
  411. }
  412.  
  413. proc html::OptionalClosingTags {} {
  414.     global HTMLmodeVars html::OptionalClosingTags html::ElemLayout
  415.     set box "-t {HTML mode Optional Closing Tags Preferences} 100 10 450 30 \
  416.     -t {Use the closing tags of} 10 40 450 55"
  417.     set ww 70; set hh 10
  418.     foreach elem ${html::OptionalClosingTags} {
  419.         append box " -c $elem [lcontains HTMLmodeVars(optionalClosing) $elem] $hh $ww [expr {$hh + 100}] [expr {$ww + 15}]"
  420.         incr ww 20
  421.         if {$ww > 150} {
  422.             set ww 70
  423.             incr hh 110
  424.         }
  425.     }
  426.     set val [eval [concat dialog -w 460 -h 315 -b OK 20 285 85 305 -b Cancel 110 285 175 305 $box]]
  427.     if {[lindex $val 1]} {return}
  428.     set oldclosing $HTMLmodeVars(optionalClosing)
  429.     set HTMLmodeVars(optionalClosing) ""
  430.     for {set i 0} {$i < [llength ${html::OptionalClosingTags}]} {incr i} {
  431.         set elem [lindex ${html::OptionalClosingTags} $i]
  432.         if {[lindex $val [expr {$i + 2}]]} {
  433.             lappend HTMLmodeVars(optionalClosing) $elem
  434.         }
  435.         if {([lindex $val [expr {$i + 2}]] && ![lcontains oldclosing $elem]) ||
  436.         (![lindex $val [expr {$i + 2}]] && [lcontains oldclosing $elem])} {
  437.             # Find new layout
  438.             html::FindOptionalLayout $elem
  439.             # Make sure content is not indented if is shouldn't be.
  440.             if {[set html::ElemLayout($elem)] != "cr2" && [lcontains HTMLmodeVars(indentElements) $elem]} {
  441.                 set HTMLmodeVars(indentElements) [lremove $HTMLmodeVars(indentElements) $elem]
  442.                 prefs::modifiedModeVar indentElements HTML
  443.             }
  444.         }
  445.     }
  446.     prefs::modifiedModeVar optionalClosing HTML
  447. }
  448.  
  449.  
  450. proc html::ElementLayout {} {
  451.     global html::ElemAttrOptional
  452.     set htmlPossibleToUse [lremove -l [array names html::ElemAttrOptional] {{LI IN OL}} {{LI IN UL}}]
  453.     regsub -all {\{INPUT TYPE=[^ ]+} $htmlPossibleToUse " " htmlPossibleToUse
  454.     lappend htmlPossibleToUse INPUT
  455.     if {![catch {listpick -p "Choose HTML element" [lsort $htmlPossibleToUse]} elem] &&
  456.     $elem != ""} {html::ElementLayoutDialog $elem}
  457. }
  458.  
  459. proc html::ElementLayoutDialog {elem} {
  460.     global html::ElemLayout HTMLmodeVars
  461.     switch [set html::ElemLayout($elem)] {
  462.         nocr {set val {1 0 0 0}}
  463.         cr0 {set val {0 1 0 0}}
  464.         cr1 {set val {0 0 1 0}}
  465.         cr2 {set val {0 0 0 1}}
  466.         open00 {set val {0 0}}
  467.         open10 {set val {1 0}}
  468.         open01 {set val {0 1}}
  469.         open11 {set val {1 1}}
  470.     }
  471.     if {[regexp {open} [set html::ElemLayout($elem)]]} {
  472.         set layout [html::SetLayoutEmpty $val $elem]
  473.     } else {
  474.         set layout [html::SetLayoutClosing $val $elem]
  475.     }
  476.     set html::ElemLayout($elem) $layout
  477.     prefs::modifiedArrayElement $elem html::ElemLayout
  478.     # Make sure content is not indented if it shouldn't be.
  479.     if {$layout != "cr2" && [lcontains HTMLmodeVars(indentElements) $elem]} {
  480.         set HTMLmodeVars(indentElements) [lremove $HTMLmodeVars(indentElements) $elem]
  481.         prefs::modifiedModeVar indentElements HTML
  482.     }
  483. }
  484.  
  485. proc html::SetLayoutEmpty {values element} {
  486.     set box "-t {Layout of $element} 15 10 180 25 \
  487.     -c {Always a new line before tag.} [lindex $values 0] 10 40 225 55 \
  488.     -c {Always a new line after tag.} [lindex $values 1] 10 60 225 75 \
  489.     -b OK 20 90 85 110 -b Cancel 105 90 170 110"
  490.     set values [eval [concat dialog -w 230 -h 120 $box]]
  491.     if {[lindex $values 3]} {error "Cancel"}
  492.     return "open[lindex $values 0][lindex $values 1]"
  493. }
  494.  
  495. proc html::SetLayoutClosing {values element} {
  496.     set box "-t {Layout of $element} 15 10 180 25 \
  497.     -r {text<TAG>text</TAG>text} [lindex $values 0] 10 40 200 60 \
  498.     -r {text\r<TAG>text</TAG>\rtext} [lindex $values 1] 10 70 150 130 \
  499.     -r {blank line\r<TAG>text</TAG>\rblank line} [lindex $values 2] 10 140 150 200 \
  500.     -r {blank line\r<TAG>\rtext\r</TAG>\rblank line} [lindex $values 3] 10 210 150 310"
  501.     set values [eval [concat dialog -w 200 -h 350 \
  502.     -b OK 20 320 85 340 -b Cancel 105 320 170 340 $box]]
  503.     if {[lindex $values 1]} {error "Cancel"}
  504.     if {[lindex $values 2]} {set layout nocr}
  505.     if {[lindex $values 3]} {set layout cr0}
  506.     if {[lindex $values 4]} {set layout cr1}
  507.     if {[lindex $values 5]} {set layout cr2}
  508.     return $layout
  509. }
  510.  
  511. proc html::TypesPrefs {type txt} {
  512.     global HTMLmodeVars
  513.     hook::register deactivateHook html::${type}CloseHook Text
  514.     if {[catch {bringToFront "* $txt *"}]} { 
  515.         new -n "* $txt *" -shell 1
  516.         insertText [join $HTMLmodeVars($type) "\r"]
  517.         shrinkWindow 1 
  518.         if {$HTMLmodeVars(explainTypePrefs)} {
  519.             set txt1 [string tolower $txt]
  520.             set v [dialog -w 350 -h 210 -t "Modify the list of $txt1 by editing the window just opened.\
  521.               Each [string trim $txt1 s] must be separated by either a space or a new line.\
  522.               Any item containing spaces must be put within quotes."  10 10 340 75\
  523.               -t "The\
  524.               new $txt1 are saved when the window is closed.\
  525.               Cancel the changes by holding down the shift key while clicking the window's\
  526.               close box." 10 80 340 140 \
  527.               -c "Do not explain this to me in the future" 0 10 150 340 165 \
  528.               -b OK 20 180 85 200]
  529.             if {[lindex $v 0]} {
  530.                 set HTMLmodeVars(explainTypePrefs) 0
  531.                 prefs::modifiedModeVar explainTypePrefs HTML
  532.             }
  533.         }
  534.     }
  535. }
  536.  
  537. proc html::contenttypesCloseHook {name} {
  538.     if {$name != "* Content Types *"} {return}
  539.     html::TypesCloseHook contenttypes
  540. }
  541.  
  542. proc html::linktypesCloseHook {name} {
  543.     if {$name != "* Link Types *"} {return}
  544.     html::TypesCloseHook linktypes
  545. }
  546.  
  547. proc html::mediatypesCloseHook {name} {
  548.     if {$name != "* Media Descriptors *"} {return}
  549.     html::TypesCloseHook mediatypes    
  550. }
  551.  
  552. proc html::TypesCloseHook {type} {
  553.     global HTMLmodeVars
  554.     # When closing size is {0 0 0 0}
  555.     if {[getGeometry] != {0 0 0 0}} {return}
  556.     if {![key::shiftPressed]} {
  557.         set HTMLmodeVars($type) [getText [minPos] [maxPos]]
  558.         prefs::modifiedModeVar $type HTML
  559.     }
  560.     hook::deregister deactivateHook html::${type}CloseHook Text
  561. }
  562.  
  563. #===============================================================================
  564. # ◊◊◊◊ Home pages ◊◊◊◊ #
  565. #===============================================================================
  566.  
  567. # Dialog to handle servers and corresponding home page folders.
  568. proc html::HomePages {{this ""}} {
  569.     global HTMLmodeVars html::NFmirrorFiles
  570.     
  571.     set pages $HTMLmodeVars(homePages)
  572.     set servers $HTMLmodeVars(FTPservers)
  573.     set templates $HTMLmodeVars(templateFolders)
  574.     array set mirrors [array get html::NFmirrorFiles]
  575.     set touchedIt 0
  576.     if {$this == ""} {set this ∞}
  577.     while {1} {
  578.         set box "-t {Home pages} 180 10 300 30 -t {URLs:} 10 40 100 60 \
  579.         -t {Home Page Folder:} 10 70 110 100 \
  580.         -t {Include Folder:} 10 110 110 130 \
  581.         -t {Template Folder:} 10 140 120 160 \
  582.         -t {Default file:} 10 170 100 190 \
  583.         -t {Ftp server:} 10 200 100 220 -t {User ID:} 10 225 100 245 \
  584.         -t Password: 10 250 100 270 -t Directory: 10 275 100 295 \
  585.         -b OK 10 325 75 345 -b Cancel 90 325 155 345 -b New… 170 325 235 345 \
  586.         -c {Tell Big Brother} 0 280 305 400 320"
  587.         if {[llength $pages]} {
  588.             set pgs ""
  589.             foreach pg $pages {
  590.                 lappend pgs "[lindex $pg 1][lindex $pg 2]"
  591.             }
  592.             append box " -m [list [concat $this $pgs]] 125 40 400 60"
  593.             append box " -b Change… 250 325 320 345 -b Remove 335 325 400 345"
  594.             foreach pg $pages {
  595.                 lappend box -n "[lindex $pg 1][lindex $pg 2]" -t [dialog::specialView::file [lindex $pg 0]] 125 70 400 110 \
  596.                 -t [lindex $pg 3] 125 170 310 190
  597.                 if {[llength $pg] == 5} {lappend box -t [dialog::specialView::file [lindex $pg 4]] 125 110 400 130}
  598.                 foreach f $servers {
  599.                     if {[lindex $f 0] == [lindex $pg 0]} {
  600.                         lappend box -t [lindex $f 1] 125 200 400 220 \
  601.                         -t [lindex $f 2] 125 225 400 245
  602.                         set pwb ""
  603.                         for {set i 0} {$i < [string length [lindex $f 3]]} {incr i} {
  604.                             append pwb •
  605.                         }
  606.                         lappend box -t $pwb 125 250 400 270 \
  607.                         -t [dialog::specialView::file [lindex $f 4]] 125 275 400 295
  608.                     }
  609.                 }
  610.                 foreach f $templates {
  611.                     if {[lindex $f 0] == [lindex $pg 0]} {
  612.                         lappend box -t [dialog::specialView::file [lindex $f 1]] 125 140 400 160
  613.                     }
  614.                 }
  615.             }
  616.         } else {
  617.             append box  " -m {{None defined} {None defined}} 125 40 400 60"
  618.         }
  619.         set values [eval [concat dialog -w 410 -h 355 $box]]
  620.         set this [lindex $values 4]
  621.         if {[lindex $values 0]} {
  622.             set HTMLmodeVars(homePages) $pages
  623.             set HTMLmodeVars(FTPservers) $servers
  624.             set HTMLmodeVars(templateFolders) $templates
  625.             prefs::modifiedModeVar homePages HTML
  626.             prefs::modifiedModeVar FTPservers HTML
  627.             prefs::modifiedModeVar templateFolders HTML
  628.             foreach mir [array names html::NFmirrorFiles] {
  629.                 if {![info exists mirrors($mir)]} {unset html::NFmirrorFiles($mir)}
  630.                 if {![info exists mirrors($mir)] || [set html::NFmirrorFiles($mir)] != $mirrors($mir)} {
  631.                     prefs::modifiedArrayElement $mir html::NFmirrorFiles
  632.                 }
  633.             }
  634.             foreach mir [array names mirrors] {
  635.                 if {![info exists html::NFmirrorFiles($mir)]} {
  636.                     prefs::modifiedArrayElement $mir html::NFmirrorFiles
  637.                 }
  638.             }
  639.             array set html::NFmirrorFiles [array get mirrors]
  640.             if {[lindex $values 3]} {
  641.                 if {[html::GetVersion Bbth] < 1.1} {
  642.                     alertnote "Cannot change the settings in Big Brother. You need Big Brother 1.1 or later."
  643.                 } elseif {[askyesno "Change URL mappings in Big Brother?"] == "yes"} {
  644.                     if {![app::isRunning Bbth] && [catch {app::launchBack Bbth}]} {
  645.                         alertnote "Could not find or launch Big Brother."
  646.                         return
  647.                     }
  648.                     set urlmap [html::URLmap]
  649.                     AEBuild 'Bbth' core setd "----" "obj{want:type('mapG'),from:null(),form:'prop',seld:type('mapS')}" "data" "\[$urlmap\]"
  650.                 }
  651.             }
  652.             return
  653.         } elseif {[lindex $values 1]} {
  654.             if {!$touchedIt || [askyesno "Really cancel without saving changes?"] == "yes"} {return}
  655.         } elseif {[lindex $values 2]} {
  656.             set newpg {{} {} {} "index.html" {}}
  657.             set newserver {{} {} {} {}}
  658.             set newtemplate {}
  659.             while {1} {
  660.                 if {[catch {html::SetHomePages $pages [lindex $newpg 0] "[lindex $newpg 1][lindex $newpg 2]" [lindex $newpg 3] [lindex $newpg 4]} newpg]} {break}
  661.                 if {[html::TestHomePage $pages $newpg]} {
  662.                     lappend pages $newpg
  663.                     if {[lindex $newserver 0] != ""} {lappend servers [concat [list [lindex $newpg 0]] $newserver]}
  664.                     if {$newtemplate != ""} {lappend templates [concat [list [lindex $newpg 0]] [list $newtemplate]]}
  665.                     set this "[lindex $newpg 1][lindex $newpg 2]"
  666.                     set touchedIt 1
  667.                     break
  668.                 }
  669.             }
  670.         } else {
  671.             for {set i 0} {$i < [llength $pages]} {incr i} {
  672.                 if {"[lindex [lindex $pages $i] 1][lindex [lindex $pages $i] 2]" == $this} {
  673.                     if {[lindex $values 5]} {
  674.                         set newpg [lindex $pages $i]
  675.                         set pg "[lindex $newpg 1][lindex $newpg 2]"
  676.                         set oldpage [lindex $newpg 0]
  677.                         set newserver {{} {} {} {}}
  678.                         foreach f $servers {
  679.                             if {[lindex $f 0] == $oldpage} {set newserver [lrange $f 1 end]}
  680.                         }
  681.                         set newtemplate {}
  682.                         foreach f $templates {
  683.                             if {[lindex $f 0] == $oldpage} {set newtemplate [lindex $f 1]}
  684.                         }
  685.                         while {1} {
  686.                             if {[catch {html::SetHomePages $pages [lindex $newpg 0] "[lindex $newpg 1][lindex $newpg 2]" [lindex $newpg 3] [lindex $newpg 4] $pg} newpg]} {break}
  687.                             if {[html::TestHomePage $pages $newpg $pg]} {
  688.                                 set pages [lreplace $pages $i $i $newpg]
  689.                                 set ns ""
  690.                                 foreach f $servers {
  691.                                     if {[lindex $f 0] != $oldpage} {lappend ns $f}
  692.                                 }
  693.                                 set servers $ns
  694.                                 set nt ""
  695.                                 foreach f $templates {
  696.                                     if {[lindex $f 0] != $oldpage} {lappend nt $f}
  697.                                 }
  698.                                 set templates $nt
  699.                                 if {[lindex $newserver 0] != ""} {lappend servers [concat [list [lindex $newpg 0]] $newserver]}
  700.                                 if {$newtemplate != ""} {lappend templates [concat [list [lindex $newpg 0]] [list $newtemplate]]}
  701.                                 if {[info exists mirrors($oldpage)]} {
  702.                                     set mirrors([lindex $newpg 0]) $mirrors($oldpage)
  703.                                     unset mirrors($oldpage)
  704.                                 }
  705.                                 set this "[lindex $newpg 1][lindex $newpg 2]"
  706.                                 set touchedIt 1
  707.                                 break
  708.                             }
  709.                         }
  710.                     } else {
  711.                         set tpg [lindex [lindex $pages $i] 0]
  712.                         set ns ""
  713.                         foreach f $servers {
  714.                             if {[lindex $f 0] != $tpg} {lappend ns $f}
  715.                         }
  716.                         set servers $ns
  717.                         set nt ""
  718.                         foreach f $templates {
  719.                             if {[lindex $f 0] != $tpg} {lappend nt $f}
  720.                         }
  721.                         set templates $nt
  722.                         catch {unset mirrors($tpg)}
  723.                         set pages [lreplace $pages $i $i]
  724.                         set touchedIt 1
  725.                     }
  726.                 }
  727.             }
  728.         }
  729.     }
  730. }
  731.  
  732. # Dialog to define or change a home page.
  733. proc html::SetHomePages {pages folder url defFile inclFld {pg ""}} {
  734.     upvar newserver server newtemplate template
  735.     while {1} {
  736.         set pwb ""
  737.         for {set i 0} {$i < [string length [lindex $server 2]]} {incr i} {
  738.             append pwb •
  739.         }
  740.         set val [dialog -w 450 -h 370 -t "Home Page Folder:" 10 10 135 30 -t [dialog::specialView::file $folder] 140 10 440 50 \
  741.         -t "Include Folder:" 10 60 110 80 -t [dialog::specialView::file $inclFld] 130 60 440 100 \
  742.         -t "Template Folder:" 10 110 120 130 -t [dialog::specialView::file $template] 130 110 440 150 \
  743.         -t "URL:" 10 160 90 180 \
  744.         -e $url 100 160 440 175 -t "Default file:" 10 195 90 210 \
  745.         -e $defFile 100 195 440 210 \
  746.         -t "Ftp Server:" 10 230 90 250 -e [lindex $server 0] 100 230 440 245 \
  747.         -t "User ID:" 10 255 90 275 -e [lindex $server 1] 100 255 440 270 \
  748.         -t "Password:" 10 280 85 300 -t $pwb 160 280 440 295 \
  749.         -t "Directory:" 10 310 90 330 -e [lindex $server 3] 100 310 440 325 \
  750.         -b OK 20 340 85 360 -b Cancel 110 340 175 360  -b Set… 90 280 150 300 \
  751.         -b "Set…" 20 30 80 50 -b "Set…" 10 80 60 100 -b "Unset" 70 80 120 100 \
  752.         -b "Set…" 10 130 60 150 -b "Unset" 70 130 120 150]
  753.         set url [string trim [lindex $val 0]]
  754.         set defFile [string trim [lindex $val 1]]
  755.         set ftp [string trim [lindex $val 2]]
  756.         regexp {^(ftp://)?(.*)$} $ftp dum1 dum2 ftp
  757.         set dir [string trimright [string trim [lindex $val 4]] /]
  758.         if {[lindex $val 7] && ![catch {dialog::password "Password for $ftp:"} newpw]} {
  759.             set pw $newpw
  760.         } else {
  761.             set pw [lindex $server 2]
  762.         }
  763.         set server [list $ftp [string trim [lindex $val 3]] \
  764.         $pw $dir]
  765.         if {[lindex $val 8] && ![catch {html::GetDir "Home Page Folder:"} fld]} {
  766.             set folder $fld
  767.         } elseif {[lindex $val 9] && ![catch {html::GetDir "Include Folder:"} fld]} {
  768.             set inclFld $fld
  769.         } elseif {[lindex $val 10]} {
  770.             set inclFld ""
  771.         } elseif {[lindex $val 11] && ![catch {html::GetDir "Template Folder:"} fld]} {
  772.             set template $fld
  773.         } elseif {[lindex $val 12]} {
  774.             set template ""
  775.         } elseif {[lindex $val 5]} {
  776.             if {![regexp {://} $url] && $url != ""} {
  777.                 set url "http://$url"
  778.             }
  779.             if {[lindex $server 0] != "" && [lindex $server 1] == ""} {
  780.                 alertnote "When you specify an ftp server you must give the user ID."
  781.             } elseif {[string length $folder] && [string length $url] && [string length $defFile]} {
  782.                 regexp -indices {://} $url css
  783.                 set sl [string first / [string range $url [expr {[lindex $css 1] + 1}] end]]
  784.                 if {$sl < 0} {
  785.                     set base "$url/"
  786.                     set path ""
  787.                 } elseif {[string index $url [expr {[string length $url] -1}]] != "/"} {
  788.                     alertnote "A directory URL ending with a slash expected."
  789.                     continue
  790.                 } else {
  791.                     set base [string range $url 0 [expr {[lindex $css 1] + $sl + 1}]]
  792.                     set path [string range $url [expr {[lindex $css 1] + $sl + 2}] end]
  793.                 }
  794.                 set ret [list $folder $base $path $defFile]
  795.                 if {$inclFld != ""} {lappend ret $inclFld}
  796.                 return  $ret
  797.             } else {
  798.                 alertnote "Home page folder, URL, and default file must be specified."
  799.             }
  800.         } elseif {[lindex $val 6]} {
  801.             error ""
  802.         }
  803.     }
  804. }
  805.  
  806. proc html::TestHomePage {pages newpg {pg ""}} {
  807.     global file::separator
  808.     foreach p $pages {
  809.         if {"[lindex $p 1][lindex $p 2]" == $pg} {continue}
  810.         if {[string match "[lindex $p 1][lindex $p 2]*" "[lindex $newpg 1][lindex $newpg 2]"] ||
  811.         [string match "[lindex $newpg 1][lindex $newpg 2]*" "[lindex $p 1][lindex $p 2]"]} {
  812.             if {[string length "[lindex $p 1][lindex $p 2]"] > [string length "[lindex $newpg 1][lindex $newpg 2]"]} {
  813.                 set s1 "[lindex $p 1][lindex $p 2]"; set s2 "[lindex $newpg 1][lindex $newpg 2]"
  814.             } else {
  815.                 set s2 "[lindex $p 1][lindex $p 2]"; set s1 "[lindex $newpg 1][lindex $newpg 2]"
  816.             }
  817.             if {$s1 == $s2} {
  818.                 alertnote "You have already defined a home page folder for $s1."
  819.             } else {                
  820.                 dialog::alert "There is already a home page folder for [lindex $p 1][lindex $p 2].\
  821.                   You can't define a home page folder for both [lindex $p 1][lindex $p 2] and [lindex $newpg 1][lindex $newpg 2].\
  822.                   Instead put the content of $s1 inside $s2 and use one home page folder."
  823.             }
  824.             return 0
  825.         }
  826.     }
  827.     set msg {"home page" "" "" "" include}
  828.     foreach p $pages {
  829.         foreach i {0 4} {
  830.             if {"[lindex $p 1][lindex $p 2]" == $pg    || [llength $p] == $i} {continue}
  831.             foreach j {0 4} {
  832.                 if {[llength $newpg] == $j} {continue}
  833.                 if {[string match [file join [lindex $p $i] *] [file join [lindex $newpg $j] " "]] || \
  834.                   [string match [file join [lindex $newpg $j] *] [file join [lindex $p $i] " "]]} {
  835.                     alertnote "The [lindex $msg $j] folder overlaps with the [lindex $msg $i] folder for [lindex $p 1][lindex $p 2]."
  836.                     return 0
  837.                 }
  838.             }
  839.         }
  840.     }
  841.     if {[string match [file join [lindex $newpg 0] *] [file join [lindex $newpg 4] " "]] ||
  842.     [string match [file join [lindex $newpg 4] *] [file join [lindex $newpg 0] " "]]} {
  843.         alertnote "The home page folder and include folder cannot be inside one another."
  844.         return 0
  845.     }
  846.     return 1
  847. }    
  848.  
  849.  
  850.