NB. built from project: ~Source\main\config\config
NB. built from makegl2.ijs

script_z_ '~system\main\dll.ijs'
script_z_ '~system\main\files.ijs'
script_z_ '~system\main\strings.ijs'

coclass 'jcfg'


glbrush=: 11!:2004
glclear=: 11!:2007
gllines=: 11!:2015
glmap=: 11!:2016
glpen=: 11!:2022
glrect=: 11!:2031
glrgb=: 11!:2032
glsel=: 11!:2035
glshow=: 11!:2036
glwantresize=: 11!:2068
MM_RAW=: 1
18!:4 <'jcfg'

FKEYQ=: 197 { a.           
MAXSMSTYLE=: IFJAVA { 3 2  
SMCOLORORG=: ''            
val=: 3;''
0!:0 < jpath '~system\extras\config\colordef.ijs'
cfv=: 3 : 0
USERNAME=: deb USERFNAME,' ',USERLNAME
val=: 3;''
0!:0 :: ] <jpath '~system\extras\util\jul.ijl'
0 pick val
)
cutfolders=: 3 : 0
j=. <;._2 y.
ndx=. j i.&> ' '
nms=. ndx {.each j
pth=. jpath each deb each (ndx+1) }.each j
nms,.pth
)
deb=: #~ (+. (1: |. (> </\)))@(' '&~:)
wdc=: 3 : 0
try. wd y.
catch.
  err=. wd 'qer'
  ndx=. >: err i. ':'
  msg=. ndx {. err
  pos=. {. ". ndx }. err
  cmd=. (>:j i.';') {. j=. pos}.y.
  if. 50 < #cmd do.
    cmd=. (47{.cmd),'...' end.
  wdinfo 'Window Driver';'wd error ',msg,LF,cmd
end.
)
cfread=: 3 : 0
0!:0 <jpath '~system\extras\config\stdcfg.ijs'
if. UNAME -: 'Darwin' do. JAVALAF=: 'Mac' end.
0!:0 :: ] <jpath '~config\config.ijs'
OUTPUT=: 0, }. OUTPUT
NEWUSER=: 1 <. NEWUSER + cfv''
USERFOLDERS=: cutfolders USERFOLDERS
)
configure=: 3 : 0
if. y.=0 do.
  cfread''
end.
configrun y.
configdel ''
)
configrun=: 3 : 0

