NB. built from project: ~Source\packages\publish\publish
NB. publish J code to HTML

script_z_ '~system\main\convert.ijs'
script_z_ '~system\main\dll.ijs'
script_z_ '~system\main\files.ijs'
script_z_ '~system\main\gl2.ijs'
script_z_ '~system\main\regex.ijs'
script_z_ '~system\main\strings.ijs'


require 'convert dll files gl2 regex strings'

coclass 'jpublish'
coextend 'jgl2'
COCLASSPATH copath coname''
script '~system\packages\publish\web.ijs'

webdefs''   NB. make sure web defs available in this locale

PUBPREFS=: jpath '~config\pubprefs.ijs'
PUBSCHMS=: jpath '~config\pubschms.ijs'
PUBSMP=: jpath '~system\extras\config\colorsmp.ijs'

NB.*publish v interactive publisher
NB.   publish ''   or   publish 'scriptname'

NB.*fmtlines v format lines of J code
NB.   fmtlines 'J code'

NB.*fmtscript v format script
NB.   fmtscript 'script.ijs'  NB. saved as script.htm

NB.*fmtscriptto v format script
NB.   'script.ijs' fmtscriptto 'output.htm'B. defaults (note default for BROWSER done at runtime)

OCXYES=: 1
TOP=: 0
OCX=: 'Shell.Explorer.2'    NB. Use OCX control
OLEMETHOD=: 'base navigate2'  NB. OLE method
SCRIPTDIR=: jpath '~user'
SCHEMEID=: 'JpubStandard'
SCHEME=: 0 : 0
global assign= bold,,
control word=  ,255 0 0,
comment=       italic,0 128 0,
bookmark=      italic bold,0 128 0,
string=        ,0 0 192,
body=          ,255 255 255
boxdraw chars= )asciibox
)

readprefs=: 3 : 0
script :: 0: PUBPREFS
)

writeprefs=: verb define
x=. 'NB. Configuration for J Script Publisher',LF,LF
NB. x=. x,'BROWSER=: ''',BROWSER,'''',LF
x=. x,'OCXYES=: ',(":OCXYES),LF
x=. x,'TOP=: ',(":TOP),LF
x=. x,'OCX=: ''',OCX,'''',LF
x=. x,'OLEMETHOD=: ''',OLEMETHOD,'''',LF
x=. x,'SCRIPTDIR=: ''',SCRIPTDIR,'''',LF
x=. x,'SCHEMEID=: ''',SCHEMEID,'''',LF
x=. x,'SCHEME=: 0 : 0',LF,SCHEME,')',LF
(toHOST x) fwrite PUBPREFS
)


NB. =========================================================
readschemes=: verb define
try.
  script_jpub0_ PUBSCHMS
catch.
  script_jpub0_ jpath '~system\extras\config\pubschms.ijs'
end.
SCHEMES=: ((0=#SCHEMEID)#a:), /:~ nl_jpub0_ ''
)

clearschemes=: 18!:55 bind (<'jpub0')

writeschemes=: verb define
x=. ''
for_s. SCHEMES do.
  x=. x,(>s),'=: 0 : 0',LF,(do_jpub0_ >s),')',LF,LF end.
x fwrite PUBSCHMS
)


splitscheme=: (({. ;&dltb }.@}.)~ i.&'=');._2

from=: {:"1@] >@{~ {."1@] i. <@[

setscheme=: verb define
fmtcomment=: fmtcommentm=: fmtcontrol=: fmtlassign=: fmtname=: ]
fmtgassign=: fmtdefword=: fmtnumber=: fmtstring=: fmtother=: fmtwhite=: ]
fmtverb=: fmtadverb=: fmtconjunction=: fmtboxdraw=: fmtparens=: ]
for_s. splitscheme y. do.
  do_jweb_ (>(schemenames i. {.s){fmtverbs,;:'fmtbody xxx'),'_jpublish_=:',makedefn s
end.
)


makedefn=: verb define
'el def'=. y.
if. ')'={.1{.def do. }.def return. end.
NB. create verb to handle sample defn:
prepsamp def   NB. make defns
NB.  combos:   (dflt),(dflt)       ==>   ]
NB.            (dflt),color        ==>   FONT color '#xxxxxx'
NB.            font,(dflt)         ==>   FONT face 'goober' size n
NB.                                possibly STRONG@EM@
NB.            font,color          ==>   FONT face 'goober' size n color '#xxxxxx'
NB.                                possibly STRONG@EM@
newverb el
)





isin=: +./@E. :: 0:




NB.  pwords  - Similar to ;: primitive, but includes blanks
NB. (use of adverse is to protect against open quote error)
pwords=: fixword^:_ (;: :: ((}: , }:&.>@{:)@;:@(,&'''')))

