All pastes #416342 Raw Edit

Stuff

public text v1 · immutable
#416342 ·published 2007-03-30 06:18 UTC
rendered paste body
;stuff to add. 
;Save/load page
;dont allow edits to break a tag
;dont allow edits after a closing body or html tag
;dont allow edits between closed head and open body
;etc etc
alias wc dialog $iif($dialog(wc),-v,-m) wc wc
menu * {
  -
  Webpage Creator: wc
}
dialog wc {
  title "Webpage Creator"
  size -1 -1 310 245
  option dbu

  box "Text Formats",      1,   8   4  46  24
  button "B",              2,  11  13  10  10
  button "U",              3,  21  13  10  10
  button "I",              4,  31  13  10  10
  button "S",              5,  41  13  10  10
  box "Alignment",         6,  55   4  48  24
  button "L",              7,  59  13  10  10
  button "R",              8,  69  13  10  10
  button "C",              9,  79  13  10  10
  button "J",             10,  89  13  10  10
  box "Headings",         11, 104   4  76  24
  button "H1",            12, 107  13  10  10
  button "H2",            13, 117  13  10  10
  button "H3",            14, 127  13  10  10
  button "H4",            15, 137  13  10  10
  button "H5",            16, 147  13  10  10
  button "H6",            17, 157  13  10  10
  button "H7",            18, 167  13  10  10
  box "Font Size/Colour", 19, 181   4  56  24
  button "+1",            20, 184  13  10  10
  button "-1",            21, 194  13  10  10
  button "Size",          22, 204  13  15  10
  button "Col",           23, 219  13  15  10
  box "Other",            24, 238   4  65  24
  button "Img",           25, 241  13  20  10
  button "URL",           26, 261  13  20  10
  button "HR",            27, 281  13  20  10
  box "Forms",            28,   8  29 146  30
  button "New Form",      29,  62  36  40  10
  button "Button",        30,  11  46  20  10
  button "Submit",        31,  31  46  20  10
  button "Cancel",        32,  51  46  20  10
  button "Radio",         33,  71  46  20  10
  button "Check",         34,  91  46  20  10
  button "Text",          35, 111  46  20  10
  button "Edit",          36, 131  46  20  10
  box "Tables",           37, 155  29  68  30
  button "New table",     38, 167  36  40  10
  button "Head",          39, 158  46  20  10
  button "Row",           40, 178  46  20  10
  button "Data",          41, 198  46  20  10
  button "CSS Manager",   42, 224  32  40  26
  button "Help",          43, 264  32  40  26
  text "Title:",          44,   2  65  15   8, right
  edit "",                45,  18  64 290  10
  edit "",                46,   2  75 306 151, multi return hsbar vsbar
  text "",                47,   2 227 178  15 
  button "Upload to FTP", 48, 183 227  40  15
  button "Preview",       49, 224 227  40  15
  button "Page Options",  50, 266 227  40  15
}
on *:dialog:wc:init:*: {
  .remove tempPage.html
  did -a $dname 46 <html> $crlf
  did -a $dname 46 $tab $+ <head> $crlf(2)
  did -a $dname 46 $tab $+ </head> $crlf
  did -a $dname 46 $tab $+ <body> $crlf(2)
  did -a $dname 46 $tab $+ </body> $crlf 
  did -a $dname 46 </html>
}

on *:dialog:wc:edit:45: {
  var %line = $$didreg(wc,46,/<title>.*<\/title>/i,1), %switch = -o
  if ($did(45)) {
    if (!%line) var %line = $calc($didreg(wc,46,/<head>/i,1) + 1)
    if (</head> isin $did(46,%line)) var %switch = -i
    did %switch $dname 46 %line $+($tab(2),<title>,$did(45),</title>) 
  }
  else did -o $dname 46 %line $null
}
on *:dialog:wc:sclick:*: {
  if ($did == 2) var %open <b>, %close </b>
  elseif ($did == 3) var %open <u>, %close </u>
  elseif ($did == 4) var %open <i>, %close </i>
  elseif ($did == 5) var %open <s>, %close </s>

  if (%open) { 
    if ($did(46).seltext) {

    }
    elseif ($did(46,1).sel) {
      var %pos = $getLinePos($did(46).selstart,$did(46,1).sel), %linenum = $did(46,1).sel, %line = $did(46,%linenum)
      var %text = $$input(What text do you want to add?,e,Input request)
      var %before = $left(%line,%pos), %after = $iif(%before,$right(%line,$+(-,%pos)),%line)
      var %tabs = $countTabs(%linenum)
      did -o $dname 46 %linenum $+($tab(%tabs),%before,%open,%text,%close,%after)
    }
    else noop $input(Can not add text after a closed body or html tag. Select a line to add text on, or select text to edit,oh,Error)
  }
}
alias -l countTabs {
  var -s %previous = $did(46,$calc($1 - 1)), %tabs = $count(%previous,$chr(160)) / 2
  return %tabs
}
alias -l getLinePos {
  var %x 1, %len 0
  while (%x < $2) {
    inc %len $calc($len($did(wc,46,%x)) + 2)
    inc %x
  }
  return $calc($1 - %len)
}

alias -l tab return $str($chr(160),$iif($1,$calc($1 * 2),2))
alias -l crlf return $iif($1,$str($+($crlf,$chr(32)),$1),$crlf)