9!:3 DISPLAYFORM
9!:7 BOXFORM { BOXES
9!:11 PRINTPREC
9!:17 BOXPOS
9!:21 (2&^ ^: (<&_)) MEMORYLIM
9!:37 OUTPUT
if. IFJAVA do.
  FIXFONT_z_=: FIXFONTJ
  PROFONT_z_=: PROFONTJ
else.
  FIXFONT_z_=: FIXFONTW
  PROFONT_z_=: PROFONTW
end.
if. IFJAVA do.
  a=. _2 [\ <;._2 wd 'javalaf'
  nms=. 0 {"1 a
  ndx=. (#nms) | nms i. <JAVALAF
  val=. > (<ndx;1) { a
  wd 'javasetlaf *',val
end.
BROWSER_j_=: BROWSER
DIRTREEX_j_=: DIRTREEX
EPSREADER_j_=: EPSREADER
PDFREADER_j_=: PDFREADER
FORMSIZES_j_=: FORMSIZES
P2UPFONT_j_=: P2UPFONT
SMPRINT_j_=: SMPRINT
PRINTERFONT_j_=: PRINTERFONT
PRINTOPT_j_=: PRINTOPT
XDIFF_j_=: XDIFF
USERFOLDERS_j_=: USERFOLDERS
clr=. getcolors SMCOLOR
if. -. clr -: SMCOLORORG do.
  setcolors clr
end.
set_fkeys_jijs_ FKEYS
set_skeys_jijs_ SKEYS

SMINIT_jijs_=: SMINIT
SMSIZE_jijs_=: SMSIZE
SMSTYLE_jijs_=: MAXSMSTYLE <. SMSTYLE
NEWUSER_jijs_=: NEWUSER
wdc 'fontdef ',PROFONT
if. y. do.
  setfontall_jijs_ FIXFONT
  setpnall_jijs_ ''
  wd 'psel ',JCFH
end.
if. y.=0 do.
  if. 1!:4 :: 0: <STARTUP do.
    startup=. STARTUP
    18!:4 <'base'
    try.
      load startup
    catch.
      wdinfo 'J Profile';'An error occurred when loading startup script: ',startup
    end.
    18!:4 <'jcfg'
  end.
end.
)
configdel=: coerase bind (<'jcfg')

delfret=: }: , {: -. PATHSEP_j_"_
dtb=: #~ +./\.@(' '&~:)
extijs=: , ([: -. '.'"_ e. ]) # '.ijs'"_
expand=: #^:_1

fexist=: 1:@(1!:4)@boxopen ::0:
index=: #@[ (| - =) i.
info=: wdinfo @ ('Config'&;)
inx1=: #@[ (| - =) i.
isnnint=: ((1: e. 0&>) < (-: <.) *. 1: = #) :: 0:

pathname=: 3 : '(b#y.);(-.b=.+./\.y.=PATHSEP_j_)#y.'
query=: wdquery 'Config'&;

a=. ''''
quote=: (a&,@(,&a))@ (#~ >:@(=&a))

sort=: /:~ :/:
subs=: 2 : 'x."_ I. @(e.&y.)@]} ]'
vectoblank=: deb @ (' ' subs LF)

tolist=: }. @ ; @: ((10{a.)&,@,@":each)
toeav=: ; @: (EAV&, @ (,&(EAV,' ')) each)
cutcommas=: 3 : 0
if. #y. do.
  a: -.~ <;._1 ',', y.
else.
  ''
end.
)
freads=: ''&$: : (4 : 0)
y=. boxopen y.
f=. 1!:(1 11 {~ 2=#y)
dat=. f :: _1: y
if. (dat -: _1) +. 0=#dat do. return. end.
dat=. dat,LF -. {:dat=. toJ dat
if. 'b'e.x. do. dat=. <;._2 dat
elseif. 'm'e.x. do. dat=. ];._2 dat
end.
)
fwrites=: 4 : 0
y=. boxopen y.
dat=. ":x.
if. -. 0 e. $dat do.
  if. 1>:#$dat do.
    dat=. toHOST dat
    dat=. dat,(LF ~: {:dat)#CRLF
  else. dat=. dat,"1 CRLF
  end.
end.
dat=. ,dat
f=. #@[ [ 1!:2
dat f :: _1: y
)
moveindex=: 4 : 0
'ndx dat'=. y.
if. x. do.
  nd1=. (<:#dat) <. ndx+1
else.
  nd1=. 0 >. ndx-1
end.
ind=. ndx, nd1
nd1;<(|. ind { dat) ind} dat
)
nubmatrix0=: ([: ~: [: {."1 ]) # ]
textline=: 3 : 0
deb ; (,&' ' ;._2) y.
)
towordlist=: 3 : 0
n=. boxxopen y.
m=. ' ' e.&> n
p=. m { '';'"'
}. ' ' ,each p ,each n ,each p
)


config=: 3 : 0
if. wdisparent 'cfmain' do.
  wd 'psel cfmain;pactive' return.
end.
TABNDX=: 0
FKEYNDX=: 0
cfread''
setfields''
COLORDATAORG=: COLORDATA
SMCOLORIDORG=: SMCOLORID
SMCOLORORG=: getcolors SMCOLOR
cfmain_run''
)
cfmain_cancel_button=: 3 : 0
wd 'fontdef ',PROFONT
setcolors COLORDATAORG
setfontall_jijs_ FIXFONT
wd 'psel ',JCFH
wd 'pclose'
configdel ''
smselout_jijs_''
smfocus_jijs_''
)
cfmain_cancel=: cfmain_cancel_button
cfmain_defaults_button=: 3 : 0
j=. 'This sets the default configuration for all items.',LF,LF
j=. j, 'OK to continue?'
if. 2 query j do. return. end.
0!:0 <jpath '~system\extras\config\stdcfg.ijs'
setfields''
info 'Default configuration set'
now=. TABNDX { TABGROUPS
fms=. (LOADED -. now), now
for_f. fms do.
  nam=. > f
  (nam,'_run')~1
  wd 'setshow ',nam,' ', ": f-:now
end.
)
boxfont=: 3 : 0
font=. ' ',y.
b=. (font=' ') > ~:/\font='"'
a: -.~ b <;._1 font
)
cfmain_ok_button=: 3 : 0

cfv''
if. #smfont do.
  ('FIXFONT',IFJAVA{'WJ')=: smfont
end.

SMPRINT=: SMPRINT,(0=#SMPRINT)#'print'
PRINTOPT=: }. ; ';' ,each PRINTOPTX
BOXFORM=: '1'={.ascii
DISPLAYFORM=: ('1'=linear,box,tree,parens)#5 2 4 6
NEWUSER=: ". newuser
STATUSBAR=: ". statusbar

(2 }.each ALLTABGROUPS)=. ALLTABGROUPS e. LOADED
if. extern do.
  BROWSER=: browser
  EPSREADER=: epsreader
  PDFREADER=: pdfreader
  XDIFF=: xdiff
end.
if. color do.
  SMCOLOR=: setcolordata COLORDATA
  try.
    smsel_jijs_ SAMPLEFILE
    smsave_jijs_''
    smclose_jijs_''
  catch.
  end.
  smselout_jijs_''
end.
if. folder do.
  USERFOLDERS_j_=: USERFOLDERS
end.
if. forms do.
  if. #fontdef do.
    ('PROFONT',IFJAVA{'WJ')=: fontdef
  end.
  FORMSIZES=: 0 ". &> bwidth;bheight;ewidth;eheight;lheight
end.
if. laf do.
end.
if. lic do.
  cflic_get''
  cfv''
  if. 1 = 0 pick val do.
    info 'License entered is for release ',": 1 pick val
  end.
  if. 3 = 0 pick val do.
    info 'Invalid J User License'
  end.
end.
if. opts do.
  j=. 9!:11 :: _1: [ _1 ". cpp
  if. _1-:j do.
    info 'Invalid setting for print precision'
    return.
  end.
  PRINTPREC=: 9!:10''
  
  linelen=. _1 ". maxlinelength
  if. -. isnnint linelen do.
    info 'Invalid setting for Max Line Length'
    return.
  end.
  
  linebef=. _1 ". maxlinesbefore
  if. -. isnnint linebef do.
    info 'Invalid setting for Max Lines Before'
    return.
  end.
  lineaft=. _1 ". maxlinesafter
  if. -. isnnint lineaft do.
    info 'Invalid setting for Max Lines After'
    return.
  end.
  OUTPUT=: 0, linelen, linebef,lineaft
end.
if. print do.
  P2UPFONT=: p2font,(0=#p2font)#P2UPFONT
  PRINTERFONT=: pfont,(0=#pfont)#PRINTERFONT
end.
if. fkeys do.
  FKEYS_jijs_=: BOXFKEYS
  FKEYS=: unboxfkeys_jijs_ BOXFKEYS
end.
if. sess do.
  cfsess_read''
  DIRTREEX_j_=: DIRTREEX
end.
if. skeys do.
  mn=. MENU -. OLDMENU
  if. 0 = #mn do.
    SKEYS=: ''
  else.
    a=. 0 {"1 mn
    b=. 1 {"1 mn
    SKEYS=: ; a ,each ' ' ,each b ,each LF
  end.
end.
if. start do.
  SMINIT=: 4 {. a , (#a) }. 0 0 700 500 [ a=. 0 ". sminit
  SMSIZE=: 2 {. a , (#a) }. 700 500 [ a=. 0 ". smsize
  STARTUP=: startup
  SMSTYLE=: 0 ". smstyle_select
end.
if. '1'=saveconfig do. configsave'' end.
configure 1

wd 'pclose'
)

cfmain_close=: cfmain_ok_button
getfontstyle=: 3 : 0
if. 0=#y. do. '' return. end.
y=. boxfont y.
y=. ({.y),tolower each }.y
s=. (#~ e.&y) 'oem';'default'
{.s,<'ansi'
)
mbfont=: 3 : 0
arg=. y.
if. #arg do.
  arg=. boxfont arg
  arg=. ({.arg), tolower each }.arg
  arg=. arg -. 'ansi';'oem';'default'
  arg=. }: ; ,&' ' &.> arg
end.
res=. wd 'mbfont ',arg
if. IFJAVA do.
  txt=. ' ',res
  b=. (txt=' ') > ~:/\txt='"'
  txt=. a: -.~ b <;._1 txt
  if. 3 = #txt do.
    num=. _1 ". &> txt
    if. ((1 { num) e. 0 1 2) *. _1 ~: 2 { num do.
      sty=. (1 { num) pick '';'bold';'italic'
      res=. (0 pick txt),' ',(2 pick txt),' ',sty
    end.
  end.
end.
deb res
)
setfontstyle=: 4 : 0
if. 0=#y. do. '' return. end.
x=. boxopen x.
y=. boxfont y.
y=. ({.y), tolower each }.y
y=. y -. 'ansi';'oem';'default'
y=. y,(x e. 'oem';'default')#x
}: ; ,&' ' &.> y
)
setfields=: 3 : 0
if. IFJAVA do.
  smfont=: FIXFONTJ
  fontdef=: PROFONTJ
else.
  smfont=: FIXFONTW
  fontdef=: PROFONTW
end.
if. 0 = #SMCOLOR -. LF,' ' do. SMCOLOR=: '' end.
COLORDATA=: getcolordata SMCOLOR
newuser=: ":NEWUSER
p2font=: P2UPFONT
pfont=: PRINTERFONT
PRINTOPTX=: ';' cutopen PRINTOPT
'linear box tree parens'=: 1 ": 5 2 4 6 e. DISPLAYFORM
'linedraw ascii'=: 1 ": 0 1=BOXFORM
statusbar=: ":STATUSBAR
'bwidth bheight ewidth eheight lheight'=: ": each FORMSIZES
sminit=: ": SMINIT
smsize=: ": SMSIZE
BOXFKEYS=: boxfkeys_jijs_ FKEYS
)

CFEDSKEY=: 0 : 0
pc cfedskey dialog owner;pn "Menu Shortcuts Edit";
xywh 7 9 52 11;cc s0 static;cn "Menu Item:";
xywh 61 9 110 100;cc item combolist ws_vscroll;
xywh 7 28 52 11;cc s1 static;cn "Shortcut Key:";
xywh 61 27 110 100;cc menu combolist ws_vscroll;
xywh 178 9 44 12;cc ok button;cn "OK";
pas 6 6;pcenter;
rem form end;
)
cfedskey_run=: 3 : 0
sk=. '{none}';skeyevents''
wd CFEDSKEY
if. 0 <: SKEYNDX do. 
  'fn ck id'=. SKEYNDX { MENU
  wd 'set item *',id
  wd 'setselect item 0'
  wd 'setenable item 0'
  wd 'set menu ',toeav sk
  wd 'setselect menu ',": sk i. <ck
else. 
  msk=. 0 = # &> 1 {"1 MENU
  if. -. 1 e. msk do.
    info 'All menu items have shortcuts'
    wd 'pclose' return.
  end.
  wd 'set item ',toeav msk # 2 {"1 MENU
  wd 'set menu ',toeav sk
end.
wd 'pshow'
)
cfedskeyerr=: wdinfo @ ('Menu Shortcuts Edit'&;)
cfedskey_cancel_button=: 3 : 0
wd 'pclose'
)
cfedskey_ok_button=: 3 : 0
cfedskey_setmenu''
wd 'psel cfmain'
cfshowskeyset''
wd 'psel cfedskey;pclose;psel cfmain'
)
cfedskey_setmenu=: 3 : 0
if. 0 > SKEYNDX do.
  if. 0 = #item do. return. end.
  SKEYNDX=: (2 {"1 MENU) i. < item
end.
if. menu -: '{none}' do.
  MENU=: (<<<SKEYNDX) { MENU
  SKEYNDX=: _1
else.
  if. (<menu) e. (<<<SKEYNDX) { 1 {"1 MENU do.
    msg=. 'Shortcut ',menu,' is already in use.'
    msg=. msg,LF,'Add it anyway?'
    if. 2 wdquery 'Menu Shortcuts Edit';msg do. return. end.
  end.
  MENU=: (<menu) (<SKEYNDX;1) } MENU
end.
)
skeyevents=: 3 : 0
f=. 'F' ,each ": each 1 + i.12
r=. f
r=. r, (<'Ctrl+') ,each f
r=. r, (<'Shift+') ,each f
r=. r, (<'Ctrl+Shift+') ,each f
a=. a. {~ ; (a. i. 'A0') + each i. each 26 10
s=. (<'Ctrl+') ,each a
s=. s, (<'Ctrl+Shift+') ,each a
s=. s -. 'Ctrl+C';'Ctrl+V';'Ctrl+X';'Ctrl+Z'
s, r
)

CFEDFKEY=: 0 : 0
pc cfedfkey dialog owner;pn "FKeys Edit";
xywh 7 8 61 11;cc sfkey static;cn "Function Key:";
xywh 70 8 60 11;cc keyname static;cn "keyname";
xywh 70 7 121 100;cc key combolist ws_vscroll;
xywh 7 29 74 53;cc g0 groupbox;cn "Output";
xywh 14 40 59 12;cc noisy radiobutton;cn "Noisy";
xywh 14 53 59 12;cc quiet radiobutton group;cn "Quiet";
xywh 14 66 59 12;cc prompt radiobutton group;cn "Prompt";
xywh 7 91 34 11;cc s0 static;cn "Label:";
xywh 42 91 95 12;cc label edit ws_border es_autohscroll;
xywh 7 108 34 11;cc s1 static;cn "Code:";
xywh 42 108 183 12;cc code edit ws_border es_autohscroll;
xywh 208 7 44 12;cc ok button;cn "OK";
xywh 208 23 44 12;cc cancel button;cn "Cancel";
pas 6 6;pcenter;
rem form end;
)
cfedfkey_run=: 3 : 0
wd CFEDFKEY
if. 0 <: FKEYNDX do.
  'key out label code'=. FKEYNDX{BOXFKEYS
  wd 'set keyname ',": fkeycase_jijs_ key
  wd 'set prompt ',":out='0'
  wd 'set quiet ',":out='1'
  wd 'set noisy ',":out='2'
  wd 'set label *',label
  wd 'set code *',code
  wd 'setshow key 0'
else.
  all=. , ('F',each ":each 2 + i.11) ,each"0/ '';'Alt';'Ctrl';'CtrlShift';'Shift'
  usd=. fkeycase_jijs_ each {."1 BOXFKEYS
  dif=. all -. usd
  if. 0 = #dif do.
    info 'All function keys are assigned'
    wd 'pclose' return.
  end.
  wd 'set key ',toeav dif
  wd 'setselect key 0'
end.
wd 'pshow'
)
cfedfkeyerr=: wdinfo @ ('Fkeys Edit'&;)
cfedfkey_cancel_button=: 3 : 0
wd 'pclose'
)
cfedfkey_ok_button=: 3 : 0
if. 0 <: FKEYNDX do.
  key=: 0 pick FKEYNDX{BOXFKEYS
else.
  key=: tolower key
end.

out=. ": (prompt,quiet,noisy) i. '1'
if. 0=#label do. cfedfkeyerr 'Enter the Label' return. end.
if. 0=#code do. cfedfkeyerr 'Enter the Code' return. end.
rep=. key;out;label;code
if. 0 <: FKEYNDX do.
  BOXFKEYS=: rep FKEYNDX } BOXFKEYS
else.
  if. #BOXFKEYS do.
    j=. rep,BOXFKEYS
    srt=. 0 ". each (}.each {."1 j) -. each <(>: a.i.'9') }. a.
    BOXFKEYS=: j /: srt ,. j
    FKEYNDX=: ({."1 BOXFKEYS) i. <key
  else.
    BOXFKEYS=: ,:rep
    FKEYNDX=: 0
  end.
end.
wd 'psel cfmain'
cfshowfkeyset''
wd 'psel cfedfkey;pclose;psel cfmain'
)

SAMPLEFILE=: jpath '~system\extras\config\colorsmp.ijs'
CFCOLOR=: 0 : 0
pc cfcolor;pn "Session Color";
xywh 6 8 248 29;cc g0 groupbox;cn "Scheme";
xywh 11 19 135 120;cc scheme combolist ws_vscroll;
xywh 156 19 44 12;cc saveas button;cn "Save As...";
xywh 202 19 44 12;cc deletescheme button;cn "&Delete...";
xywh 6 44 248 121;cc g1 groupbox;cn "Item";
xywh 11 55 135 108;cc item listbox ws_vscroll;
xywh 156 56 44 12;cc color button;cn "Color...";
xywh 202 56 44 12;cc add button;cn "&Add";
xywh 156 68 44 12;cc edit button;cn "Edit...";
xywh 202 68 44 12;cc delete button;cn "&Delete...";
xywh 156 85 90 13;cc gcolor isigraph;
xywh 156 103 90 11;cc italic checkbox;cn "Italic";
xywh 156 115 90 11;cc underline checkbox;cn "Underline";
xywh 156 131 44 12;cc moveup button;cn "&Move Up";
xywh 202 131 44 12;cc movedn button;cn "&Move Down";
xywh 156 146 90 12;cc sample button;cn "Show Sample";
pas 2 2;pcenter;
rem form end;
)
cfcolor_run=: 3 : 0
if. y.=0 do.
  wd CFCOLOR
end.
glsel 'gcolor'
COLORDATA=: getcolordata SMCOLOR
COLORMB=: 48$255
ckread''                 
csread''                 
css=. {."1 COLORSCHEMES
names=. 4 {"1 COLORDATA
cfcolorsetschemes''
if. SMCOLORID -: 'None' do. cfdisable 1 end.
wd 'set item *',tolist names
cfcoloritem 0
)
cfcolor_act=: 3 : 0
glsel 'gcolor'
)
cfcolor_color_button=: 3 : 0
sel=. 0 ". item_select
ndx=. < sel;1
old=. > ndx { COLORDATA
new=. ,0 ". wd 'mbcolor ',":old,COLORMB
if. #new do.
  if. -. new -: old do.
    COLORDATA=: (<3 {. new) ndx} COLORDATA
    COLORMB=: 3 }. new
    cfcoloranon ''
    cfcolorgraph 3 {. new
    cfcolorapply''
  end.
end.
)
cfcolor_delete_button=: 3 : 0
sel=. 0 ". item_select
'num val j j txt j'=. sel { COLORDATA
if. num e. 0 1 do.
  info 'You cannot delete this color item' return.
end.
if. 0 = 2 query 'OK to delete color item:',LF,LF,txt do.
  cfcoloranon''
  COLORDATA=: (<<<sel) { COLORDATA
  nums=. > {."1 COLORDATA
  nums=. nums - (num e. USRCOLORS) *. nums > num
  COLORDATA=: (<&>nums) ,. }."1 COLORDATA
  sel=. sel <. <: #COLORDATA
  sel cfcolorreset ''
end.
)
cfcolor_deletescheme_button=: 3 : 0
sel=. 0 ". scheme_select
if. (<scheme) e. 'JStandard';'JReverse' do.
  info 'You cannot delete ',scheme return.
end.
if. 0 = 2 query 'OK to delete ',scheme,'?' do.
  COLORSCHEMES=: (<<<sel) { COLORSCHEMES
  cfcolorsetscheme sel <. _2 + #COLORSCHEMES 
  cfcolorsetschemes''
  cswrite''
end.
)
cfcolor_italic_button=: 3 : 0
ita=. 0 ". italic
sel=. 0 ". item_select
COLORDATA=: (<ita) (<sel;2)} COLORDATA
cfcoloranon ''
cfcoloritem sel
cfcolorapply''
)
cfcolor_underline_button=: 3 : 0
und=. 0 ". underline
sel=. 0 ". item_select
COLORDATA=: (<und) (<sel;3)} COLORDATA
cfcoloranon ''
cfcoloritem sel
cfcolorapply''
)
cfcolor_item_select=: 3 : 0
cfcoloritem 0 ". item_select
)
cfcolor_sample_button=: 3 : 0
txt=. fread SAMPLEFILE
sel=. '''this is selected text'''
pos=. (1 i.~ sel E. txt) + 0, #sel
open SAMPLEFILE
if. (#txt) > {. pos do.
  smsetselect_jijs_ pos,0
end.
cfcolor_setfocus''
)
cfcolor_setfocus=: 3 : 0
wd 'psel cfmain;pactive;setfocus item'
)
cfcolor_scheme_select=: 3 : 0
cfcolorsetscheme 0 ". scheme_select
)
cfmain_tctrlshift_fkey=: 3 : 0
wdview ": COLORDATA
)
cfcolormove=: 3 : 0
sel=. 0 ". item_select
if. #sel do.
  'ndx new'=. y. moveindex sel;<COLORDATA
  if. ndx ~: sel do.
    cfcoloranon''
    ndx cfcolorreset new
  end.
end.
cfcolor_setfocus''
)

cfcolor_saveas_button=: cssave_run
cfcolor_add_button=: cfadd_run bind 0
cfcolor_edit_button=: cfedit_run bind 1
cfcolor_moveup_button=: cfcolormove bind 0
cfcolor_movedn_button=: cfcolormove bind 1
getcolordata=: 3 : 0
if. 0 e. $y. do. i.0 6 return. end.
dat=. getcolors y.
nums=. >{."1 dat
ind=. FIXCOLORS i. nums
b=. ind < #FIXCOLORS
keys=. 4 {"1 dat
keys=. ((b#ind) { FIXCOLORNAMES) (I. b)} keys
keys=. toblank each keys
dat=. keys 4}"0 1 dat
)
getuserkey=: 3 : 0
(({."1 USRKEYS) i. y.) { {:"1 USRKEYS
)
setcolordata=: 3 : 0
if. 0 e. #COLORDATA do. '' return. end.
emp=. (#COLORDATA)#a:
num=. ([: ; 4&{.) "1 COLORDATA
msk=. ({."1 num) e. USRCOLORS
mtx=. msk # 4{"1 COLORDATA
txt=. (tounder each mtx) (I. msk)} emp
res=. (<"1 ": num) ,each ' ' ,each txt
if. 0 e. j=. mtx e. KEYCOLORNAMES do.
  usr=. msk expand -. j
  userkeys=. usr # 4{"1 COLORDATA
  uservals=. getuserkey userkeys
  val=. uservals (I. usr)} emp
  res=. res ,each ' ' ,each val
end.

res=. LF ,~ tolist res
)
cfcolorapply=: 3 : 'setcolors COLORDATA'
cfcoloranon=: 3 : 0
SMCOLORID=: ''
wd 'setselect scheme -1'
)
cfcolorgraph=: 3 : 0
glsel 'gcolor'
glrgb y.
glbrush''
glrect 0 0 1000 1000
glshow''
)
cfcoloritem=: 3 : 0
if. 0 e. $COLORDATA do. return. end.
nums=. > {."1 COLORDATA
'num clr ita und key j'=. y. { COLORDATA
ndx=. I. nums e. USRCOLORS
cfcolorgraph clr
wd 'setenable add ',": 0 e. USRCOLORS e. nums
wd 'setenable delete ',": -. num e. 0 1
wd 'setenable edit ',": (<key) e. USRCOLORNAMES
wd 'setenable italic ',": num > 3
wd 'setenable underline ',": num > 3
wd 'set italic ',": ita
wd 'set underline ',": und
if. #ndx do.
  wd 'setenable moveup ',": y. > {.ndx
  wd 'setenable movedn ',": (y. >: {.ndx) *. y. < {:ndx
else.
  wd 'setenable moveup 0;setenable movedn 0'
end.
wd 'setselect item ',":y.
wd 'setshow item 0;setshow item 1'
)
cfcolorreset=: 0&$: : (4 : 0)
if. #y. do. COLORDATA=: y. end.
cfcolorapply''
names=. 4 {"1 COLORDATA
wd 'set item *',tolist names
cfcoloritem x.
)
cfcolorsetscheme=: 3 : 0
y=. {. y.,0
ifoldnone=. SMCOLORID -: 'None'
'SMCOLORID SMCOLOR'=: y { COLORSCHEMES
ifnewnone=. SMCOLORID -: 'None'
if. ifnewnone do. SMCOLOR=: '' end.
cfdisable ifnewnone - ifoldnone
SMCOLORIDORG=: SMCOLORID
cfcolorreset COLORDATA=: getcolordata SMCOLOR
ckincx''
cfcolor_setfocus''
)
cfcolorsetschemes=: 3 : 0
css=. {."1 COLORSCHEMES
wd 'set scheme ',toblank toeav css
wd 'setselect scheme ',": css inx1 < SMCOLORID
)
cfdisable=: 3 : 0
if. y. ~: 0 do.
  j=. 'saveas deletescheme item color add edit delete'
  nms=. > ;: j,' italic underline moveup movedn'
  wd 'setenable ',"1 nms (,"1) 2 ": y.<0
end.
)

CFADD=: 0 : 0
pc cfadd owner;pn "Add Item";
xywh 6 8 140 107;cc g0 groupbox;cn "Item";
xywh 11 20 125 74;cc itemlist listbox ws_vscroll;
xywh 13 97 44 12;cc new button;cn "New Item";
xywh 59 97 44 12;cc delete button;cn "Delete";
xywh 6 123 205 79;cc g1 groupbox;cn "Definition";
xywh 11 135 90 12;cc itemname edit ws_border es_autohscroll;
xywh 11 152 192 40;cc itemdef editm ws_border es_autovscroll;
xywh 159 135 44 12;cc add button;cn "Accept";
xywh 165 14 44 12;cc ok button bs_defpushbutton;cn "OK";
xywh 165 30 44 12;cc cancel button;cn "Cancel";
pas 4 4;pcenter;
rem form end;
)
cfadd_run=: 3 : 0
nums=. {."1 COLORDATA
FIXUNUSED=: (-. FIXCOLORS e. nums) # FIXCOLORNAMES
wd CFADD
wd 'setfont itemdef ',FIXFONT
cfaddshowkeys''
cfaddshow 0 pick COLADDKEYS,a:
wd 'pshow;'
)
cfadd_ok_button=: 3 : 0
if. #itemlist do.
  wd 'pclose'
  cfaddkey itemlist
else.
  info 'No color item selected'
end.
)
cfadd_add_button=: 3 : 0
name=. deb itemname
def=. vectoblank itemdef

if. 0 e. #name do.
  info 'Item name must be given' return.
end.
if. 0 e. #def do.
  info 'Item definition must be given' return.
end.
if. _2 = 4!:0 <tounder name do.
  j=. 'The item name must be a J name,',LF
  info j,'or list of blank-delimited J names' return.
end.

USRKEYS=: sort nubmatrix0 (name;def), USRKEYS
USRCOLORNAMES=: {."1 USRKEYS
cfaddshowkeys''
cfaddshow name
ckwrite''
)
cfadd_delete_button=: 3 : 0
name=. deb itemname
if. 2 query 'OK to delete: ',LF,LF,name do. return. end.
ndx=. ({."1 USRKEYS) i. <name
ind=. COLADDKEYS i. <name
USRKEYS=: (<<<ndx) { USRKEYS
USRCOLORNAMES=: {."1 USRKEYS
cfaddshowkeys''
if. 0 e. #COLADDKEYS do.
  cfaddshow ''
else.
  cfaddshow (ind <. <: #COLADDKEYS) pick COLADDKEYS
end.
ckwrite''
)
cfadd_itemname_button=: 3 : 0
)
cfadd_itemlist_select=: 3 : 0
cfaddshow itemlist
)
cfadd_new_button=: 3 : 0
wd 'setreadonly itemname 0;setreadonly itemdef 0'
wd 'set itemname;set itemdef'
wd 'setenable add 1'
wd 'setselect itemlist -1'
)
cfadd_enter=: cfadd_ok_button
cfadd_cancel_button=: cfadd_cancel=: cfadd_close=: wd bind 'pclose'
cfadd_itemlist_button=: cfadd_ok_button
cfaddshow=: 3 : 0
wd 'set itemname *',y.
if. 0 = #y. do.
  wd 'setenable delete 0'
  wd 'setenable new 1;setenable add 1'
  wd 'setreadonly itemname 0;setreadonly itemdef 0'
  wd 'setfocus itemname'
else.
  if. (<y.) e. USRCOLORNAMES do.
    wd 'set itemdef *', > getuserkey <y.
    wd 'setreadonly itemname 0;setreadonly itemdef 0'
    wd 'setenable add 1;setenable delete 1'
  else.
    if. (<y.) e. FIXCOLORNAMES do.
      wd 'set itemdef *{',y.,'}'
    else.
      wd 'set itemdef *',". tounder y.
    end.
    wd 'setenable add 0;setenable delete 0'
    wd 'setreadonly itemname 1;setreadonly itemdef 1'
  end.
  wd 'setselect itemlist ',":COLADDKEYS i. <y.
  wd 'setfocus itemlist'
end.
)
cfaddshowkeys=: 3 : 0
names=. 3 {"1 COLORDATA
COLADDKEYS=: (FIXCOLORNAMES,KEYCOLORNAMES,USRCOLORNAMES) -. names
wd 'set itemlist ', toeav COLADDKEYS
)
cfaddkey=: 3 : 0
cfcoloranon''  
txt=. deb y.
if. (<txt) e. FIXUNUSED do.
  
  num=. FIXCOLORS {~ FIXCOLORNAMES i. <txt
  
  nums=. > {."1 COLORDATA
  ndx=. (nums > num) i. 1
  
  if. num=2 do. clr=. 1 pick (nums i. 1) { COLORDATA
  elseif. num=3 do. clr=. 1 pick (nums i. 0) { COLORDATA
  elseif. 1 do. clr=. 0 0 0
  end.
  
  new=. num;clr;0;0;txt;''
  
  COLORDATA=: (ndx {. COLORDATA), new , ndx }. COLORDATA
  ndx cfcolorreset ''
  
elseif. (<txt) e. KEYCOLORNAMES do.
  
  val=. ". tounder txt
  num=. {. USRCOLORS -. > {."1 COLORDATA
  COLORDATA=: COLORDATA , num;0 0 0;0;0;txt;val
  (<: #COLORDATA) cfcolorreset ''
  
elseif. 1 do.
  
  val=. vectoblank itemdef
  if. 0 e. $val do.
    info 'No keyword definition' return.
  end.
  num=. {. USRCOLORS -. > {."1 COLORDATA
  COLORDATA=: COLORDATA , num;0 0 0;0;0;txt;val
  (<: #COLORDATA) cfcolorreset ''
  USRKEYS=: sort nubmatrix0 (txt;val) , USRKEYS
  ckwrite''
  
end.
)

BOXES=: ];._2 (0 : 0)
ÚÂ¿ÃÅ´ÀÁÙ³Ä
+++++++++|-
)
toblank=: ' '&(I. @(e.&'_')@]})
tounder=: '_'&(I. @(e.&' ')@]})
getsyskey=: 3 : '". @ tounder each y.'
SYSCOLORS=: 0 1 2 3 4 5 6 7  
CLSCOLORS=: 20 21 22 23 24 25 26 27 28 29  
USRCOLORS=: 40+i.20

SYSCOLORNAMES=: <;._2 (0 : 0)
background
text
selection background
selection text
margin
mark
lab text background
lab text foreground
)

CLSCOLORNAMES=: <;._2 (0 : 0)
primitive
name
number
string
comment
open quote
unmatched parenthesis
global assignment
local assignment
close definition
)

KEYCOLORNAMES=: <;._2 (0 : 0)
adverbs
arguments
box drawing
conjunctions
control words
nouns
verbs
)

UKEYCOLORNAMES=: tounder each KEYCOLORNAMES

USRCOLORNAMES=: ''

FIXCOLORS=: SYSCOLORS,CLSCOLORS
FIXCOLORNAMES=: SYSCOLORNAMES,CLSCOLORNAMES

JStandard=: 0 : 0
 0 255 255 255 0 0
 1   0   0   0 0 0
 6 228 228 228 0 0
23   0   0 255 0 0
24   0 128   0 0 0
25 255   0 255 0 0
26 255   0 255 0 0
40 255   0   0 0 0 control_words
)
on=: @:
deb=: #~ (+. 1: |. (> </\))@(' '&~:)
getcolors=: 3 : 0
if. 0 e. $ y. do. i.0 6 return. end.
getcolor4 ;._2 y.
)
getcolor4=: 3 : 0
dat=. deb y.
ndx=. (dat e. '0123456789 ') i. 0
num=. 6 {. ". ndx {. dat
num=. ({.num);(1 2 3{num);(4{num);5{num
dat=. ndx }. dat
ndx=. dat i. ' '
key=. tounder ndx {. dat
if. (<key) e. UKEYCOLORNAMES do.
  val=. ". key
else.
  val=. (ndx+1) }. dat
end.
num,key;val
)
setcolors=: 3 : 0
wd ,';smkeywords ' ,"1 ": ,. USRCOLORS
wd 'smcolor'

if. 0 e. $y. do. return. end.

nums=. > 0 {"1 y.
vals=. > 1 {"1 y.
ital=. > (> 2 {"1 y.) { '';' italic '
unds=. > (> 3 {"1 y.) { '';' underline '
keys=. 4 {"1 y.
sets=. 5 {"1 y.
if. 0 e. 2 3 e. nums do.
  ndx=. nums i. 0 1
  nums=. nums, 3 2
  msk=. ~: nums
  nums=. msk # nums
  vals=. msk # vals, ndx{vals
  ital=. msk # ital, ndx{ital
  unds=. msk # unds, ndx{unds
  keys=. msk # keys, ndx{keys
  sets=. msk # sets, ndx{sets
end.

b=. keys e. KEYCOLORNAMES
if. 1 e. b do.
  ndx=. I. b
  keys=. (getsyskey ndx{keys) ndx} keys
end.

b=. nums e. USRCOLORS
if. 1 e. b do.
  j=. <"1 ';smkeywords ' ,"1 (": ,. b#nums) ,"1 ' ',EAV
  wd ; j ,each (b#sets) ,each EAV
end.

wd ,';smcolor ' ,"1 (": nums ,. vals) ,. ital ,. unds

)

CFEDIT=: 0 : 0
pc cfedit owner;pn "Edit Item";
xywh 6 8 204 74;cc g1 groupbox;cn "Definition";
xywh 11 20 100 12;cc itemname edit ws_border es_autohscroll;
xywh 11 35 194 40;cc itemdef editm ws_border es_autovscroll;
xywh 118 90 44 12;cc ok button;cn "OK";
xywh 164 90 44 12;cc cancel button;cn "Cancel";
pas 4 4;pcenter;
rem form end;
)
cfedit_run=: 3 : 0
sel=. 0 ". item_select
'name def'=. 4 5 { sel { COLORDATA
wd CFEDIT
wd 'setfont itemdef ',FIXFONT
wd 'set itemname *',name
wd 'set itemdef *', def
wd 'setfocus itemdef'
wd 'pshow'
)
cfedit_ok_button=: 3 : 0
sel=. 0 ". item_select
name=. deb itemname
def=. vectoblank itemdef
if. 0 e. #name do.
  info 'Item name must be given' return.
end.
if. 0 e. #def do.
  info 'Item definition must be given' return.
end.
if. _2 = 4!:0 <tounder name do.
  j=. 'The item name must be a J name,',LF
  info j,'or list of blank-delimited J names' return.
end.
USRKEYS=: sort nubmatrix0 (name;def), USRKEYS
USRCOLORNAMES=: {."1 USRKEYS
COLORDATA=: (name;def) (<sel;4 5)} COLORDATA
wd 'pclose'
sel cfcolorreset ''
)
cfedit_itemname_button=: cfedit_enter=: cfedit_ok_button
cfedit_cancel_button=: cfedit_cancel=: cfedit_close=: wd bind 'pclose'

CSFILE=: jpath '~config\colors.ijs'
CKFILE=: jpath '~config\colorkey.ijs'
DEFSCHEMES=: 'BlueJay';'Desert';'Emacs';'JReverse';'JSamples';'JStandard'
j=. <;.2 (0 : 0)
colors.ijs

This file contains color schemes for the session manager.

The file is updated by Configure, and may also be
changed manually. Each entry must consist of a
definition of a color scheme.
)

CSFILEHEADER=: LF ,~ ; 'NB. '&, each j
j=. <;.2 (0 : 0)
colorkey.ijs

This file contains color keys for the session manager.

The file is updated by Configure, and may also be
changed manually. Each entry must consist of a
definition of a color key.

Replace blank in color key names with an underscore.
)

CKFILEHEADER=: LF ,~ ; 'NB. '&, each j
0 : 0

00-19  system colors
20-39  class colors
40-59  keyword colors

 0      bkgnd
 1      text
 2      selbkgnd
 3      seltext
 4      margin
 5      mark (character digits, not bitmaps)
 6      lab text background
 7      lab text foreground
 8-19   reserved
20      primitive
21      name
22      number
23      string
24      comment
25      open quote
26      first unmatched )(
27      name =:
28      name =.
29      naked ) - explicit definition and lab section close
30-39   reserved
40-59   keywords

)
BlueJay=: 0 : 0
 0   0   0 128 0 0
 1 255 255 255 0 0
 6 228 228 228 0 0
 7   0   0 128 0 0
23 255 255  64 0 0
24   0 255 128 0 0
25 255   0 255 0 0
26 255   0 255 0 0
40 255 192 128 0 0 control_words
)

Desert=: 0 : 0
 0 255 239 213 0 0
 1   0   0 255 0 0
 6 228 228 228 0 0
23   0  64 128 0 0
24 128  64   0 0 0
25 255   0 255 0 0
26 255   0 255 0 0
40 255   0   0 0 0 control_words
41 128  64   0 0 0 box_drawing
)
Emacs=: 0 : 0
 0  47  79  79 0 0
 1 245 222 179 0 0
 4 224 224 224 0 0
23 135 206 235 0 0
24 192 192 192 0 0
25 255   0 255 0 0
26 255   0 255 0 0
40 255   0   0 0 0 control_words
)

JReverse=: 0 : 0
 0   0   0   0 0 0
 1 255 255 255 0 0
 2 128 255 255 0 0
 3   0   0   0 0 0
 6 228 228 228 0 0
 7   0   0   0 0 0
21   0 255 255 0 0
23 255 255  64 0 0
24 192 192 192 0 0
25 255 128 255 0 0
26 255 128 255 0 0
40 255   0   0 0 0 control_words
)

JSamples=: 0 : 0
 0 192 192 192 0 0
 1 255 255 255 0 0
 2 255   0   0 0 0
 3 255 255 255 0 0
 4 128 255 128 0 0
 5   0   0   0 0 0
 6 228 228 228 0 0
 7   0   0   0 0 0
20   0   0 255 0 0
21   0   0 255 0 0
22  64   0  64 0 0
23   0 255 255 0 1
24   0 255   0 0 0
25 255   0 255 0 0
26 255   0   0 0 0
27 255 255 128 0 0
28 255 255 128 0 0
29 255   0   0 0 0
40 255   0   0 0 0 control_words
41 128 128 192 0 0 adverbs
42 128 128 192 0 0 arguments
43 128 128 192 0 0 bookmarks
47 255 255   0 0 0 boxdrawing
44 128 128 192 0 0 conjunctions
45 128 128 192 0 0 nouns
46 128 128 192 0 0 verbs
)
CSSAVE=: 0 : 0
pc cssave owner;pn "Save Scheme";
xywh 136 5 34 12;cc ok button;cn "OK";
xywh 136 20 34 12;cc cancel button;cn "Cancel";
xywh 5 7 122 8;cc label static;cn "Save this color scheme as:";
xywh 4 16 122 10;cc name edit ws_border es_autohscroll;
pas 4 4;pcenter;
rem form end;
)
cssave_run=: 3 : 0
wd CSSAVE
wd 'set name *',toblank SMCOLORIDORG
wd 'setfocus name'
wd 'setselect name ',": 0,#SMCOLORIDORG
wd 'pshow;'
)
cssave_cancel_button=: cssave_cancel=: cssave_close=: wd bind 'pclose'
cssave_ok_button=: 3 : 0
if. 0 = #name do.
  info 'First enter a color scheme name' return.
end.
if. name -: 'None' do.
  info 'You may not save color scheme: None' return.
end.
name=. tounder name
if. _2 = 4!:0 <name do.
  j=. 'The color scheme name must be a J name,',LF
  info j,'or list of blank-delimited J names' return.
end.
SMCOLORID=: name
SMCOLOR=: setcolordata COLORDATA
nms=. {."1 COLORSCHEMES
val=. {:"1 COLORSCHEMES
ndx=. nms i. <SMCOLORID
if. ndx = #nms do.
  nms=. nms, <SMCOLORID
  val=. val, <SMCOLOR
  COLORSCHEMES=: sort nms ,. val
else.
  val=. (<SMCOLOR) ndx} val
  COLORSCHEMES=: nms ,. val
end.
cswrite''
wd 'pclose'
SMCOLORIDORG=: SMCOLORID
cfcolorsetschemes''

)

cssave_enter=: cssave_name_button=: cssave_ok_button
ckread=: 3 : 0
if. 0=fexist CKFILE do.
  USRKEYS=: i.0 2
else.
  script_jcfg0_ <CKFILE
  p_jcfg0_=: [: (, ,&< ".) &> (4!:1)
  dat=. p_jcfg0_ 0
  dat=. dat #~ (<'y.') ~: {."1 dat
  if. 0 e. $dat do.
    USRKEYS=: i.0 2
  else.
    nms=. toblank each {."1 dat
    USRKEYS=: nms ,. {:"1 dat
  end.
  18!:55 <'jcfg0'
end.
ckincx''
)
ckincx=: 3 : 0
msk=. -. (4 {"1 COLORDATA) e. FIXCOLORNAMES,KEYCOLORNAMES
USRKEYS=: (4 5 {"1 msk # COLORDATA), USRKEYS
USRKEYS=: sort nubmatrix0 USRKEYS
USRCOLORNAMES=: {."1 USRKEYS
)
ckwrite=: 3 : 0
if. #USRKEYS do.
  nms=. tounder each {."1 USRKEYS
  val=. {:"1 USRKEYS
  j=. nms ,each (<'=: ') ,each quote each val
  j=. j ,each (<LF,LF)
  dat=. _2 }. ; j
else.
  dat=: ''
end.

(CKFILEHEADER, dat) fwrites CKFILE
)
csread=: 3 : 0

if. 0 = fexist CSFILE do.
  dat=. DEFSCHEMES ,. ". each DEFSCHEMES
else.
  script_jcfg0_ <CSFILE
  p_jcfg0_=: [: (, ,&< ".) &> (4!:1)
  dat=. p_jcfg0_ 0
  dat=. dat #~ (<'y.') ~: {."1 dat
  18!:55 <'jcfg0'
  if. 0 e. $dat do.
    dat=. DEFSCHEMES ,. ". each DEFSCHEMES
  end.
end.

dat=. ~. dat , 'None';''
COLORSCHEMES=: sort dat

)
cswrite=: 3 : 0
css=. COLORSCHEMES -. 'None';''
nms=. tounder each {."1 css
val=. {:"1 css
j=. nms ,each (<'=: 0 : 0',LF)
j=. j ,each val ,each (<')',LF,LF)
dat=. _2 }. ; j
(CSFILEHEADER, dat) fwrites CSFILE
)

CFEXTERN=: 0 : 0
pc cfextern;
xywh 8 8 246 21;cc xn static;
xywh 9 34 92 11;cc s0 static;cn "Browser:";
xywh 123 32 50 12;cc bdef button;cn "Default";
xywh 176 32 50 12;cc bbrowser button;cn "Browse...";
xywh 8 46 220 12;cc browser edit ws_border es_autohscroll;
xywh 9 66 92 11;cc s2 static;cn "EPS Reader:";
xywh 123 64 50 12;cc bepsdef button;cn "Default";
xywh 176 64 50 12;cc bepsbrowse button;cn "Browse...";
xywh 8 78 220 12;cc epsreader edit ws_border es_autohscroll;
xywh 9 98 92 11;cc s1 static;cn "PDF Reader:";
xywh 123 96 50 12;cc bpdfdef button;cn "Default";
xywh 176 96 50 12;cc bpdfbrowse button;cn "Browse...";
xywh 8 110 220 12;cc pdfreader edit ws_border es_autohscroll;
xywh 9 130 111 11;cc s3 static;cn "File Comparison:";
xywh 176 128 50 12;cc bxdiff button;cn "Browse...";
xywh 8 142 220 12;cc xdiff edit ws_border es_autohscroll;
pas 6 6;pcenter;
rem form end;
)
cfextern_run=: 3 : 0
if. y.=0 do.
  wd CFEXTERN
end.
wd 'set xn *Enter command strings for the external programs.'
wd 'set browser *',BROWSER
wd 'set epsreader *',EPSREADER
wd 'set pdfreader *',PDFREADER
wd 'set xdiff *',XDIFF
)

cfextern_act=: ]
cfextern_bdef_button=: 3 : 0
wd 'set browser *',dfltbrowser ''
)
cfextern_bbrowser_button=: 3 : 0
f=. cfextern_browsefile browser
if. #f do.
  wd 'set browser *',browser=: f
end.
)
cfextern_bepsdef_button=: 3 : 0
wd 'set epsreader *',dfltepsreader ''
)
cfextern_bepsbrowse_button=: 3 : 0
f=. cfextern_browsefile epsreader
if. #f do.
  wd 'set epsreader *',epsreader=: f
end.
)
cfextern_bpdfdef_button=: 3 : 0
wd 'set pdfreader *',dfltpdfreader ''
)
cfextern_bpdfbrowse_button=: 3 : 0
f=. cfextern_browsefile pdfreader
if. #f do.
  wd 'set pdfreader *',pdfreader=: f
end.
)
cfextern_bxdiff_button=: 3 : 0
f=. cfextern_browsefile xdiff
if. #f do.
  wd 'set xdiff *',xdiff=: f
end.
)
cfextern_browsefile=: 3 : 0
if. #y. do. 'p f'=. pathname y.
else.
  p=. jpath '~home'
  f=. ''
end.
j=. '"Applications (*.exe)|*.exe|All Files (*.*)|*.*"'
j=. j,' ofn_filemustexist ofn_nochangedir'
wd 'mbopen "Open File" "',p,'" "',f,'" ',j
)

CFFOLDER=: 0 : 0
pc cffolder closeok owner;pn "User Folders";
xywh 3 6 248 126;cc g0 groupbox rightmove bottommove;cn "";
xywh 9 15 46 11;cc s0 static;cn "Name";
xywh 67 15 62 11;cc s1 static;cn "Folder Path";
xywh 9 27 236 84;cc ftypes listbox ws_hscroll ws_vscroll rightmove bottommove;
xywh 9 114 44 12;cc up button topmove bottommove;cn "Move &Up";
xywh 55 114 44 12;cc down button topmove bottommove;cn "Move Do&wn";
xywh 202 114 44 12;cc delete button topmove bottommove;cn "&Delete";
xywh 3 140 248 59;cc g0 groupbox topmove rightmove bottommove;cn "";
xywh 8 152 33 9;cc label static topmove bottommove;cn "Name:";
xywh 42 151 203 12;cc desc edit ws_border es_autohscroll topmove rightmove bottommove;
xywh 8 167 33 9;cc label static topmove bottommove;cn "Folder:";
xywh 42 166 203 12;cc efolder edit ws_border es_autohscroll topmove rightmove bottommove;
xywh 8 182 44 12;cc addtop button topmove bottommove;cn "Add at &top";
xywh 54 182 44 12;cc addend button topmove bottommove;cn "Add at &end";
xywh 202 183 44 12;cc replace button topmove bottommove;cn "&Replace";

pas 2 2;pcenter;
rem form end;
)
cffolder_run=: 3 : 0
if. y.=0 do.
  wd CFFOLDER
  
  wd 'settabstops ftypes 60'
  XNDX=: _1
end.
cffoldershow''
)

cffolder_act=: ]
cffoldershow=: 3 : 0
if. #USERFOLDERS do.
  'a b'=. |: USERFOLDERS
  j=. }. , LF ,. '"' ,. a ,. TAB ,"1 b ,. '"'
  wd 'set ftypes ', j
  cffoldershowdetails''
end.
)
cffoldershowdetails=: 3 : 0
if. 0 <: XNDX do.
  'j k'=. XNDX { USERFOLDERS
  wd 'set desc *',j
  wd 'set efolder *',delfret k
  wd 'setselect ftypes ',":XNDX
end.
)
cffolder_up_button=: 3 : 0
if. #ndx=. ". ftypes_select do.
  ind=. ndx, ndx1=. 0 >. ndx-1
  USERFOLDERS=: (|.ind{USERFOLDERS) ind} USERFOLDERS
  XNDX=: ndx1
  cffoldershow''
end.
)
cffolder_down_button=: 3 : 0
if. #ndx=. ". ftypes_select do.
  ind=. ndx, ndx1=. (<:#USERFOLDERS) <. ndx+1
  USERFOLDERS=: (|.ind{USERFOLDERS) ind} USERFOLDERS
  XNDX=: ndx1
  cffoldershow''
end.
)
cffolder_delete_button=: 3 : 0
if. #ndx=. ". ftypes_select do.
  if. 1=#USERFOLDERS do.
    info 'You cannot delete the only folder' return.
  end.
  msg=. 'OK to delete: ',>{.ndx{USERFOLDERS
  if. 0=2 query msg do.
    USERFOLDERS=: USERFOLDERS #~ -. (i.#USERFOLDERS) e. ndx
    XNDX=: (<:#USERFOLDERS) <. ndx
    cffoldershow''
  end.
end.
)
cffolder_ftypes_select=: 3 : 0
XNDX=: ". ftypes_select
cffoldershowdetails''
)
cffolder_addtop_button=: 3 : 0
if. cffolder_addcheck 0 do.
  USERFOLDERS=: ~. (desc;efolder),USERFOLDERS
  XNDX=: 0
  cffoldershow''
end.
)
cffolder_addend_button=: 3 : 0
if. cffolder_addcheck 0 do.
  USERFOLDERS=: ~. USERFOLDERS, desc;efolder
  XNDX=: ({."1 USERFOLDERS) i. <desc
  cffoldershow''
end.
)
cffolder_replace_button=: 3 : 0
if. cffolder_addcheck 1 do.
  if. #ndx=. ". ftypes_select do.
    USERFOLDERS=: (desc;efolder) ndx} USERFOLDERS
    XNDX=: ndx
    cffoldershow''
  end.
end.
)
cffolder_addcheck=: 3 : 0

desc=: deb desc
efolder=: deb efolder

if. (desc;efolder) e. USERFOLDERS do. 0 return. end.
r=. 0

if. 0=#desc do.
  info 'Enter the name'
elseif. 20<#desc do.
  info 'Name may not exceed 20 characters'
elseif. 0=#efolder do.
  info 'Enter the folder paths'
elseif. y. < (<desc) e. {."1 USERFOLDERS do.
  info 'Name already in use'
elseif. y. < (<efolder) e. {:"1 USERFOLDERS do.
  info 'Folder already in use'
elseif. 1 do. r=. 1
end.

r
)

FORMNOTES=: textline 0 : 0
Control sizes are derived from these values.
Label height is normally less than edit height
and they are centered horizontally.
)
CFFORMS=: 0 : 0
pc cfforms;pn "Configure Forms";
xywh 7 10 28 11;cc sffont static;cn "Font:";
xywh 37 9 150 12;cc fontdef edit ws_border es_autohscroll;
xywh 37 24 44 12;cc fansi radiobutton;cn "Ansi";
xywh 88 24 44 12;cc foem radiobutton group;cn "OEM";
xywh 139 24 54 12;cc fdefault radiobutton group;cn "Default";
xywh 208 10 44 12;cc fbrowse button;cn "&Select...";
xywh 7 42 60 11;cc f0 static;cn "Button width:";
xywh 68 41 22 12;cc bwidth edit ws_border es_autohscroll;
xywh 7 57 60 11;cc f1 static;cn "Button height:";
xywh 68 56 22 12;cc bheight edit ws_border es_autohscroll;
xywh 7 72 60 11;cc f2 static;cn "Edit width:";
xywh 68 71 22 12;cc ewidth edit ws_border es_autohscroll;
xywh 7 87 60 11;cc f3 static;cn "Edit height:";
xywh 68 86 22 12;cc eheight edit ws_border es_autohscroll;
xywh 7 102 60 11;cc f4 static;cn "Label height:";
xywh 68 101 22 12;cc lheight edit ws_border es_autohscroll;
xywh 7 118 52 10;cc f5 static;cn "Notes:";
xywh 15 129 241 36;cc f6 static;
pas 4 2;pcenter;
rem form end;
)
cfforms_run=: 3 : 0
if. y.=0 do.
  wd CFFORMS
  f=. ". @ wd :: _1:
  if. _1 ~: j=. f 'qformsize' do.
    FORMSIZES=: j
  end.
end.
if. IFJAVA do.
  font=. PROFONTJ
else.
  font=. PROFONTW
end.
wd 'set fontdef *',font
setformsstyle getfontstyle font
wd 'set f6 *',FORMNOTES
wd 'set bwidth ',":0{FORMSIZES
wd 'set bheight ',":1{FORMSIZES
wd 'set ewidth ',":2{FORMSIZES
wd 'set eheight ',":3{FORMSIZES
wd 'set lheight ',":4{FORMSIZES
)
cfforms_act=: ]
cfforms_cancel_button=: 3 : 0
wd 'pclose;'
)
cfforms_fbrowse_button=: 3 : 0
if. #j=. mbfont fontdef do.
  fontdef=: j
  formsstyle FSTYLE
end.
)
cfforms_fansi_button=: formsstyle bind 'ansi'
cfforms_fdefault_button=: formsstyle bind 'default'
cfforms_foem_button=: formsstyle bind 'oem'
formsstyle=: 3 : 0
setformsstyle y.
wd 'set fontdef *',FSTYLE setfontstyle fontdef
)
setformsstyle=: 3 : 0
FSTYLE=: boxopen y.
wd 'set fansi ',":FSTYLE = <'ansi'
wd 'set fdefault ',":FSTYLE = <'default'
wd 'set foem ',":FSTYLE = <'oem'
)

18!:4 <'jcfg'
getuserfolders=: 3 : 0
ids=. {."1 USERFOLDERS_j_
pth=. {:"1 USERFOLDERS_j_
usr=. ids, each ' ', each pth
'USERFOLDERS=: 0 : 0';usr,<')'
)
configsaveuser=: 3 : 0
fl=. <jpath '~config\config.ijs'
dat=. 1!:1 :: 0: fl
if. dat -: 0 do. return. end.
ndx=. ('USERFOLDERS' E. dat) i. 1
hdr=. ndx {. dat
dat=. ndx }. dat
ndx=. dat i. ')'
dat=. (ndx + 1) }. dat
usr=. getuserfolders''
usr=. ; usr ,each LF
dat=. hdr, usr, dat
dat 1!:2 fl
)

LAFNOTES=: textline 0 : 0
Choose a look & feel from the list below.

Some of the changes may not apply until you have exited and re-entered J.
)
CFLAF=: 0 : 0
pc cflaf;
xywh 9 8 180 36;cc ln static;
xywh 10 57 60 12;cc l0 static;cn "Look and Feel:";
xywh 72 56 90 12;cc laf combolist ws_vscroll;
pas 6 6;pcenter;
rem form end;
)
cflaf_run=: 3 : 0
if. y.=0 do.
  wd CFLAF
end.
wd 'set ln *',LAFNOTES
ndx=. JAVALAFNMS index <JAVALAF
wd 'set laf ',toeav JAVALAFNMS
wd 'setselect laf ',":ndx
)
cflaf_act=: ]
cflaf_laf_select=: 3 : 0
ndx=. 0 ". laf_select
JAVALAF=: ndx pick JAVALAFNMS
)


LICENSENOTES=: textline 0 : 0
Enter your name and J User License.

To save the license, check "Save Config".

For more information, see Help|J User License.
)
CFLIC=: 0 : 0
pc cflic;
xywh 9 8 240 44;cc ln static;cn "ln";
xywh 10 65 58 11;cc l0 static;cn "First Name:";
xywh 69 65 80 12;cc userfname edit ws_border es_autohscroll;
xywh 10 81 58 11;cc l3 static;cn "Last Name:";
xywh 69 81 80 12;cc userlname edit ws_border es_autohscroll;
xywh 10 96 58 11;cc l1 static;cn "User License:";
xywh 69 96 80 12;cc userjul edit ws_border es_autohscroll;
xywh 153 65 44 12;cc apply button;cn "&Check";

pas 6 6;pcenter;
rem form end;
)
cflic_act=: ]
cflic_run=: 3 : 0
if. y.=0 do.
  wd CFLIC
  
end.
wd 'set ln *',LICENSENOTES
cflic_set''
)

cflic_get=: 3 : 0
USERFNAME=: deb userfname
USERLNAME=: deb userlname
USERJUL=: fmtjul userjul
)
cflic_set=: 3 : 0
wd 'set userfname *',USERFNAME
wd 'set userlname *',USERLNAME
wd 'set userjul *',USERJUL
)
cflic_info=: 3 : 0
select. cfv''
case. 0 do.
  info 'Valid User License'
case. 1 do.
  info 'Invalid License. This is for release J',(":1 pick val),'.'
case. 2 do.
  info 'No license entered'
case. 3 do.
  info 'License is invalid. Please check your name and license is exactly that provided.'
end.
)
cflic_apply_button=: 3 : 0
cflic_get''
cflic_set''
cflic_info''
)
fmtjul=: 3 : 0
dat=. (,y.) -. ' -'
if. 11 = #dat do.
  dat 0 1 2 3 5 6 7 9 10 11 12 } 13 # '-'
else.
  ,y.
end.
)

CFOPTS=: 0 : 0
pc cfopts;
xywh 6 8 248 52;cc v0 groupbox;cn "Global Parameters";
xywh 12 24 67 11;cc l2 static;cn "Memory Limit:";
xywh 80 23 115 100;cc cml combolist ws_vscroll cbs_autohscroll;
xywh 202 23 44 12;cc defml button;cn "Default";
xywh 12 41 67 11;cc l0 static;cn "Print Precision:";
xywh 80 40 30 12;cc cpp edit ws_border es_autohscroll;
xywh 202 40 44 12;cc defpp button;cn "Default";
xywh 6 67 248 54;cc v1 groupbox;cn "Session Manager";
xywh 12 81 67 11;cc s2 static;cn "Max Line Length:";
xywh 80 79 30 12;cc maxlinelength edit ws_border es_autohscroll;
xywh 12 93 67 11;cc s3 static;cn "Max Lines Before:";
xywh 80 92 30 12;cc maxlinesbefore edit ws_border es_autohscroll;
xywh 12 105 67 11;cc s4 static;cn "Max Lines After:";
xywh 80 104 30 12;cc maxlinesafter edit ws_border es_autohscroll;
xywh 202 78 44 12;cc defll button;cn "Defaults";
pas 6 6;pcenter;
rem form end;
)
cfopts_run=: 3 : 0
if. y.=0 do.
  wd CFOPTS
  
end.
wd 'set cml *',tolist getml''
wd 'setselect cml ',":MEMLIM i. <. 2 ^. 9!:20''
wd 'set cpp ',":PRINTPREC 
wd 'set maxlinelength ',": 1 { OUTPUT
wd 'set maxlinesbefore ',": 2 { OUTPUT
wd 'set maxlinesafter ',": 3 { OUTPUT
)
cfopts_act=: ]
cfopts_cancel_button=: wd bind 'pclose'
cfmt=: 3 : 0
dat=. ":x:<.y.
len=. #dat
msk=. (-len) {. (|. len $ 1j1 1 1),3$1
msk # !.',' dat
)
getml=: 3 : 0
min=. 17
max=. getmaxml''
MEMLIM=: min + i. 1 + max - min
mlfmt each MEMLIM
)
getmaxml=: 3 : 0
old=. 9!:20''
9!:21 [ _
max=. 9!:20''
9!:21 old
<. 2 ^. max
)
mlfmt=: 3 : 0
'2^',(":y.),' = ',cfmt 2^y.
)
cfopts_cml_button=: 3 : 0
MEMORYLIM=: MEMLIM {~ ". cml_select
if. MEMORYLIM = {:MEMLIM do.
  MEMORYLIM=: _
end.
)

cfopts_cml_select=: cfopts_cml_button
cfopts_defml_button=: 3 : 0
MEMORYLIM=: _
wd 'setselect cml ',": <: #MEMLIM
)
cfopts_defpp_button=: 3 : 0
wd 'set cpp 6'
)
cfopts_maxlinelength_button=: 3 : 0
if. -. isnnint _1 ". maxlinelength do.
  info 'Invalid setting for Max Line Length'
end.
)
cfopts_maxlinesbefore_button=: 3 : 0
if. -. isnnint _1 ". maxlinesbefore do.
  info 'Invalid setting for Max Lines Before'
end.
)
cfopts_maxlinesafter_button=: 3 : 0
if. -. isnnint _1 ". maxlinesafter do.
  info 'Invalid setting for Max Lines After'
end.
)
cfopts_defll_button=: 3 : 0
wd 'set maxlinelength 256'
wd 'set maxlinesbefore 0'
wd 'set maxlinesafter 222'
)

PRINTNOTES=: 'A 7-7.5 point fixed-pitch font is recommended.'

CFPRINT=: 0 : 0
pc cfprint;pn "Configure Print";
xywh 6 8 248 42;cc g0 groupbox;cn "Print Font";
xywh 12 20 183 12;cc pfont edit ws_border es_autohscroll;
xywh 13 35 42 11;cc pansi radiobutton;cn "Ansi";
xywh 70 35 42 11;cc poem radiobutton group;cn "OEM";
xywh 127 35 60 11;cc pdefault radiobutton group;cn "Default";
xywh 202 20 44 12;cc pbrowse button;cn "&Browse...";
xywh 6 58 248 53;cc g1 groupbox;cn "Print 2-Up Font";
xywh 12 82 183 12;cc p2font edit ws_border es_autohscroll;
xywh 13 97 42 11;cc p2ansi radiobutton;cn "Ansi";
xywh 70 97 42 11;cc p2oem radiobutton group;cn "OEM";
xywh 127 97 60 11;cc p2default radiobutton group;cn "Default";
xywh 202 82 44 12;cc p2browse button;cn "&Browse...";
xywh 10 69 231 11;cc p2 static;
xywh 6 119 248 40;cc g2 groupbox;cn "Default Print Type";
xywh 12 131 54 11;cc bprint radiobutton;cn "print";
xywh 12 143 68 11;cc bprint2 radiobutton group;cn "print 2-up";
xywh 72 131 173 11;cc bascii checkbox;cn "Ascii box-drawing characters";
pas 2 2;pcenter;
rem form end;
)
cfprint_run=: 3 : 0
if. y.=0 do.
  wd CFPRINT
  
end.
wd 'set p2 *',PRINTNOTES
wd 'set pfont *',PRINTERFONT
setprintstyle getfontstyle PRINTERFONT
wd 'set p2font *',P2UPFONT
setprint2style getfontstyle P2UPFONT
wd 'set bprint ',":SMPRINT-:'print'
wd 'set bprint2 ',":SMPRINT-:'print2'
wd 'set bascii ',": (<'ascii') e. PRINTOPTX
)
cfprint_act=: ]
cfprint_cancel_button=: 3 : 0
wd 'pclose;'
)
cfprint_pbrowse_button=: 3 : 0
if. #j=. mbfont pfont do.
  pfont=: j
  printstyle PSTYLE
end.
)
cfprint_p2browse_button=: 3 : 0
if. #j=. mbfont p2font do.
  p2font=: j
  print2style P2STYLE
end.
)
cfprint_pansi_button=: printstyle bind 'ansi'
cfprint_pdefault_button=: printstyle bind 'default'
cfprint_poem_button=: printstyle bind 'oem'
printstyle=: 3 : 0
setprintstyle y.
wd 'set pfont *',PSTYLE setfontstyle pfont
)
setprintstyle=: 3 : 0
PSTYLE=: boxopen y.
wd 'set pansi ',":PSTYLE = <'ansi'
wd 'set pdefault ',":PSTYLE = <'default'
wd 'set poem ',":PSTYLE = <'oem'
)
cfprint_p2ansi_button=: print2style bind 'ansi'
cfprint_p2default_button=: print2style bind 'default'
cfprint_p2oem_button=: print2style bind 'oem'

cfprint_bprint_button=: 3 : 'SMPRINT=: ''print'''
cfprint_bprint2_button=: 3 : 'SMPRINT=: ''print2'''

cfprint_bascii_button=: 3 : 0
if. '1'=bascii do.
  PRINTOPTX=: PRINTOPTX, <'ascii'
else.
  PRINTOPTX=: PRINTOPTX -. <'ascii'
end.
)
print2style=: 3 : 0
setprint2style y.
wd 'set p2font *',P2STYLE setfontstyle p2font
)
setprint2style=: 3 : 0
P2STYLE=: boxopen y.
wd 'set p2ansi ',":P2STYLE = <'ansi'
wd 'set p2default ',":P2STYLE = <'default'
wd 'set p2oem ',":P2STYLE = <'oem'
)

CFGITEMS=: <;._2 (0 : 0)
FIXFONTJ
PROFONTJ
FIXFONTW
PROFONTW
PRINTERFONT
P2UPFONT
SMPRINT
PRINTOPT
SMINIT
SMSIZE
SMSTYLE
BOXFORM
BOXPOS
BROWSER
DIRTREEX
DISPLAYFORM
EPSREADER
FORMSIZES
MEMORYLIM
NEWUSER
OUTPUT
PDFREADER
PRINTPREC
JAVALAF
SMCOLORID
STARTUP
STATUSBAR
USERJUL
USERFNAME
USERLNAME
XDIFF
)
CFGLISTS=: <;._2 (0 : 0)
SMCOLOR
FKEYS
SKEYS
)
configclean=: 3 : 0
txt=. y., LF
txt=. txt #~ -. (LF,LF) E. txt
(LF = {. txt) }. txt
)
a=. ''''
quote=: (a&,@(,&a))@ (#~ >:@(=&a))
cfgitem=: 3 : 0
val=. y.~
if. #val do.
  select. 3!:0 val
  case. 2 do.
    val=. quote val
  case. 32 do.
    val=. 5!:5 <'val'
  case. do.
    val=. ": val
  end.
else.
  val=. ''''''
end.
y.,'=: ',val
)
cfglist=: 3 : 0
val=. y.~
if. # val do.
  y.,'=: 0 : 0',LF,val,')'
else.
  y.,'=: '''''
end.
)
configsave=: 3 : 0
FKEYS=: configclean FKEYS
j=. 'NB. configuration';''
j=. j, cfgitem each CFGITEMS
j=. j, cfglist each CFGLISTS
j=. j,getuserfolders ''
j=. toHOST ;j ,each LF
j 1!:2 :: ] <jpath '~config\config.ijs'
)