fixword=: dyad define
d=. 0 i.~ x. =/@:>@; ;y.   NB. index of first difference
if. d=#x. do. y. return. end.  NB. exit if none.
i=. d i.~ 0,+/\#@> y.    NB. number of words before diff
(i{.y.),(<' '#~0 i.~ ' '= d}.x.),i}.y.  NB. insert blanks
)


NB. Format words of a line

fmtwords=: verb define
c1=. {.@>y.                                 NB. first character
cm=. (<'NB.')=3{.&.>y.                      NB. comments
cmm=. cm *. special e.~ {:@(4&{.)@> y.      NB. markup comments
cm=. cm>cmm                                 NB. (don't include cmm)
cn=. (2<#@>y.) *. ('.'={:@>y.) *. -.cm+.cmm NB. control clause
b=. c1=' '                                  NB. blank
al=. (+. p1) y. = <'=.'                     NB. local assignment
ag=. (+. p1) y. = <'=:'                     NB. global assignment
a=. (al=. al>p) +. (ag=. ag>p=. y.=<,')')   NB. ignore  )=.
nm=. a < (y. e. nouns) +. (c1 e. Alpha) > (+./@(e.&'.:')@> y.)
NB. name
NB. defn=. (y.-:,<,')')+.(y. e. DEFwords)*.-.a  NB. "define" words
conn=. (':'e.&> y.) < c1 e. '_0123456789'   NB. constant number
cons=. a < c1=''''                          NB. constant string
v=. y. e. verbs                             NB. primitive verbs
ad=. y. e. adverbs                          NB. primitive adverbs
conj=. y. e. conjunctions                   NB. primitive conjunctions
bd=. y. e. ;:boxdrawchars                   NB. box drawing chars
par=. y. e. ;:'()'                          NB. parentheses
o=. -. cm+.cmm+.cn+.b+.a+.nm+.cons+.conn+.v+.ad+.conj+.bd+.par  NB. other
idx=. +/(i.15)*cm,cmm,cn,b,al,ag,nm,cons,conn,v,ad,conj,bd,par,:o NB. indices
(idx{fmtverbs)Each across (entities^:_1)&.>y. NB. format each word
)




fmtverbs=. fmtcomment`fmtcommentm`fmtcontrol`fmtwhite`fmtlassign
fmtverbs=. fmtverbs`fmtgassign`fmtname`fmtstring`fmtnumber
fmtverbs=. fmtverbs`fmtverb`fmtadverb`fmtconjunction`fmtboxdraw
fmtverbs=: fmtverbs`fmtparens`fmtother
schemenames=: <;._1 noun define -.LF
/comment/bookmark/control word/white space/local assign/global assign/name
/string/number/verb/adverb/conjunction/boxdraw chars/parentheses/other/body
)



NB. ordered scheme names (for scheme editor)
oschemenames=: 15 6 7 8 0 1 9 10 11 4 5 2 13 12 3 14{schemenames

NB. ordered descriptions (for scheme editor)
oschemedescs=: <;._2 noun define
Covers entire body of document, and specifies background color, and default foreground color and font.
Names (being referenced).
Character constants.
Numeric constants.
Normal comments.  (NB.)
Bookmark comments.  (NB. followed immediately by a graphic)
Primitive verbs.
Primitive adverbs.
Primitive conjunctions.
Names being assigned locally.
Names being assigned globally.
Control words. (if., while., etc)
Parentheses.
Box drawing characters.
Whitespace.
Other characters (eg special glyphs)
)




Alpha=: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
nouns=: ;:'m. n. u. v. x. y. a. a:'
t=. ' = < <. <: > >. >: _: + +. +: * *. *: - -. -: % %. %: ^ ^.'
t=. t,' $ $. $: ~. ~: | |. |: , ,. ,: ; ;: # #. #: ! /: \: [ [: ]'
t=. t,' { {. {: {:: }. }: ". ": ? ?.'
t=. t,' A. c. C. e. E. i. i: j. L. o. p. p: q: r. x:'
t=. t,' _9: _8: _7: _6: _5: _4: _3: _2: _1:'
t=. t,' 0: 1: 2: 3: 4: 5: 6: 7: 8: 9:'
verbs=: ;:t
adverbs=: ;:'~ / \ /. \. } b. f. t. t:'
conjunctions=: ;:' ^: . .. .: :  :. :: ;. !. !: " ` `: @ @. @: & &. &: d. D. D: H. L: S: T.'

boxdrawchars=: 179 180 191 192 193 194 195 196 197 217 218{a.



special=: '!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~'
p1=: 1&(|.!.0)
DEFwords=: ;:'noun adverb conjunction verb dyad def define'





page=: HEAD@(TITLE by meta)@[ HTML@by fmtbody   NB. add head to body
meta=: META name 'GENERATOR' content ((9!:14''),' Publisher')
rd=: toJ@fread                        NB. cover to fread
wr=: toHOST@[ empty@fwrite ]          NB. cover to fwrite


NB. Main verbs:
fmtline=: ;@fmtwords@pwords ^: (+./ . ~:&' ') @ detab
fmtlines=: PRE@CODE@;@(<@by@fmtline ;. _2)@(,&CRLF)
fmtscriptto=: (page fmtlines@rd)@[ wr ]
fmtscript=: fmtscriptto ,&'.htm'@(_4&}.)

NB.  Read registry and return name of default browser
NB. dfltbrowser ''
NB.     return default browser, or '' if we cannot
dfltbrowser=: verb define
'' if. 1~:>{.r=. querykeyvalue HKEY_CLASSES_ROOT;'.htm';'' do. return. end.
if. 1~:>{.r=. querykeyvalue HKEY_CLASSES_ROOT;((}:>{:r),'\shell\open\command');'' do. return. end.
r=. deb >{:r
r {.~ 1 i.~ (r=' ') > ~:/\r='"'
)

RegOpenKeyExA=: 'advapi32 RegOpenKeyExA i i *c i i *i'&cd
RegQueryValueExA=: 'advapi32 RegQueryValueExA i i *c i *i *c *i'&cd
RegCloseKey=: 'advapi32 RegCloseKey i i'&cd
HKEY_CLASSES_ROOT=: _2147483648

NB. STANDARD_RIGHTS_ALL,KEY_QUERY_VALUE,KEY_SET_VALUE
NB. KEY_CREATE_SUB_KEY,KEY_ENUMERATE_SUB_KEYS
NB. KEY_NOTIFY,KEY_CREATE_LINK
NB. and not SYNCHRONIZE
fullaccess=: 983103




NB. 'type value'=. querykeyvalue hkey;subkey;value
querykeyvalue=: verb define
2000 querykeyvalue y.
:
'hkey subkey value'=. y.
'rc handle'=. regopen hkey;subkey
if. rc~:0 do. (-rc);'' return. end.
'rc x x x type data len'=. RegQueryValueExA handle;value;0;(,0);(x.${.a.);,x.
'unable to close' assertrc regclose handle
if. rc~:0 do. (-rc);'' return. end.
({.type);({.len){.data
)


NB. regopen key;subkey
regopen=: verb define
'hkey subkey'=. y.
'rc x x x x handle'=. RegOpenKeyExA hkey;subkey;0;fullaccess;,0
rc;{.handle
)


regclose=: verb define
>{.RegCloseKey ,<y.
)

assertrc=: ([ , ' ('"_ , ":@] , ')'"_) assert ]=0:















NB. publish

NB. publish 0 (or '')      create pub win
NB. publish 1              create pub win / open qsmact
NB. publish 'scriptname'   create pub win / open script

PUBLISH=: 0 : 0
pc publish;pn "Publisher";
menupop "&File";
menu open "&Open..." "Ctrl+O" "" "";
menu opensamp "Open Sample" "" "" "";
menusep ;
menu save "&Save..." "Ctrl+S" "" "";
menu saveas "Save &As..." "" "" "";
menusep ;
menu launch "&Launch Browser" "Ctrl+L" "" "";
menu preferences "&Preferences" "" "" "";
menusep ;
menu close "E&xit" "" "" "";
menupopz;
xywh 9 44 275 149;cc output ocx:$ rightmove bottommove;
xywh 6 32 283 165;cc ocxoutputbox groupbox rightmove bottommove;cn "Output";
xywh 253 16 40 12;cc close button leftmove rightmove;cn "Close";
xywh 122 16 40 12;cc edit button;cn "&Edit...";
xywh 164 16 40 12;cc schemeas button;cn "Save &As...";
xywh 11 15 100 60;cc scheme combolist;
xywh 6 4 204 28;cc gscheme groupbox;cn "Scheme";
pas 6 6;pcenter;
rem form end;
)

publish=: publish_run=: 3 : 0
if. wdisparent 'publish' do.
  wd 'psel publish;pactive'
else.
  S=: H=: ''
  readprefs ''
  if. _1=nc<'BROWSER' do.
    BROWSER=: BROWSER_j_
    if. 0 = #BROWSER do.
      BROWSER=: dfltbrowser ''
    end.
    writeprefs ''
  end.
  setscheme SCHEME
  readschemes ''
  clearschemes ''
  pubform ''
  wpset_j_ 'jpublish'
  wd 'pshow'
end.

arg=. y.
if. arg-:0 do. arg=. '' end.
if. arg-:1 do.
  smselact_jijs_ ''
  smsave_jijs_ ''
  arg=. id2name_jijs_ SMSEL_jijs_
end.

if. 0=#arg do. empty'' return. end.
publish_now (arg,~(relpath arg)#SCRIPTDIR,PATHSEP_j_#~PATHSEP_j_~:{:SCRIPTDIR),'.ijs'#~-.'.'e.({.~ -@(i.&PATHSEP_j_)@|.)arg
)

relpath=: ':'&e. < PATHSEP_j_&~:@{.

pubform=: verb define
x=. PUBLISH rplc '$';OCX
if. -.OCXYES do.
  x=. x rplc '%';'nosize nomax'
  x=. ;(#~ -.@:(+./@('ocx'&E.)@>)) <;.2 x end.
wd x-.'%'
NB. initialize form here
wd 'set scheme *',}.;LF,&.>SCHEMES
wd 'setselect scheme ',":SCHEMES i. <SCHEMEID
0 enable 'save saveas launch'
wd 'setfocus scheme;'
)


publish_close=: publish_close_button=: 3 : 0
wpsave_j_ 'jpublish'
wd 'psel publish;pclose'
)

publish_octrl_fkey=: publish_open_button=: 3 : 0
if. *#s=: wd 'mbopen "Open Script" "',SCRIPTDIR,'" "" "J Scripts (*.ijs)|*.ijs',Allfiles,'" ofn_filemustexist'
do. publish_now s end.
)

publish_opensamp_button=: publish_now bind PUBSMP


publish_now=: 3 : 0
if. _1-:x=. fread y. do.
  wd 'mb "Publish Open" "Unable to open script." mb_iconexclamation'
  return. end.
(H=: (S=: y.) page fmtlines toJ x) wr jpath '~temp\publish.htm'
wd 'psel publish'
1 enable 'save saveas launch'
if. OCXYES do.
  wd 'olemethod output ',OLEMETHOD,' *',tempname
  wd 'setcaption ocxoutputbox *',S end.
)

tempname=: 'file://',({.,'|'"_,2&}.) jpath '~temp\publish.htm'

NB. =========================================================
publish_lctrl_fkey=: publish_launch_button=: 3 : 0
f=. jpath '~temp\publish.htm'
f=. '/' (I. f='\') } f
wd 'winexec *',BROWSER,' file://',f
)


publish_browse_button=: 3 : 0
if. *#f=. wd 'mbopen "Browse" "" "" "J Script (*.ijs)|*.ijs',Allfiles,'" ofn_filemustexist'
do. wd 'set scriptname *',f end.
)

Allfiles=: '|All files (*.*)|*.*'

publish_saveas_button=: 3 : 0
if. *#f=. wd 'mbsave "Save As" "" "" "HTML (*.htm)|*.htm',Allfiles,'" ofn_overwriteprompt'
do. H save (, -.@('.'&e.)@(PATHSEP_j_&taketo&.|.) # '.htm'"_) f end.
)


publish_sctrl_fkey=: publish_save_button=: 3 : 0
H save (_4}.S),'.htm'
)


save=: dyad define
if. _1-:(toHOST x.) fwrite y. do.
  wd 'mb "Save" "Unable to save" mb_iconexclamation'
else.
  wd 'mb "Save" "Saved: ',y.,'" mb_iconinformation'
end.
)


publish_scheme_select=: publish_scheme_button=: 3 : 0
if. scheme-:SCHEMEID do. return. end.
NB. new scheme -- save prefs and process file
if. SCHEMEID-:'' do.  NB. refresh scheme and wipe ''
  SCHEMES=: SCHEMES-.a:
  wd 'set scheme *',}.;LF,&.>SCHEMES
  wd 'setselect scheme ',":SCHEMES i. <scheme
end.

SCHEMEID=: scheme
readschemes''
setscheme SCHEME=: do_jpub0_ SCHEMEID
clearschemes''
writeprefs''
if. *#S do. publish_now S end.
)


NB. publish_top_button=: verb define
NB. TOP=: {.".top
NB. wd 'ptop ',top
NB. writeprefs''
NB. )


publish_edit_button=: 3 : 0
pubscheme_run ''
)



publish_schemeas_button=: 3 : 0
newscheme_run''
)




publish_preferences_button=: 3 : 0
pubpref_run ''
)



enable=: dyad define
({.":x.) ([: wd 'setenable '"_ , ] , ' '"_ , [)&> ;:y.
)




show=: dyad define
({.":x.) ([: wd 'setshow '"_ , ] , ' '"_ , [)&> ;:y.
)












NB. default schemes

JpubNone=: 0 : 0
boxdraw chars=)asciibox
)

JpubReverse=: 0 : 0
global assign= bold,,
name=          ,0 255 255
local assign=  ,0 255 255
control word=  ,255 0 0,
bookmark=      italic bold,192 192 192,
comment=       italic,192 192 192,
string=        ,255 255 64,
normal=        ,0 255 255,
body=          ,0 0 0,255 255 255
boxdraw chars= )asciibox
)

JpubStandard=: 0 : 0
global assign= bold,,
control word=  ,255 0 0,
comment=       italic,0 128 0,
bookmark=      italic bold,0 128 0,
string=        ,0 0 192,
body=          ,255 255 255
boxdraw chars= )asciibox
)

pubBlueJay=: 0 : 0
global assign= bold,,
control word=  ,255 192 128,
bookmark=      italic bold,0 255 128,
comment=       italic,0 255 128,
string=        ,255 255 64,
body=          ,0 0 128,255 255 255
boxdraw chars= )asciibox
)

pubDesert=: 0 : 0
body=          ,255 239 213,0 0 255
global assign= bold,,
control word=  ,255 0 0,
bookmark=      italic bold,128 64 0,
comment=       italic,128 64 0,
string=        ,0 64 128
boxdraw chars= )FONT color '#804000'@asciibox
)




NB.   Preferences


PUBPREF=: 0 : 0
pc pubpref dialog nomax nosize owner;pn "Publish Preferences";
xywh 4 9 38 11;cc label static;cn "&Script dir:";
xywh 43 8 169 12;cc scrdir edit ws_border es_autohscroll;
xywh 4 32 206 63;cc gocx groupbox;cn "OCX Control";
xywh 16 43 74 11;cc ocxno radiobutton;cn "&No OCX control";
xywh 16 57 74 11;cc ocxyes radiobutton group;cn "&Use OCX control:";
xywh 26 68 59 11;cc cocxcon static ss_right;cn "&OCX Control:";
xywh 26 80 59 11;cc colemeth static ss_right;cn "OLE &Method:";
xywh 92 66 111 12;cc ocxcon edit ws_border es_autohscroll;
xywh 92 79 111 12;cc olemeth edit ws_border es_autohscroll;
xywh 220 63 40 12;cc cancel button;cn "Cancel";
xywh 220 79 40 12;cc ok button;cn "OK";
pas 6 6;pcenter;
rem form end;
)

pubpref_run=: 3 : 0
wd PUBPREF
wd 'set scrdir *',SCRIPTDIR
NB. wd 'set brwsr *',BROWSER
ORIGOCXYES=: OCXYES
wd 'set ocxno ',(":-.OCXYES),';set ocxyes ',":OCXYES
ocxenable OCXYES
wd 'set ocxcon *',OCX
wd 'set olemeth *',OLEMETHOD
wd 'pshow;'
)

pubpref_close=: 3 : 0
wd'pclose'
)

pubpref_cancel_button=: 3 : 0
pubpref_close''
)


NB. pubpref_browsebr_button=: 3 : 0
NB. if. #b=. wd 'mbopen "Select Browser" "',(BROWSER}.~-PATHSEP_j_ i.~|.BROWSER),'" "',BROWSER,'" "Executables|*.exe" ofn_filemustexist'
NB. do. wd 'set brwsr *',b end.
NB. )

pubpref_ok_button=: 3 : 0
SCRIPTDIR=: scrdir
NB. BROWSER=: brwsr
OCXYES=: {.".ocxyes
OCX=: ocxcon
OLEMETHOD=: olemeth
writeprefs''
wd 'pclose;psel publish'
if. OCXYES~:ORIGOCXYES do.  NB. must recreate publish window
  x=. wd 'qformx'
  wd 'pclose'
  pubform ''
  wd 'pmovex ',x,';pas 6 6;pshow'
  wdfit '' end.
)

pubpref_ocxno_button=: ocxenable bind 0
pubpref_ocxyes_button=: ocxenable bind 1


ocxenable=: verb define
y. enable 'cocxcon colemeth ocxcon olemeth'
)












NB.   Scheme editor

PUBSCHEME=: 0 : 0
pc pubscheme dialog nomax nosize owner;pn "Edit Scheme";
xywh 6 6 84 121;cc gverbs groupbox;cn "&Elements";
xywh 11 18 73 108;cc fmverbs listbox ws_vscroll;
xywh 6 127 84 74;cc gdesc groupbox rightmove;cn "Description";
xywh 9 138 76 59;cc desc static ss_noprefix rightmove;cn "";
xywh 96 8 2 191;cc ccstaticbox staticbox ss_blackframe;
xywh 116 23 185 38;cc gfont groupbox;cn "Font";
xywh 158 29 93 11;cc curfont static ss_center ss_noprefix;cn "";
xywh 123 42 40 12;cc fontdefault button;cn "&Default";
xywh 173 42 12 11;cc fontitalic checkbox;cn "&I";
xywh 193 42 15 11;cc fontbold checkbox;cn "&B";
xywh 210 42 27 67;cc fontsize combolist;
xywh 240 42 40 12;cc fontspecify button;cn "S&pecify...";
xywh 116 66 185 38;cc gcolor groupbox;cn "Color";
xywh 123 81 40 12;cc colordefault button;cn "De&fault";
xywh 165 81 70 10;cc curcolor isigraph;
xywh 183 82 39 10;cc curcolordefault static ss_center;cn "(default)";
xywh 240 81 40 12;cc colorspecify button;cn "Spe&cify...";
xywh 116 108 185 38;cc gfgcolor groupbox;cn "Foreground Color";
xywh 123 126 40 12;cc fgcolordefault button;cn "Def&ault";
xywh 165 126 70 10;cc curfgcolor isigraph;
xywh 183 127 39 10;cc curfgcolordefault static ss_center;cn "(default)";
xywh 240 126 40 12;cc fgcolorspecify button;cn "Specif&y...";
xywh 107 160 151 11;cc bverb radiobutton;cn "by &Verb definition:";
xywh 112 174 154 12;cc defn edit ws_border es_autohscroll rightmove;
xywh 322 10 40 12;cc ok button leftmove rightmove;cn "&OK";
xywh 322 26 40 12;cc cancel button leftmove rightmove;cn "Cancel";
xywh 107 7 48 11;cc bsample radiobutton;cn "by &Sample:";
xywh 309 8 2 191;cc ccstaticbox staticbox ss_blackframe;
xywh 322 50 40 12;cc help button;cn "&Help...";
pas 6 6;pcenter;
rem form end;
)



pubscheme_run=: 3 : 0
wd PUBSCHEME
wd 'set fmverbs *',}.;LF,&.>oschemenames
sch=: splitscheme SCHEME   NB. "local" copy for editing
wd 'set fontsize *',;LF,&.>stdsizes=: <@":"0 ]8 10 12 14 18 24 36
pubset '0'
wd 'setselect fontsize 0'
wd'setfocus fmverbs'
wd'setfont defn isij 12'
wd 'pshow;'
)



pubset=: verb define
wd 'setselect fmverbs ',y.
d=. (curscheme=: >oschemenames{~".y.) from :: (''"_) sch
wd 'set desc *', >oschemedescs {~ oschemenames i. <curscheme

isbody=. 0=".y.
(d;isbody) spectype isverb=. ')'={.1{.d
isbody show 'gfgcolor fgcolordefault fgcolorspecify'
)


NB. defn spectype type
NB. set specify type: 0-sample; 1-verb
NB. x. is defn;isbody
spectype=: dyad define
'd b'=. x.
(-.y.) enable 'gfont gcolor gfgcolor curfont curcolor curfgcolor fontdefault colordefault fgcolordefault fontspecify colorspecify fgcolorspecify fontitalic fontbold fontsize'
y. enable 'defn'
wd 'setcaption gcolor *',>b{'Color';'Background Color'
wd 'set ',(>y.{;:'bsample bverb'),' 1'
lastby=: y.
if. y. do. wd 'set defn *',}.d   NB. verb
  0 show 'curcolor curcolordefault curfgcolor curfgcolordefault'
  wd 'set fontitalic 0;set fontbold 0;setselect fontsize 0'
  prepsamp 0
  wd 'set curfont *'
else. wd 'set defn *'        NB. sample
  prepsamp d
  writesamp b end.
)


NB. =========================================================
NB. rip apart sample     ('font color [fgcolor]')
NB. into:   sampfont, sampcolor, and sampfgcolor
prepsamp=: verb define
if. y.-:0 do. 'sampfont sampcolor sampfgcolor'=: 0 return. end.  NB. recognize no sample
m=. *#@> x=. deb&.> 3{.(<;._1',',y.),3#a:
x=. ({. , ".&.>@}.) x
'sampfont sampcolor sampfgcolor'=: m{"0 1 ] 0;"0 x
)


NB. writesamp - write sample defn onto controls (arg is isbody)
writesamp=: verb define
wd 'set curfont *',>(sampfont-:0){sampfont;'(default)'
if. (sampfont-:0) do. wd 'set fontitalic 0;set fontbold 0;setselect fontsize 0'
elseif. -.'"' e. sampfont do. x=. ;:sampfont
  wd 'set fontitalic ',":x e.~ <'italic'
  wd 'set fontbold ',":x e.~ <'bold'
  wd 'setselect fontsize ',":>./8|>:stdsizes i. x
end.
(sampcolor-:0) show 'curcolordefault'
(-.sampcolor-:0) show 'curcolor'
(y. *. sampfgcolor-:0) show 'curfgcolordefault'
(y. *. -.sampfgcolor-:0) show 'curfgcolor'
if. -.sampcolor-:0 do. 'curcolor' paintcolor sampcolor end.
if. -.sampfgcolor-:0 do. 'curfgcolor' paintcolor sampfgcolor end.
)



NB. paintcolor - paint control x. with color y.
paintcolor=: dyad define
glshow '' [ glrect 0 0 1000 1000 [ glbrush [ glrgb y. [ glsel x.
)





NB. font overrides:  don't set font, just bold/italic/size

pubscheme_fontitalic_button=: pubscheme_fontbold_button=: pubscheme_fontsize_select=: 3 : 0
sampfont=: deb fontsize,' ',('italic'#~".fontitalic),' ',('bold'#~".fontbold)
appendcurrent''
pubset fmverbs_select
)






pubscheme_bsample_button=: 3 : 0
if. lastby=0 do. return. end.  NB. No change
lastby=: 0
prepsamp newsamp ''
bverb=: '0'
appendcurrent''
pubset fmverbs_select
)

pubscheme_bverb_button=: 3 : 0
if. lastby=1 do. return. end.  NB. No change
lastby=: 1
defn=: newverb fmverbs
bverb=: '1'
appendcurrent''
pubset fmverbs_select
)




NB. create new sample from verb
newsamp=: verb define
''
)




NB. create new verb from sample
newverb=: verb define
body=. y.-:'body'
v=. ('bold' isin sampfont)#<'STRONG'
v=. v,('italic' isin sampfont)#<'EM'
f=. >{.a:,~ }.@}:&.> (#~ ''''&=@{.@>) w=. ;:'"''' charsub :: (''"_) sampfont
s=. >{.a:,~ (#~ e.&'0123456789'@{.@>) w
c=. (body +: sampcolor-:0)#' color ',fmtcolor sampcolor
v=. v,~(*#f,s,c)#<'FONT',((*#f)#' face ''',f,''''),((*#s)#' size ',(":>:@(+/)@(>&9 11 13 16 20 30){.0,~".s)),c
x=. }:;v,&.>'@'
if. body do.
  b=. 'BODY',(-.sampcolor-:0)#' bgcolor ',fmtcolor sampcolor
  b=. b,(-.sampfgcolor-:0)#' text ',fmtcolor sampfgcolor
  x=. b,((*#x)#'@'),x,'@]' end.
>(*#x){']';x
)


tohex=: ,@:((_2&{.)@('0'&,)@hfd"0)

mapcolor=: verb def '>(({."1 colormap) i. <2}.}:y.){ ({:"1 colormap),<y.'

fmtcolor=: mapcolor@('''#'"_ , tohex , ''''"_)



colormap=: (({.;}.@}.)~ i.&' ');._2 noun define
000000 Black
C0C0C0 Silver
800000 Maroon
C00000 Red
008000 Green
00C000 Lime
000080 Navy
0000C0 Blue
808080 Gray
000000 White
800080 Purple
C000C0 Fuchsia
808000 Olive
C0C000 Yellow
008080 Teal
00C0C0 Aqua
FFFFFF White
)







pubscheme_close=: pubscheme_cancel_button=: 3 : 0
wd'pclose'
)



pubscheme_fmverbs_select=: 3 : 0
appendcurrent''
pubset fmverbs_select
)


appendcurrent=: 3 : 0
if. ".bverb do. x=. ')',defn else.
  x=. (dflt sampfont),',',(dflt sampcolor),',',dflt sampfgcolor
end.
sch=: (#~ ~:@:({."1)) sch,~curscheme;x
)


dflt=: verb define
>(y.-:0){(":y.);''
)



refresh=: 3 : 0
appendcurrent''
pubset fmverbs_select
)


pubscheme_fontdefault_button=: 3 : 0
sampfont=: 0
refresh''
)

pubscheme_colordefault_button=: 3 : 0
sampcolor=: 0
refresh''
)

pubscheme_fgcolordefault_button=: 3 : 0
sampfgcolor=: 0
refresh''
)



pubscheme_fontspecify_button=: 3 : 0
if. 0=#x=. wd 'mbfont' do. return. end.
sampfont=: x
wd 'set fontitalic 0;set fontbold 0;setselect fontsize 0'
refresh''
)


pubscheme_colorspecify_button=: 3 : 0
if. 0=#x=. wd 'mbcolor' do. return. end.
sampcolor=: 3{.".x
refresh''
)

pubscheme_fgcolorspecify_button=: 3 : 0
if. 0=#x=. wd 'mbcolor' do. return. end.
sampfgcolor=: 3{.".x
refresh''
)


pubscheme_ok_button=: verb define
appendcurrent''
x=. (>@{. , '='"_ , >@{:)"1 sch
SCHEME=: ,x,"1 0 LF
SCHEMEID=: ''
SCHEMES=: '';SCHEMES-.a:
setscheme SCHEME
writeprefs ''
wd 'pclose;psel publish'
wd 'set scheme *',}.;LF,&.>SCHEMES
wd 'setselect scheme ',":SCHEMES i. <SCHEMEID
if. *#S do. publish_now S end.
)



pubscheme_help_button=: 3 : 0
'jpubhelp' wdview 'Publisher Help';helptext;1;0
)

helptext=: noun define
>>> Editing a Scheme:

Font and color attributes can be selected for each of the elements on the left.

Each element can be defined by sample (simply selecting font and color attributes), or by verb definition.  With a verb definition, the specified verb is applied to each fragment of the script matching the element.  See the web.ijs script for HTML-producing definitions.

The "body" element specifies background color, and default foreground color and font.

A font can be specified in one of three ways:  Use the default, specify simply as bold/italic and size (no face), or fully specified with the "specify" button.

Colors are specified either as default, or by explicitly specifying them.


>>> Restrictions:

More element types will be added.

No documentation exists for the web definitions for use in the verb definition.

Publisher schemes are distinct from session manager schemes.
)














NB.   New scheme dialog

NEWSCHEME=: 0 : 0
pc newscheme dialog nomax nosize owner;pn "Save Scheme";
xywh 6 6 88 29;cc gprompt groupbox;cn "Enter scheme name";
xywh 11 18 78 12;cc name edit ws_border es_autohscroll;
xywh 7 42 40 12;cc cancel button;cn "Cancel";
xywh 51 42 40 12;cc ok button bs_defpushbutton;cn "OK";
pas 6 6;pcenter;
rem form end;
)

newscheme_run=: 3 : 0
wd NEWSCHEME
wd 'setfocus name'
wd 'pshow;'
)

newscheme_close=: newscheme_cancel_button=: 3 : 0
wd'pclose;psel publish'
)


newscheme_name_button=: newscheme_ok_button=: 3 : 0
readschemes''
do name,'_jpub0_=: SCHEME_jpublish_'
SCHEMES=: /:~ ~.name;SCHEMES-.a:
writeschemes''
clearschemes''
wd 'pclose;psel publish'
wd 'set scheme *',}.;LF,&.>SCHEMES
wd 'setselect scheme ',":SCHEMES i. <SCHEMEID=: name
)
