NB. built from project: ~Source\main\jijs\jijs
NB. jijs init

coclass 'jijs'


COCLASSPATH=: ,each 'jijs';'j';'z'
(}.COCLASSPATH) copath <'jijs'

SMNAME=: ''
SMHWNDP=: ''
SMPATH=: '' 
SMTEXT=: ''

SMSEL=: '' 
SMINIT=: 0 0 700 500 
SMSIZE=: 700 500 
QFORMX=: SMINIT

FTYPES=: '"Scripts (*.ijs)|*.ijs|Session (*.ijx)|*.ijx|All Files (*.*)|*.*"'
IFMAX=: 0 
IFSAVED=: 1 
IFSHOW=: 0 

IFIOX=: (0: ". wd) :: 0: 'qiox'
sh=: 3 : 0
wd'psel jijs;pshow ',>y.{'sw_hide';'sw_shownormal'
)

3 : 0''
if. 0: ~: 4!:0 <'IFJIJX_j_' do. IFJIJX_j_=: 0 end.
)

1!:5 :: ] < jpath '~temp' 
3 : 0''
qm=. 0 ". wd 'qm'
if. IFWIN32 > IFJAVA do.
  SMDESK=: 14 15 { qm
  SMBLK=: +/ <: 9 10 { qm
else.
  SMDESK=: (2 {. qm) - 0 33
  SMBLK=: 26
end.
)
deb=: #~ (+. 1: |. (> </\))@(' '&~:)
intn=: i.@>: % ]
quote=: ''''&,@(,&'''')@(#~ >:@(=&''''))
pathname=: ({. ; }.)~ (0: i.~ +./\.@(=&PATHSEP))
roundint=: <.@:+&0.5
todelim=: ; @: ((EAV&,) @ (,&EAV) @ , @ ": &.>)
tolist=: }. @ ; @: (LF&, @ , @ ": each)
sysmodifiers=: ''
close=: 3 : 0
if. IFIJX do.
  closeijx''
else.
  closeijs''
end.
)
closewindows=: 3 : 0
for_f. qsmallijs_jijs_'' do.
  smsel f
  smsave :: ] ''
  smclose ''
end.
smselact_jijs_ ''
)
closeijx_jijs_=: 3 : 0
if. wdquery 'Jsoftware';'Do you want to close?' do. return. end.
fms=. wdforms''
fms=. fms #~ (<'jijs') = 3 {"1 fms
loc=. 2{"1 fms
for_lc. loc do.
  if. 0 = exitijs__lc :: 1: '' do. return. end.
end.
0!:101 :: ] SYS_TERMINATE
2!:55''
)
closeijs=: 3 : 0
if. iftempscript SMNAME do.
  if. 0 = #readid SMHWNDP do.
    1!:55 :: ] <SMNAME
  else.
    select. 3 query 'Delete ',SMNAME,'?'
    case. 0 do. 1!:55 :: ] <SMNAME
    case. 1 do. save 2
    case. 2 do. 0 return.
    end.
  end.
else.
  save 0
end.
destroy''
)

exitijs=: 3 : 0
if. iftempscript SMNAME do.
  if. 0 = #readid SMHWNDP do.
    1!:55 :: ] <SMNAME
    1 return.
  end.
  select. 3 query 'Delete ',SMNAME,'?'
  case. 0 do.
    1!:55 :: ] <SMNAME
    1 return.
  case. 2 do.
    0 return.
  end.
end.
save 1
1
)
getactsize=: 3 : 0
wd 'psel ',qsmact''
0 ". wd 'qformx'
)
getformx=: 3 : 0
res=. i. 0 4
for_i. y. do.
  wd 'psel ',>i
  res=. res, 0 ". wd 'qformx'
end.
)
getsaveas=: 3 : 0

fn=. SMNAME, (0=#SMNAME) # jpath '~temp'

while. 1 do.
  'p f'=. pathname fn
  
  j=. FTYPES,' ofn_nochangedir'
  
  fn=. wd 'mbsave "Save As" "',p,'" "',f,'" ',j
  
  if. 0=#fn do. return. end.
  if. -. '.' e. fn do. fn=. fn,'.ijs' end.
  if. fn -: SMNAME do. return. end.
  if. 0=flexist fn do. return. end.
  
  j=. fn,LF,'This file already exists.',LF,LF
  msg=. j,'Replace existing file?'
  
  if. 0=2 query msg do. fn return. end.
end.

)
ifshiftkey=: 3 : 0
'1' e. sysmodifiers
)
iftempscript=: 3 : 0
name=. 1 pick pathname y.
_1 ~: _1 ". (name i: '.') {. name
)
info=: 3 : 0
wdinfo 'Jsoftware';y.
)
nounrep=: 4 : 0
dat=. y.
if. (0=#dat) +. 2=3!:0 dat do.
  if. LF e. dat do.
    dat=. dat, LF -. {:dat
    x.,'=: 0 : 0', LF, ; <;.2 dat,')',LF
  else.
    x.,'=: ',(quote dat),LF
  end.
else.
  x.,'=: ',(":dat),LF
end.
)
parentname=: 3 : 0
sn=. (-.+./\.SMNAME=PATHSEP) # SMNAME
select. SMSTYLE
case. 0 do.
  n=. sn
case. 1 do.
  n=. SMNAME
case. 2 do.
  n=. sn,' - ',SMNAME
case. 3 do.
  n=. sn,'  [] ',SMNAME
end.
'pn *',n
)
pmovex=: 4 : 0
for_i. x. do.
  wd 'psel ', >i
  wd 'pshow sw_shownormal'
  wd 'pmovex ', ": i_index{y.
end.
)
query=: 4 : 0
x. wdquery 'Jsoftware';y.
)
readid=: 3 : 0
wd 'psel ',y.
dat=. wd 'qd'
ndx=. ({."1 dat) i. <,'e'
1 pick ndx { dat
)
marksavedid=: 3 : 0
wd 'psel ',y.
wd 'setmodified e 0'
)
saveopenwindows=: 3 : 0
for_f. qsmallijs '' do.
  smsel f
  smsave ''
end.
)
setfontall=: 3 : 0
for_id. qsmall''do.
  wd 'psel ',> id
  wd 'setfont e ',y.
end.
)
setpnall=: 3 : 0
for_lc. 2 {"1 qsmallforms'' do.
  wd 'psel ',":SMHWNDP__lc
  wd parentname__lc ''
end.
)
togglexs=: 3 : 0
smfocus smsel qsmlastxs ''
)
winmax=: 3 : 0
if. IFWIN32 > IFJAVA do.
  ids=. qsmall''
  sfx=. IFMAX pick 'maximized';'normal'
  wd ; (<'psel ') ,each ids ,each <(';pshow sw_show',sfx,';')
else.
  fms=. qsmallforms''
  ids=. 1 {"1 fms
  loc=. 2 {"1 fms
  if. IFMAX do.
    qf=. i. 0 4
    for_lc. loc do.
      qf=. qf, QFORMX__lc
    end.
    wd ; (<';psel ') ,each ids ,each <"1 ';pmovex ',"1 ": qf
  else.
    for_lc. loc do.
      QFORMX__lc=: 0 ". wd 'psel ',(lc_index pick ids),';qformx'
    end.
    wd ; (<';psel ') ,each ids ,each (<';pmovex ',": 0 0,SMDESK)
  end.
end.
IFMAX_jijs_=: -.IFMAX
SMSEL_jijs_=: _1 pick ids
smfocus_jijs_''
)
ide_maximize=: 3 : 0
wd ; ('psel '&,@(,&';pshow sw_showmaximized;')) each qsmall''
)
ide_minimize=: 3 : 0
wd ; ('psel '&,@(,&';pshow sw_showminimized;')) each qsmall''
)
ide_restore=: 3 : 0
wd ; ('psel '&,@(,&';pshow sw_restore;')) each qsmall''
)

create=: 3 : 0

SMNAME=: y.
IFIJX=: '.ijx' -: _4 {. SMNAME

if. IFIJX do.
  ndx=. 6 + ('editijs' E. JIJS) i.1
  bf=. 'x' ndx } JIJS
else.
  bf=. JIJS
end.

if. -. IFWINCE do.
  if. # wd 'qpx' do.
    topleft=. getcascade''
    bf=. bf,'pmovex ',": topleft, SMSIZE
  else.
    bf=. bf,'pmovex ',": SMINIT
  end.
end.

if. IFIJX do.
  txt=. ''
  if. -. IFWINCE do.
    bf=. bf, ';setenable editformedit 0'
  end.
  bf=. bf, ';pgroup jijx'
  IFSAVED=: 1
else.
  if. IFSAVED=: -. flexist SMNAME do.
    '' flwrite SMNAME
  end.
  SMTEXT=: flread SMNAME
  txt=. SMTEXT
  bf=. bf, ';pgroup jijs'
  recent_put SMNAME
end.

bf=. bf, ';setfont e ',FIXFONT
bf=. bf, ';setmodified e 0;setfocus e;setselect e 0 0 0;qhwndp'
SMHWNDP=: wd bf
smsel SMHWNDP

wd parentname''
if. #txt do. wd 'set e *', txt end.
if. IFSHOW = 0 do.
  IFSHOW_jijs_=: 1
  if. ARGV -: ,<'undefined' do. return. end.
end.

if. -.IFIOX do. wd 'pshow' end.
)
destroy=: 3 : 0
wd 'pclose'
codestroy''
)

ABOUTJ=: 0 : 0
Copyright 1994-2005 Jsoftware Inc.

For information about this and related products:

   www.jsoftware.com
   info@jsoftware.com

This computer program is protected by copyright
law and international treaties.
)
aboutj=: 3 : 0
r=. 'J', }. (i.&'/' {. ]) 9!:14''
r=. r,' - ',ABOUTJ,LF,JVERSION,LF,aboutjul''
coerase <'jcfg'
r
)
aboutjul=: 3 : 0
cocurrent 'jcfg'
val=: 2;''
USERFNAME=: USERLNAME=: USERJUL=: ''
0!:0 :: ] <jpath '~config\config.ijs'
USERNAME=: USERFNAME,' ',USERLNAME
0!:0 :: ] <jpath '~system\extras\util\jul.ijl'
nl=. 'Name: ',USERNAME,LF,'License: ',USERJUL
select. 0 pick val
case. 0 do.
  'J User License:',LF,nl
case. 1 do.
  'Non-current J User License:',LF,nl,LF,'Release: J',1 pick val
case. 2 do.
  'No J User License.'
case. 3 do.
  'Invalid J User License:',LF,nl
end.
)


getcascade=: 3 : 0
getcascade1 (1 {"1 wdforms'');SMSIZE
)
getcascade1=: 3 : 0
'fms size'=. y.
if. 0 = #fms do. 0 0 return. end.
len=. 1 + 0 >. <. <./ (SMDESK - size) % SMBLK
bgn=. (SMBLK * i.len) - -: SMBLK
end=. bgn + SMBLK
res=. 2 {."1 getformx fms
res=. res #~ *./"1 res < {: end
x=. {."1 res
y=. {:"1 res
x=. (i.<./) +/ (x >/ bgn) *. x </ end
y=. (i.<./) +/ (y >/ bgn) *. y </ end
SMBLK * x,y
)
getcascades=: 3 : 0
len=. 1 + 0 >. <. <./ (SMDESK - SMSIZE) % SMBLK
SMBLK * len | i. y.
)

flexist=: 1:@(1!:4)@< :: 0:
flread=: 3 : 'toJ 1!:1 <y.'
flwrite=: 4 : '(toHOST x.) 1!:2 <y.'
openijs=: 3 : 0

if. #SMNAME do.
  if. 'ijx' -: _3 {. SMNAME do.
    p=. SMPATH
    if. 0 = #p do.
      p=. jpath '~temp'
    end.
  else.
    p=. 0 pick pathname SMNAME
  end.
else.
  p=. jpath '~user'
end.

j=. FTYPES,' ofn_filemustexist ofn_nochangedir'
f=. wd 'mbopen "Open File" "',p,'" "" ',j
if. 0 = #f do. '' return. end.
SMPATH=: 0 pick pathname f
open f
)
open=: 3 : 0
0 open y.
:
smopen > y.
smscroll x.
smfocus ''
)
save=: 3 : 0
sel=. {. y. , 1
new=. readid SMHWNDP
if. SMTEXT -: new do. 1 return. end.
if. (sel=0) +. (sel=1) *. IFSAVED=0 do.
  if. 1=2 query 'Save changes to ',SMNAME,'?' do.
    0 return.
  end.
end.
new flwrite SMNAME
recent_put SMNAME
marksavedid SMHWNDP
SMTEXT=: new
IFSAVED=: 1
)
saveas=: 3 : 0
fn=. getsaveas''
if. #fn do.
  SMNAME=: fn
  new=. readid SMHWNDP
  new flwrite SMNAME
  recent_put SMNAME
  SMTEXT=: new
  IFSAVED=: 1
  wd parentname ''
end.
)

FKEYQ=: 197{a.      
a=. '0123456789acfhilrstAFCS'
fkeycase=: 'F'"_ , (('acs',a)"_ i. }.) { ('ACS',a)"_
set_fkeys=: 3 : 0
FKEYS=: boxfkeys y.
)
boxfkeys=: 3 : 0
if. 0 = #y. do.
  i.0 4
else.
  key=. y. , LF -. {:y.
  <;._1 &> FKEYQ ,each <;._2 key
end.
)
unboxfkeys=: 3 : 0
if. 0 = #y. do.
  ''
else.
  tolist <@}.@;"1 FKEYQ ,each y.
end.
)
fkeyrun=: 3 : 0
ndx=. ({."1 FKEYS) i. <y.
if. ndx = # FKEYS do. empty '' return. end.
'sty cmd'=. 1 3 { ndx { FKEYS
select. {. sty
case. '0' do.
  smprompt cmd
case. '1' do.
  runimmx0 cmd
case. '2' do.
  runimmx1 cmd
end.
)
fkeyselect=: 3 : 0
if. 0 e. #FKEYS do.
  info 'No fkeys are defined. See menu Edit|Configure|FKeys' return.
end.
require 'jpick'
pik=. fkeylist FKEYS
sel=. pik;'';'FKeys';'fkeyselect1';1 45
sel conew 'jpick'
)
fkeylist=: 3 : 0
nos=. fkeycase each 0 {"1 y.
sep=. TAB
nos ,each sep ,each 2 {"1 y.
)
fkeyselect1=: 3 : 0
if. #y. do.
  fkeys (<y.;0) pick FKEYS
end.
)

getfile=: 3 : 0
path=. jpath '~home'
t=. 'mbopen "Select File" "',path,'" "" '
t=. t,'"Scripts (*.ijs)|*.ijs|All Files (*.*)|*.*"'
t=. t,' ofn_filemustexist ofn_pathmustexist;'
wd t
)
getline=: 3 : 0
smselact''
txt=. smread''
pos=. {. smgetsel''
ndx=. pos + <./ (pos }. txt) i. CRLF
txt=. ndx {. txt
ndx=. - <./ (|. txt) i. CRLF
ndx {. txt
)
getselection=: 3 : 0
smselact''
txt=. smread''
'b e'=. 2 $ smgetsel''
b }. e {. txt
)

new=: 3 : 0
n=. conew 'jijs'
d=. 1!:0 jpath '~temp\*.',y.
a=. 0, {.@:(0&".)@> _4 }. each {."1 d
a=. ": {. (i. >: #a) -. a
create__n jpath '~temp\',a,'.',y.
)
newijs=: 3 : 0
new 'ijs'
)
newijx=: 3 : 0
new 'ijx'
if. IFWINCE < y. -: 0 do.
  if. (NEWUSER = 1) *. 1 = #ARGV do.
    load jpath '~system\extras\util\newuser.ijs'
  end.
end.
)

comparesvn=: 3 : 0
'require'~'compare'
smselact''
smsave''
nam=. id2name SMSEL
msk=. +./\. nam=PATHSEP
pth=. msk # nam
bal=. (-.msk) # nam
svn=. pth,'.svn\text-base\',bal,'.svn-base'
txt=. 1!:1 :: 0: <svn
if. txt -: 0 do.
  wdinfo 'Unable to read: ',svn
else.
  wdview fcompare svn;nam
end.
)

RECENTFILE=: jpath '~config\recent.ijs'
RECENTMAX=: 20
WRECENT=: 0 : 0
pc wrecent;pn "Recent Scripts";
xywh 3 3 175 130;cc lb listbox ws_vscroll rightmove bottommove;
xywh 182 4 48 11;cc open button bs_defpushbutton leftmove rightmove;cn "&Open";
xywh 182 16 48 11;cc view button leftmove rightmove;cn "&View";
xywh 182 28 48 11;cc run button leftmove rightmove;cn "&Run";
xywh 182 40 48 11;cc rund button leftmove rightmove;cn "Run &Display";
pas 3 3;pcenter;
rem form end;
)
wrecent_run=: 3 : 0
wd WRECENT
wd 'set lb ',todelim y.
wd 'setselect lb 0'
wd 'setfocus lb'
wd 'pshow'
)
wrecent_close=: 3 : 0
wd 'pclose'
codestroy ''
)
wrecent_open_button=: 3 : 0
if. #lb do.
  if. 0 = ifshiftkey'' do. wrecent_close'' end.
  runimmx0_jijs_ 'smopen_jijs_ ''',lb,''''
end.
)
wrecent_view_button=: 3 : 0
if. #lb do.
  if. 0 = ifshiftkey'' do. wrecent_close'' end.
  runimmx0 'wdview 1!:1 < ''',lb,''''
end.
)
wrecent_run_button=: 3 : 0
if. #lb do.
  if. 0 = ifshiftkey'' do. wrecent_close'' end.
  runimmx1 'load ''',lb,''''
end.
)
wrecent_rund_button=: 3 : 0
if. #lb do.
  if. 0 = ifshiftkey'' do. wrecent_close'' end.
  runimmx1 'loadd ''',lb,''''
end.
)
wrecent_enter=: wrecent_lb_button=: wrecent_open_button
wrecent_cancel=: wrecent_close
recent_run=: 3 : 0
if. 0 e. #RECENT do.
  info 'No recent files'
else.
  a=. conew 'jijs'
  wrecent_run__a RECENT
end.
)
recent_open=: 3 : 0
if. #y. do.
  smopen y. pick RECENT
end.
)
recent_put=: 3 : 0
if. iftempscript y. do. return. end.
new=. ~. (boxxopen y.), RECENT
new=. (RECENTMAX <. #new) {. new
if. new -: RECENT do. return. end.
recent_save RECENT_jijs_=: new
)
recent_read=: 3 : 0
try.
  0!:100 (1!:1) <RECENTFILE
  RECENT=: LF cutopen RECENT
catch.
  RECENT=: ''
end.
)
recent_save=: 3 : 0
dat=. 'NB. Recent Scripts',LF
dat=. dat,LF,'RECENT' nounrep tolist RECENT
dat=. toHOST dat
dat 1!:2 <RECENTFILE
)

runimmx0=: 3 : 0
IMMX_jijs_=: y.
9!:27 '0!:100 IMMX_jijs_'
9!:29 [ 1
)
runimmx1=: 3 : 0
IMMX_jijs_=: y.
9!:27 '0!:101 IMMX_jijs_'
9!:29 [ 1
)
runfile=: 3 : 0
f=. getfile $0
if. #f do.
  fn=. 'load',(1 = 1 {. y.)#'d'
  runimmx1 fn,' ''',f,''''
end.
)
runline=: 3 : 0
runimmx1 getline''
)
runselection=: 3 : 0
runimmx1 getselection''
)
runwindow=: 3 : 0
save 1
fn=. 'load',(1 = 1 {. y.)#'d'
runimmx1 fn,' ''',SMNAME,''''
)

set_skeys=: 3 : 0
if. 0 = #y. do. return. end.
dat=. <;._2 y.
ndx=. dat i. &> ' '
nam=. ndx {.each dat
key=. (ndx+1) }.each dat
frm=. <;._2 JIJS
ndx=. 5 + (5 }.each frm) i. &> ' '
sel=. ndx {. each frm
ind=. sel i. (<'menu ') ,each nam
msk=. ind < #frm
if. 0 e. msk do.
  ind=. msk # ind
  key=. msk # key
end.
new=. key set_skey1 each ind { frm
frm=. new ind } frm
JIJS=: ; frm ,each LF
)
set_skey1=: 4 : 0
txt=. 4 }. y.
sep=. (txt = ' ') > ~:/\ txt = '"'
'id cp sc tt sh'=. 5 {. sep <;.1 txt
sc=. ' "',x.,'"'
key=. getskey x.
('jijs_',key,'_fkey')=: ('jijs_',(id-.' '),'_button')~
'menu', ;id;cp;sc;tt;sh
)
getskey=: 3 : 0
tolower '+ ' -.~ ({:y.),}:y.
)
boxskeys=: 3 : 0
if. 0 = #y. do.
  i.0 2
else.
  dat=. <;._2 y.
  ndx=. dat i. &> ' '
  (ndx {.each dat) ,. (ndx+1) }.each dat
end.
)
unboxskeys=: 3 : 0
if. 0 = #y. do.
  ''
else.
  nam=. {."1 y.
  key=. {:"1 y.
  tolist nam ,each ' ' ,each key
end.
)

getSMSEL=: 3 : 0
if. -. (<SMSEL) e. 1 {"1 wdforms'' do.
  smsel ''
end.
SMSEL
)
id2loc=: 3 : 0
fms=. wdforms''
ndx=. (1 {"1 fms) i. boxopen y.
if. ndx < #fms do.
  (<ndx;2) { fms
else.
  ''
end.
)
id2names=: 3 : 0
fms=. wdforms''
ndx=. ,(1 {"1 fms) i. boxxopen y.
ind=. I. ndx < #fms
nms=. (#ndx) # <''
for_i. ind do.
  loc=. 2 { (i{ndx) { fms
  nms=. (<SMNAME__loc) i } nms
end.
)
id2name=: > @ {. @ id2names
name2id=: 3 : 0
fms=. wdforms''
fms=. fms #~ (3 {"1 fms) e. 'jijs';'jijx'
fid=. tolower > y.
if. 0 = #fid do. return. end.
if. (<fid) e. 1 {"1 fms do. return. end.
for_loc. 2 {"1 fms do.
  if. fid -: tolower SMNAME__loc do.
    1 pick loc_index { fms return.
  end.
end.
''
)
qsmact=: 3 : 0
fms=. wdforms''
b=. (3 {"1 fms) e. 'jijs';'jijx'
fms=. b # fms
last=. 0 ". > 4{"1 fms
ndx=. last i. >./last
(<ndx;1) pick fms
)
qsmall=: 3 : 0
fms=. wdforms''
msk=. ('jijs';'jijx') e.~ 3 {"1 fms
fms=. msk # fms
(1 {"1 fms) /: 0 ". > 4{"1 fms
)
qsmlastxs=: 3 : 0
fms=. wdforms''
b=. (3 {"1 fms) e. 'jijs';'jijx'
fms=. b # fms
last=. 0 ". > 4 {"1 fms
fms=. fms \: last
if. (<'jijs') = 3 { {. fms do.
  ndx=. (3 {"1 fms) i. <'jijx'
else.
  ndx=. 1
end.
ndx=. ndx <. <: #fms
(<ndx;1) pick fms
)
qsmallforms=: 3 : 0
fms=. wdforms''
msk=. ('jijs';'jijx') e.~ 3 {"1 fms
fms=. msk # fms
fms /: 0 ". > 4{"1 fms
)
qsmallijs=: 3 : 0
fms=. wdforms''
msk=. (<'jijs') = 3 {"1 fms
msk # 1 {"1 fms
)
qsmsize=: 3 : 0
wd 'psel ',SMSEL
0 ". wd 'qformx'
)
qsmout=: 3 : 0
fms=. wdforms''
ind=. (3 {"1 fms) i. <'jijx'
(<ind;1) pick fms
)
smappend=: 3 : 0
txt=. smread ''
smwrite txt,y.
)
smclose=: 3 : 0
getSMSEL''
if. #SMSEL do.
  loc=. id2loc SMSEL
  destroy__loc ''
  smsel ''
end.
)
smfocus=: 3 : 0
wd 'psel ',SMSEL
wd 'pactive'
wd 'setfocus e'
)
smfocusact=: smfocus @ smselact
smfocusout=: smfocus @ smselout
smgetsel=: 3 : 0
wd 'psel ',SMSEL
dat=. wd 'qd'
ndx=. ({."1 dat) i. <'e_select'
0 ". 1 pick ndx { dat
)
smopen=: 3 : 0
id=. name2id y.
if. 0 = #id do.
  a=. conew 'jijs'
  create__a y.
else.
  smsel id
  wd 'psel ',SMSEL
end.
wd 'setfocus e'
empty''
)
smmove=: 3 : 0
wd 'psel ',SMSEL
wd 'pmovex ',": y.
)
smprompt=: 3 : 0
'txt def'=. 2 {. boxxopen y.
smsel qsmout''
wd 'psel ',SMSEL
dat=. wd 'qd'
ndx=. ({."1 dat) i. <,'e'
ses=. 1 pick ndx { dat
ses=. ses, (LF ~: _1 {. ses) # LF
ses=. ses,txt
wd 'set e *',ses,def
wd 'setselect e ',": ((#ses)+0,#def), 1
)
smread=: 3 : 0
readid SMSEL
)
smreplace=: 3 : 0
wd 'psel ',SMSEL
wd 'setreplace e *',y.
)
smsave=: 3 : 0
getSMSEL''
if. #SMSEL do.
  loc=. id2loc SMSEL
  save__loc 2
end.
)
smscroll=: 3 : 0
wd 'psel ',SMSEL
wd 'setscroll e ',": y.
)
smsel=: 3 : 0
empty SMSEL_jijs_=: name2id , > y.
)
smselact=: smsel @ qsmact
smselout=: smsel @ qsmout
smsetcmd=: 3 : 0
cmd=. 4 {. y.
def=. cmd , FKEYS
FKEYS=: sort (~: {."1 def) # def
)
smsetselect=: 3 : 0
wd 'psel ',SMSEL
wd 'setselect e ',": y.
)
smwrite=: 3 : 0
wd 'psel ',SMSEL
wd 'set e *',y.
)

select_line=: 3 : 0

smselact''
txt=. smread ''
'bgn end'=. oldsel=. smgetsel ''

if. 0 = #txt do.
  wdinfo 'Selection';'No text selected' return.
end.

sel=. bgn }. end {. txt

if. LF ~: {. sel do.
  ndx=. LF i.~ |. bgn {. txt
  bgn=. bgn - ndx
end.
if. LF ~: {: sel do.
  txt=. txt, LF
  ndx=. 1 + LF i.~ end }. txt
  end=. end + ndx
end.

sel=. bgn }. end {. txt

csl=. <;.2 sel

select. y.
case. 'minus' do.
  msk=. -. (8 {. each csl) e. 'NB. ----';'NB. ===='
  csl=. msk # csl
  msk4=. (<'NB. ') = 4 {. each csl
  msk3=. msk4 < (<'NB.') = 3 {. each csl
  new=. ; ((msk4 * 4) + msk3 * 3) }. each csl
  set=. bgn + 0, <: #new
case. 'plus' do.
  msk=. 1 < # &> csl
  hdr=. (3 + msk) {. each <'NB.'
  new=. ; hdr ,each csl
  set=. bgn + 0, <: #new
case. 'plusline1' do.
  cmt=. 'NB. ',(57#'-'),LF
  new=. ; cmt ; csl
  set=. oldsel + #cmt
case. 'plusline2' do.
  cmt=. 'NB. ',(57#'='),LF
  new=. ; cmt ; csl
  set=. oldsel + #cmt
case. 'sort' do.
  new=. ; /:~ csl
  set=. bgn + 0, <: #new
end.

if. -. new -: sel do.
  smsetselect bgn, end
  smreplace new
  smsetselect set <. <: #smread''
end.

)
select_text=: 3 : 0

smselact''
txt=. smread ''
'bgn end'=. smgetsel ''

if. bgn = end do.
  wdinfo 'Selection';'No text selected' return.
end.

sel=. bgn }. end {. txt
select. y.
case. 'lower' do.
  new=. tolower sel
case. 'toggle' do.
  lwr=. a. {~ (i.26) + a. i. 'a'
  upr=. a. {~ (i.26) + a. i. 'A'
  ndx=. (lwr,upr,a.) i. sel
  new=. ndx { upr,lwr,a.
case. 'upper' do.
  new=. toupper sel
end.

if. -. new -: sel do.
  smreplace new
  smsetselect bgn + 0,#new
end.

)

tilecascade=: 3 : 0
ids=. qsmall''
pos=. getcascades_jijs_ #ids
ids pmovex (pos,.pos) ,"1 SMSIZE
)
tileacross=: 3 : 0
'ids x y w h'=. tileget''
len=. # ids
if. len = 0 do. return. end.
if. 4 > len do.
  xs=. x + roundint w * intn len
  xp=. }: xs
  wp=. (}. xs) - xp
  pos=. xp,.y,.wp,.h
else.
  pos=. ids tile2fit x,y,w,h
end.
ids pmovex pos
)
tile=: 3 : 0
'ids x y w h'=. tileget''
len=. # ids
if. len = 0 do. return. end.
if. 4 > len do.
  ys=. y + roundint h * intn len
  yp=. }: ys
  hp=. (}. ys) - yp
  pos=. x,.yp,.w,.hp
else.
  pos=. ids tile2fit x,y,w,h
end.
ids pmovex pos
)
tileget=: 3 : 0
ids=. |. qsmall''
len=. # ids
fmx=. getformx ids
xy=. 2 {."1 fmx
msk=. xy +./ . >: _10000
if. 0 e. msk do. 
  ids=. msk # ids
  fmx=. msk # fmx
  xy=. msk # xy
end.
wh=. 2 }."1 fmx
'x y'=. <./ xy
'w h'=. (>./ xy + wh) - x,y
ids;x;y;w;h
)
rdist=: 3 : 0
r=. <.y.
r + ((+/r) + \:/: 1|y.) < <.0.5++/y.
)
tile2fit=: 4 : 0
ids=. x.
'x y w h'=. y.
len=. #x.
cls=. <. %: len
rws=. rdist cls # len % cls

nub=. ~. rws
wid=. rdist cls # w % cls
blk=. {.nub
cnt=. +/ rws = blk
col=. cnt {. wid

pos=. tile2fit1 x;y;w;h;blk;col

if. cnt < #rws do.
  x=. x + +/ col
  w=. w - +/ col
  col=. cnt }. wid
  blk=. {: nub
  pos=. pos, tile2fit1 x;y;w;h;blk;col
end.

)
tile2fit1=: 3 : 0
'x y w h rws wid'=. y.
cls=. #wid
ys=. y + roundint h * intn rws
xp=. rws # x + 0, +/\ }: wid
yp=. (rws*cls) $ }: ys
wp=. rws # wid
hp=. (rws*cls) $ (}.-}:) ys
xp,.yp,.wp,.hp
)

JIJS=: 0 : 0
pc jijs;
menupop "&File";
menu filenewijs "&New ijs" "Ctrl+N" "" "";
menu filenewclass "&New Class..." "" "" "";
menusep ;
menu fileopen "&Open..." "Ctrl+O" "" "";
menu filerecent "&Recent..." "" "" "";
menusep ;
menu save "Save" "Ctrl+S" "" "";
menu saveas "Save &As..." "" "" "";
menu close "Close" "" "" "";
menusep ;
menu fileprint "&Print" "Ctrl+P" "" "";
menu fileprintsetup "Print Setup..." "" "" "";
menusep ;
menu fileexit "E&xit" "" "" "";
menupopz;
menupop "&Edit";
menu editundo "&Undo" "Ctrl+Z" "" "";
menu editredo "&Redo" "Ctrl+Y" "" "";
menusep ;
menu editcut "Cu&t" "Ctrl+X" "" "";
menu editcopy "&Copy" "Ctrl+C" "" "";
menu editpaste "&Paste" "Ctrl+V" "" "";
menusep ;
menu editselectall "Select &All" "Ctrl+A" "" "";
menusep ;
menu editfind "&Find..." "Ctrl+F" "" "";
menu editfif "Find &in Files..." "Ctrl+Shift+F" "" "";
menusep ;
menu editdirmatch "Directory &Match..." "" "" "";
menusep ;
menu editinputlog "Input &Log..." "Ctrl+D" "" "";
menusep ;
menu editformedit "Form &Editor..." "" "" "";
menusep ;
menu editconfigure "Confi&gure..." "" "" "";
menupopz;
menupop "&Run";
menu runline "&Line" "Ctrl+R" "" "";
menu runselection "&Selection" "Ctrl+E" "" "";
menu runwindow "&Window" "Ctrl+W" "" "";
menu runwindowd "Window &Display" "Ctrl+Shift+W" "" "";
menusep ;
menu runfile "&File" "Ctrl+T" "" "";
menu runfiled "File Di&splay" "Ctrl+Shift+T" "" "";
menusep ;
menu runprojman "&Project Manager..." "Ctrl+B" "" "";
menu rundebug "&Debug..." "Ctrl+K" "" "";
menu runpublish "&HTML Publish..." "" "" "";
menupopz;
menupop "&Tools";
menupop "Selection";
menu selminus "&Remove ZZ." "Ctrl+Shift+B" "" "";
menu selplus "&Add ZZ." "Ctrl+Shift+N" "" "";
menu selplusline1 "&Add ZZ. --" "Ctrl+Shift+K" "" "";
menu selplusline2 "&Add ZZ. ==" "Ctrl+Shift+L" "" "";
menusep ;
menu sellower "&Lower Case" "" "" "";
menu selupper "&Upper Case" "" "" "";
menu seltoggle "&Toggle Case" "" "" "";
menusep ;
menu selsort "&Sort" "" "" "";
menupopz;
menusep ;
menu fkeys "&FKeys..." "" "" "";
menupopz;
menupop "&Studio";
menu labs "&Labs..." "" "" "";
menu labadvance "Advance" "Ctrl+J" "" "";
menu labchapters "Chapters..." "" "" "";
menusep ;
menu labauthor "A&uthor..." "" "" "";
menusep ;
menu demos "Demos..." "" "" "";
menupopz;
menupop "&Window";
menu tilecascade "&Cascade" "" "" "";
menu tile "&Tile" "" "" "";
menu tileacross "Tile Acros&s" "" "" "";
menusep ;
menu max "&Maximize On/Off" "Ctrl+M" "" "";
menusep ;
menu forms "&Forms..." "Ctrl+Q" "" "";
menupopz;
menupop "&Help";
menu helphelp "&Help" "" "" "";
menusep ;
menu helplicense "&J User License" "" "" "";
menu helpgeneral "&General Info" "" "" "";
menu helprelease "&Release Highlights" "" "" "";
menusep ;
menu helpvocab "&Vocabulary" "F1" "" "";
menu helpconstants "&Constants" "" "" "";
menu helpcontrols "Control &Structures" "" "" "";
menu helpforeigns "&Foreign Conjunction" "" "" "";
menusep ;
menu helpwdover "&wd Overview" "Shift+F1" "" "";
menu helpwdcmd "&wd Commands" "" "" "";
menu helpgl2cmd "&gl2 Commands" "" "" "";
menusep ;
menu helpcontext "&Context Sensitive" "Ctrl+F1" "" "";
menusep ;
menu helpindex "&Index" "" "" "";
menu helpuser "&User Manual" "" "" "";
menu helpprimer "&Primer" "" "" "";
menu helpphrases "&Phrases" "" "" "";
menu helpdictionary "&Dictionary" "" "" "";
menu helprelnotes "Release &Notes" "" "" "";
menusep ;
menu aboutj "&About J..." "" "" "";
menupopz;
xywh 0 0 250 150;cc e editijs ws_hscroll ws_vscroll es_nohidesel rightmove bottommove;
pas 0 0;
rem form end;
)

3 : 0 ''
ndx=. I. 'ZZ' E. JIJS
JIJS=: 'NB' (ndx +/ 0 1) } JIJS

if. IFJAVA do.
  t=. <;.2 JIJS,LF
  m=. (1: e. 'fileprintsetup'&E.) &> t
  if. IFUNIX do.
    m=. m +. (+. 1&|.) (1: e. 'runpublish'&E.) &> t
  end.
  JIJS=: }: ; (-.m) # t
end.

)
jijs_aboutj_button=: 3 : 0
wd'mb "About J" *',aboutj''
)
jijs_default=: 3 : 0
if. systype -: 'fkey' do. fkeyrun syschild end.
)

jijs_close=: jijs_cancel=: jijs_close_button=: close
jijs_demos_button=: demos
jijs_editconfigure_button=: config
jijs_editcopy_button=: 3 : 'wd ''setedit e c'''
jijs_editcut_button=: 3 : 'wd ''setedit e x'''
jijs_editdirmatch_button=: dirmatch
jijs_editfif_button=: fif
jijs_editfind_button=: editfind
jijs_editformedit_button=: formedit
jijs_editinputlog_button=: editinputlog
jijs_editpaste_button=: 3 : 'wd ''setedit e v'''
jijs_editredo_button=: 3 : 'wd ''setedit e y'''
jijs_editselectall_button=: 3 : 'wd ''setselect e'''
jijs_editundo_button=: 3 : 'wd ''setedit e z'''
jijs_fileexit_button=: closeijx
jijs_filenewclass_button=: classwizard_j_
jijs_filenewijs_button=: newijs
jijs_fileopen_button=: openijs
jijs_fileprint_button=: fileprint_j_
jijs_fileprintsetup_button=: fileprintsetup_j_
jijs_filerecent_button=: recent_run
jijs_fkeys_button=: fkeyselect
jijs_forms_button=: forms
jijs_helpconstants_button=: 3 : 'htmlhelp ''dictionary\dcons.htm'''
jijs_helpcontext_button=: 3 : 'help y.'
jijs_helpcontrols_button=: 3 : 'htmlhelp ''dictionary\ctrl.htm'''
jijs_helpdictionary_button=: 3 : 'htmlhelp ''dictionary\contents.htm'''
jijs_helpforeigns_button=: 3 : 'htmlhelp ''dictionary\xmain.htm'''
jijs_helpgeneral_button=: 3 : 'htmlhelp ''user\product.htm'''
jijs_helpgl2cmd_button=: 3 : 'htmlhelp ''user\gl2_commands.htm'''
jijs_helphelp_button=: 3 : 'htmlhelp ''index.htm'''
jijs_helpindex_button=: 3 : 'htmlhelp ''index\a.htm'''
jijs_helplicense_button=: 3 : 'htmlhelp ''user\jul.htm'''
jijs_helpphrases_button=: 3 : 'htmlhelp ''phrases\contents.htm'''
jijs_helpprimer_button=: 3 : 'htmlhelp ''primer\contents.htm'''
jijs_helprelease_button=: 3 : 'htmlhelp ''user\relhigh.htm'''
jijs_helprelnotes_button=: 3 : 'htmlhelp ''release\contents.htm'''
jijs_helpuser_button=: 3 : 'htmlhelp ''user\contents.htm'''
jijs_helpvocab_button=: 3 : 'htmlhelp ''dictionary\vocabul.htm'''
jijs_helpwdcmd_button=: 3 : 'htmlhelp ''user\wd_commands.htm'''
jijs_helpwdover_button=: 3 : 'htmlhelp ''user\win_driver_cmd_ref_overview.htm'''
jijs_labadvance_button=: 3 : 'lab 0'
jijs_labauthor_button=: 3 : 'lab 2'
jijs_labchapters_button=: 3 : 'lab 1'
jijs_labs_button=: 3 : 'lab'''''
jijs_max_button=: winmax
jijs_rundebug_button=: debug
jijs_runfile_button=: runfile bind 0
jijs_runfiled_button=: runfile bind 1
jijs_runline_button=: runline
jijs_runprojman_button=: projectmanager
jijs_runpublish_button=: publish
jijs_runselection_button=: runselection
jijs_runwindow_button=: runwindow bind 0
jijs_runwindowd_button=: runwindow bind 1
jijs_save_button=: save bind 2
jijs_saveas_button=: saveas
jijs_sellower_button=: select_text bind 'lower'
jijs_selminus_button=: select_line bind 'minus'
jijs_selplus_button=: select_line bind 'plus'
jijs_selplusline1_button=: select_line bind 'plusline1'
jijs_selplusline2_button=: select_line bind 'plusline2'
jijs_selsort_button=: select_line bind 'sort'
jijs_seltoggle_button=: select_text bind 'toggle'
jijs_selupper_button=: select_text bind 'upper'
jijs_tile_button=: tile
jijs_tileacross_button=: tileacross
jijs_tilecascade_button=: tilecascade
jijs_f1_fkey=: jijs_helpvocab_button
jijs_f1ctrl_fkey=: jijs_helpcontext_button
jijs_f1shift_fkey=: jijs_helpwdover_button
jijs_actrl_fkey=: jijs_editselectall_button
jijs_bctrl_fkey=: jijs_runprojman_button
jijs_dctrl_fkey=: jijs_editinputlog_button
jijs_ectrl_fkey=: jijs_runselection_button
jijs_fctrl_fkey=: jijs_editfind_button
jijs_jctrl_fkey=: jijs_labadvance_button
jijs_kctrl_fkey=: jijs_rundebug_button
jijs_mctrl_fkey=: jijs_max_button
jijs_nctrl_fkey=: jijs_filenewijs_button
jijs_octrl_fkey=: jijs_fileopen_button
jijs_pctrl_fkey=: jijs_fileprint_button
jijs_qctrl_fkey=: jijs_forms_button
jijs_rctrl_fkey=: jijs_runline_button
jijs_sctrl_fkey=: jijs_save_button
jijs_tctrl_fkey=: jijs_runfile_button
jijs_wctrl_fkey=: jijs_runwindow_button

jijs_bctrlshift_fkey=: jijs_selminus_button
jijs_ectrlshift_fkey=: jijs_runselection_button
jijs_fctrlshift_fkey=: jijs_editfif_button
jijs_kctrlshift_fkey=: jijs_selplusline1_button
jijs_lctrlshift_fkey=: jijs_selplusline2_button
jijs_nctrlshift_fkey=: jijs_selplus_button
jijs_rctrlshift_fkey=: jijs_runline_button
jijs_tctrlshift_fkey=: jijs_runfiled_button
jijs_wctrlshift_fkey=: jijs_runwindowd_button



recent_read''