CFSESS=: 0 : 0
pc cfsess;
xywh 6 11 248 66;cc g0 groupbox;cn "Directory Exclusion";
xywh 11 21 236 36;cc sn static;cn "ln";
xywh 11 58 236 12;cc dirtreex edit ws_border es_autohscroll;
pas 6 6;
rem form end;
)
cfsess_act=: ]
cfsess_run=: 3 : 0
if. y.=0 do.
  wd CFSESS
end.
msg=. 'Directory exclusion list for dirtree,'
msg=. msg,' also used by dirfind, dirss and dirssrplc.'
msg=. msg,' Commas separate entries. Hidden directories'
msg=. msg,' are automatically excluded.'
wd 'set sn *',msg
cfsess_set''
)
cfsess_read=: 3 : 0
DIRTREEX=: cutcommas dirtreex
)
cfsess_set=: 3 : 0
wd 'set dirtreex *', }. ; ',' ,each DIRTREEX
)


CFSKEYS=: 0 : 0
pc cfskeys;pn "Menu Shortcuts";
xywh 8 8 220 20;cc s0 static;
xywh 6 32 145 10;cc t0 static;cn "Menu Shortcut Definitions:";
xywh 6 43 146 134;cc skeyset listbox ws_border ws_vscroll;
xywh 160 43 66 12;cc add button;cn "&Add";
xywh 160 57 66 12;cc modify button;cn "&Modify";
xywh 160 74 66 12;cc original button;cn "Restore Original";
pas 6 6;pcenter;
rem form end;
)
cfskeys_run=: 3 : 0
if. y.=0 do.
  MENU=: readmenu JIJS_jijs_
  wd CFSKEYS
  wd 'setcaption s0 *',SELNOTES
  wd :: ] 'settabstops skeyset 50'
end.
cfshowskeyset''
OLDMENU=: readmenu getjijs''
)
cfskeys_act=: ]
cfskeys_add_button=: 3 : 0
cfedskey_run SKEYNDX=: _1
)
cfskeys_cancel_button=: 3 : 0
wd 'pclose;'
)
cfskeys_modify_button=: 3 : 0
SKEYNDX=: cfskeys_index''
cfedskey_run ''
)
cfskeys_original_button=: 3 : 0
MENU=: OLDMENU
SKEYNDX=: _1
cfshowskeyset''
)
getjijs=: 3 : 0
cocurrent 'jtemp'
0!:0 <jpath '~system\extras\util\jijs.ijs'
res=. JIJS
cocurrent 'jcfg'
coerase <'jtemp'
res
)
cfskeys_index=: 3 : 0
if. 0 = #skeyset do. _1 return. end.
(1 {"1 MENU) i. < (<./ skeyset i. TAB,' ') {. skeyset
)
cfskeys_skeyset_button=: cfskeys_modify_button
cfshowskeyset=: 3 : 0
if. #MENU do.
  msk=. 0 < # &> 1 {"1 MENU
  key=. msk # 1 {"1 MENU
  cap=. msk # 2 {"1 MENU
  txt=. toeav key ,each TAB ,each cap
  wd 'set skeyset ',txt
else.
  wd 'set skeyset'
end.
)
readmenu=: 3 : 0
mnu=. <;._2 y.
mnu=. mnu #~ (<'menu') = 4 {.each mnu
mnu=. (mnu i.&> ';') {. each mnu
r=. i. 0 3
n=. p=. ''
for_m. mnu do.
  m=. > m
  x=. m i. ' '
  select. x {. m
  case. 'menu' do.
    txt=. ' ', deb x }. m
    sep=. (txt = ' ') > ~:/\ txt = '"'
    'id cp sc tt sh'=. 5 {. (sep <;._1 txt) -. each <'&"'
    r=. r, id;sc;n,cp
  case. 'menupop' do.
    p=. p, < (x }. m) -. ' &"'
    n=. ; p ,each '|'
  case. 'menupopz' do.
    p=. }: p
    n=. ; p ,each '|'
  case. 'menusep' do.
  case. do.
    info 'Unrecognized menu command: ',m
  end.
end.
r
)

SELNOTES=: textline 0 : 0
Startup selections take effect when you
next load J. To save the selections,
check "Save Config".
)
SMSTYLES=: toeav cutopen 0 : 0
board.ijs
d:\jxs\board.ijs
board.ijs - d:\jxs\board.ijs
board.ijs* [20 3] d:\jxs\board.ijs
)
CFSTART=: 0 : 0
pc cfstart;pn "Configure View";
xywh 8 8 246 20;cc s0 static;
xywh 6 34 248 29;cc v1 groupbox;cn "Startup Script";
xywh 12 46 137 12;cc startup edit ws_border es_autohscroll;
xywh 182 46 66 12;cc startupopen button;cn "&Open";
xywh 6 70 248 64;cc v0 groupbox;cn "Windows";
xywh 11 82 67 11;cc a0 static;cn "Initial Session Position:";
xywh 11 98 67 11;cc a1 static;cn "New Window Size:";
xywh 11 116 67 11;cc a2 static;cn "Window Title Style:";
xywh 80 84 80 11;cc sminit edit ws_border es_autohscroll;
xywh 80 99 80 11;cc smsize edit ws_border es_autohscroll;
xywh 79 115 120 90;cc smstyle combolist;
xywh 182 83 66 12;cc currentpos button;cn "&Current Position";
xywh 182 98 66 12;cc currentsiz button;cn "Current &Size";
xywh 6 143 248 28;cc v2 groupbox;cn "Welcome to J";
xywh 11 154 236 11;cc newuser checkbox;cn "&Show Welcome to J form";
pas 2 2;pcenter;
rem form end;
)
cfstart_run=: 3 : 0
if. y.=0 do.
  wd CFSTART
end.
CFSTARTH=: wd 'qhwndp'
wd 'setcaption s0 *',SELNOTES
wd 'set sminit *',sminit
wd 'set smsize *',smsize
wd 'set startup *',STARTUP
wd 'set smstyle ',SMSTYLES
wd 'setselect smstyle ',":SMSTYLE
cfstart_act''
)
cfstart_act=: 3 : 0
if. cfv'' do.
  newuser=: 1
  wd 'set newuser 1'
  wd 'setenable newuser 0'
else.
  wd 'set newuser ',":NEWUSER
  wd 'setenable newuser 1'
end.
)
cfstart_currentpos_button=: 3 : 0
p=. ": getactsize_jijs_''
wd 'psel ',CFSTARTH
wd 'set sminit *',p
)
cfstart_currentsiz_button=: 3 : 0
p=. ": _2 {. getactsize_jijs_''
wd 'psel ',CFSTARTH
wd 'set smsize *',p
)
cfstart_startupopen_button=: 3 : 0
if. 0 = fexist startup do.
  if. 2 query 'Startup file does not exist. Create it?' do.
    return. end.
  '' fwrite startup
end.
open_j_ startup
)

CFFKEYS=: 0 : 0
pc cffkeys;pn "Configure Fkeys";
xywh 6 8 150 11;cc t0 static;cn "Function Key Definitions:";
xywh 6 21 193 180;cc fkeyset listbox ws_border ws_vscroll;
xywh 208 21 44 12;cc add button;cn "&Add";
xywh 208 35 44 12;cc modify button;cn "&Modify";
xywh 208 54 44 12;cc delete button;cn "&Delete";
pas 6 6;pcenter;
rem form end;
)
cffkeys_run=: 3 : 0
if. y.=0 do.
  wd CFFKEYS
  wd :: ] 'settabstops fkeyset 60'
end.
cfshowfkeyset''
)
cffkeys_act=: ]
cffkeys_add_button=: 3 : 0
cfedfkey_run FKEYNDX=: _1
)
cffkeys_cancel_button=: 3 : 0
wd 'pclose;'
)
cffkeys_modify_button=: 3 : 0
FKEYNDX=: {.(".fkeyset_select),_1
cfedfkey_run ''
)
cffkeys_fkeyset_button=: cffkeys_modify_button
cfshowfkeyset=: 3 : 0
if. #BOXFKEYS do.
  txt=. toeav fkeylist_jijs_ BOXFKEYS
  wd 'set fkeyset ',txt
  wd 'setselect fkeyset ',": FKEYNDX=: 0 >. FKEYNDX
else.
  wd 'set fkeyset'
end.
)
cffkeys_delete_button=: 3 : 0
FKEYNDX=: {.(".fkeyset_select),_1
if. 0 > FKEYNDX do. return. end.
key=. fkeycase_jijs_ 0 pick FKEYNDX{BOXFKEYS
key=. (key i. TAB) {. key
msg=. 'Delete ',key,'?'
if. 0=0 wdquery 'Tools'; msg do.
  BOXFKEYS=: (FKEYNDX ~: i.#BOXFKEYS) # BOXFKEYS
  FKEYNDX=: FKEYNDX <. <:#BOXFKEYS
  cfshowfkeyset''
end.
)

FONTHELP=: textline 0 : 0
Use any fixed pitch font. The Linedraw selection below needs an
oem font with style oem or default, e.g. "ISIJ" 10 oem.
)
CFVIEW=: 0 : 0
pc cfview;pn "Configure View";
xywh 6 6 248 69;cc v2 groupbox;cn "Display Font";
xywh 12 17 140 12;cc smfont edit ws_border es_autohscroll;
xywh 13 30 40 11;cc vansi radiobutton;cn "Ansi";
xywh 58 30 40 11;cc voem radiobutton group;cn "OEM";
xywh 103 30 45 11;cc vdefault radiobutton group;cn "Default";
xywh 202 16 44 12;cc browse button;cn "&Browse...";
xywh 12 42 235 31;cc fonthelp static;
xywh 6 83 248 58;cc v1 groupbox;cn "Display Form";
xywh 12 95 54 9;cc linear checkbox;cn "&Linear";
xywh 12 106 54 9;cc box checkbox group;cn "Bo&x";
xywh 12 117 54 9;cc tree checkbox group;cn "&Tree";
xywh 12 128 54 9;cc parens checkbox group;cn "&Parens";
xywh 81 95 161 11;cc multi checkbox;cn "Allow &Multiple Selections";
xywh 6 152 104 50;cc v3 groupbox;cn "Box Chars and Positioning";
xywh 14 165 50 9;cc ascii radiobutton;cn "&Ascii";
xywh 14 176 50 9;cc linedraw radiobutton group;cn "Li&nedraw";
xywh 68 164 32 32;cc gpos isigraph;
pas 6 6;pcenter;
rem form end;
)
cfview_run=: 3 : 0
if. y.=0 do.
  wd CFVIEW
  
  DISPLAYFORM=: 9!:2''
end.
GPOSORG=: 0 ". wd 'qchildxywhx gpos'
set_gpos_size ''
MULTI=: 1<#DISPLAYFORM
if. IFJAVA do.
  font=. FIXFONTJ
else.
  font=. FIXFONTW
end.
setviewstyle getfontstyle font
wd 'set linedraw ',":linedraw
wd 'set ascii ',":ascii
wd 'set smfont *',font
wd 'set fonthelp *',FONTHELP
wd 'set multi ',":MULTI
cfviewdisp''
)
set_gpos_size=: 3 : 0
a=. 0 ". wd 'qchildxywhx gpos'
GPOSWH=: 3 * >. 3 %~ <./ (2 {. a % GPOSORG) * _2 {. GPOSORG
wd 'setxywhx gpos ',": (2 {. a), 2 # GPOSWH
cfps BOXPOS
)

cfview_gpos_size=: set_gpos_size
cfview_act=: 3 : 0
glsel 'gpos'
)
cfviewdisp=: 3 : 0
wd 'set linear ',":5 e. DISPLAYFORM
wd 'set box ',":2 e. DISPLAYFORM
wd 'set tree ',":4 e. DISPLAYFORM
wd 'set parens ',":6 e. DISPLAYFORM
)
cfview_linear_button=: cfdisplay bind 5
cfview_box_button=: cfdisplay bind 2
cfview_tree_button=: cfdisplay bind 4
cfview_parens_button=: cfdisplay bind 6
cfview_cancel_button=: 3 : 0
wd 'pclose;'
)
cfview_browse_button=: 3 : 0
smfont=: mbfont smfont
viewstyle VSTYLE
)
cfview_gpos_mbldown=: 3 : 0
if. 0 ~: 4!:0 <'sysdata' do. empty'' return. end.
'x y w h'=. 4 {. 0 ". sysdata
px=. 2 - <. 2.99 * y % h
py=. <. 2.99 * x % w
cfps BOXPOS=: px,py
)
cfview_multi_button=: 3 : 0
if. MULTI do.
  MULTI=: 0
  DISPLAYFORM=: (1<.#DISPLAYFORM)$DISPLAYFORM
  cfviewdisp''
else.
  MULTI=: 1
end.
)
cfdisplay=: 3 : 0
DISPLAYFORM=: y. cftoggle DISPLAYFORM
cfviewdisp''
)
cfps=: 3 : 0
'x y'=. y.
xy=. >,{;~0 1 2

scale=. GPOSWH % 3

off=. (IFWINCE) * 16b40000000
f=. wd @ ('qcolor '&,) @ ": @ (off&+)

glclear''
glwantresize''
glmap MM_RAW
glbrush glrgb 0 ". f 15
glrect 0 0, ,~ scale*3
glbrush glrgb 0 ". f IFJAVA { 16 10
p=. 0 1 2 3
gllines scale * 0 ,. p ,. 3 ,. p
gllines scale * p ,. 0 ,. p ,. 3
glrect (0 0,2 > y,x) + scale * (y, x) , 1 1
glshow''
)
cftoggle=: 4 : 0
if. x. e. y. do.
  y. -. x.
else.
  x. , MULTI#y.
end.
)
cfview_vansi_button=: viewstyle bind 'ansi'
cfview_vdefault_button=: viewstyle bind 'default'
cfview_voem_button=: viewstyle bind 'oem'
viewstyle=: 3 : 0
setviewstyle y.
wd 'set smfont *',VSTYLE setfontstyle smfont
)
setviewstyle=: 3 : 0
VSTYLE=: boxopen y.
wd 'set vansi ',":VSTYLE = <'ansi'
wd 'set vdefault ',":VSTYLE = <'default'
wd 'set voem ',":VSTYLE = <'oem'
)

j=. <;._2 (0 : 0)
cfview Display
cfcolor Color
cffkeys Fkeys
cffolder Folders
cfforms Forms
cflaf Look and Feel
cflic License
cfopts Parameters
cfprint Print
cfsess Session
cfskeys Shortcuts
cfstart Startup
cfextern External Programs
)

ndx=. j i.&> ' '
TABGROUPS=: ndx {.each j
TABNAMES=: (ndx+1) }.each j
ALLTABGROUPS=: TABGROUPS
CFMAIN=: 0 : 0
pc cfmain nomax nosize;pn "Configure";
xywh 3 4 77 152;cc t0 groupbox;cn "Category";
xywh 6 16 70 138;cc category listbox ws_vscroll;
xywh 84 0 260 225;cc tabs groupbox;
xywh 12 166 59 10;cc saveconfig checkbox;cn "Save Config";
xywh 15 179 52 12;cc default button;cn "Set Defaults";
xywh 15 207 52 12;cc ok button;cn "OK";
xywh 15 193 52 12;cc cancel button;cn "Cancel";
xywh 3 156 77 69;cc g1 groupbox;cn "";
pas 3 6;pcenter;ptop;
rem form end;
)
cfmain_run=: 3 : 0

if. IFJAVA do.
  exclude=. <'cfcolor'
  JAVALAFNMS=: _2 {.\ <;._2 wd 'javalaf'
  if. IFUNIX do.
    JAVALAFNMS=: JAVALAFNMS -. <'Windows'
  end.
else.
  exclude=. <'cflaf'
end.

msk=. -. TABGROUPS e. exclude
TABGROUPS=: msk # TABGROUPS
TABNAMES=: msk # TABNAMES

TABNDX=: 0
LOADED=: TABNDX { TABGROUPS

wd CFMAIN
JCFH=: wd 'qhwndp'
wd 'setshow tabs 0'
wd 'set category ',toeav TABNAMES
wd 'setselect category 0'
wd 'creategroup tabs'
cfview_run''
wd 'creategroup'
wd 'setshow cfview 1'
wd 'set saveconfig 1'
wd 'pshow'
)
cfmain_category_select=: 3 : 0
swap 0 ". category_select
)


regclean=: 3 : 0
r=. tolower deb y. -. {. a.
res=. r {.~ 1 i.~ (r=' ') > ~:/\r='"'
if. ('"' = {.res) *. '"' = {:res do. }. }: res end.
)
dfltbrowser=: 3 : 0
dlft_shellopen '.htm'
)
dfltepsreader=: 3 : 0
dlft_shellopen '.eps'
)
dfltpdfreader=: 3 : 0
dlft_shellopen '.pdf'
)
dlft_shellopen=: 3 : 0
'' if. 1~:>{.r=. querykeyvalue HKEY_CLASSES_ROOT;y.;'' do.
  return. end.
if. 1~:>{.r=. querykeyvalue HKEY_CLASSES_ROOT;((}:>{:r),'\shell\open\command');'' do.
  return. end.
regclean >{: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
fullaccess=: 983103
querykeyvalue=: 3 : 0
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
)
regopen=: 3 : 0
'hkey subkey'=. y.
'rc x x x x handle'=. RegOpenKeyExA hkey;subkey;0;fullaccess;,0
rc;{.handle
)
regclose=: 3 : 0
>{.RegCloseKey ,<y.
)
assertrc=: ([ , ' ('"_ , ":@] , ')'"_) assert ]=0:

swap=: 3 : 0
ndx=. (#TABGROUPS) | y.
new=. ndx pick TABGROUPS
if. -. (<new) e. LOADED do.
  wd 'creategroup tabs'
  (new,'_run')~0
  wd 'creategroup'
  LOADED=: LOADED,<new
else.
  (new,'_act')~0
end.
wd 'setshow ',(TABNDX pick TABGROUPS),' 0'
TABNDX=: ndx
wd 'setshow ',(TABNDX pick TABGROUPS),' 1'
)

config 0