Some explanation of this script can be found here. NB.* SDDir.ijs: Source/Destination directory specification.
usuinit=: 0 : 0
- load '~User/code/sddir.ijs' coinsert_srcdest_ 'base' DEBUGON_srcdest_=: 1 NB. Display events as they happen.
sd=. sddir_handler_srcdest_
)
coclass 'srcdest' load 'dirbrowse logger' NB. See "Scripts/logger.ijs"
DEBUGON=: 0 NB. 0 no debug, 1 debug NB. INITFL=: 'SDDir.ini',~getTempDir NB. Keep window field values here
SDDIR=: 0 : 0 pc sddir; pn "Source and Destination Directories"; xywh 240 8 34 12;cc ok button;cn "OK"; xywh 240 23 34 12;cc cancel button;cn "Cancel";
xywh 2 6 40 12;cc inpBoxSD static;cn "Source Directory"; xywh 60 6 115 12;cc SDsrcd edit; xywh 190 6 34 12;cc brwsSrc button;cn "Browse";
xywh 2 23 60 12;cc inpBoxDD static;cn "Destination Directory"; xywh 60 23 115 12;cc SDdestd edit; xywh 190 23 34 12;cc brwsDest button;cn "Browse";
xywh 12 40 150 12;cc inpBoxMsg static;cn "Enter directories"; pas 6 6;pcenter; rem form end; )
sddir_handler=: 3 : 0
- wd SDDIR
NB. SDHWNDP=: wd 'qhwndp;' NB. Initialize entry fields here...
if. 0>4!:0 <'SRCDIR' do. SRCDIR=: '<source directory with holdings>' end. if. 0>4!:0 <'DESTDIR' do. DESTDIR=: '<destination directory for Barra portfolio files>' end.
NB. Put current values or explanatory text in the entry fields.
- wd 'set SDsrcd "',SRCDIR,'"' wd 'set SDdestd "',DESTDIR,'"' wd 'setfocus SDsrcd' wd 'pshow'
NB. Our very own event loop.
- keepWaiting=: 1 while. keepWaiting do. NB. Wait until user exits...
NB. This is the key: assign the entire queue to "wdq" and
- wdq=: wd 'wait;q'
NB. assign every variable in 1st column to its value in the 2nd column.
- ({."1 wdq)=: {:"1 wdq if. DEBUGON do.
- smoutput 'syschild is "',syschild,'"; systype is "',systype,'".'
cxl=. (<'cancel') e. systype;syschild button=. systype -: 'button' if. button do.
- select. syschild
- fcase. 'enter' do. NB. Don't think this works.
case. 'ok' do. sddir_ok_button
- fcase. 'enter' do. NB. Don't think this works.
NB. Treat enter in an input field just like pressing OK.
case. 'SDdestd' do. sddir_ok_button case. 'SDsrcd' do. sddir_ok_button case. 'brwsSrc' do.
- wd 'set inpBoxMsg "Enter Directory or press OK"'
sddir_brwsSrc_button
- wd 'set inpBoxMsg "Enter Directory or press OK"'
case. 'brwsDest' do. sddir_brwsDest_button case. 'cancel' do. sddir_cancel_button
- end.
- end.
- end.
)
sddir_ok_button=: 3 : 0 NB.* sddir_ok_button: set source and destination directory values: SRCDIR & DESTDIR. NB. ({."1 wdq)=: {:"1 wdq
- SRCDIR=: SDsrcd DESTDIR=: SDdestd NB. Destination same as source if not spec'd.
if. '<'={.DESTDIR do. DESTDIR=: SRCDIR end. NB. '<' is from original wd 'set SDdestd "',DESTDIR,'"' NB. default text. if. DEBUGON do.
- smoutput 'ok_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.'
wd 'reset' [ sddir_close smoutput NB. Seems necessary to -> immediate execution.
NB. Ensure dirs end with path separator (i.e. '/').
- ps=. PATHSEP_j_
'SRCDIR DESTDIR'=: (SRCDIR;DESTDIR),&.>(ps~:&.>{:&.>SRCDIR;DESTDIR)#&.><ps keepWaiting=: 0 SRCDIR;DESTDIR
)
sddir_brwsSrc_button=: 3 : 0
- sv=. SRCDIR if. DEBUGON do.
- smoutput 'brwsSrc_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.'
SRCDIR=: dirbrowse_jdirbrowse_ if. 0=#SRCDIR do. SRCDIR=: sv end. if. DEBUGON do.
- smoutput 'brwsSrc_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.'
)
sddir_brwsDest_button=: 3 : 0
- sv=. DESTDIR if. DEBUGON do.
- smoutput 'brwsDest_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.'
DESTDIR=: dirbrowse_jdirbrowse_ if. 0=#DESTDIR do. DESTDIR=: sv end. if. DEBUGON do.
- smoutput 'brwsDest_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.'
)
sddir_close=: 3 : 0
- wd'pclose'
)
sddir_cancel_button=: 3 : 0
4!:55&><&.>'SRCDIR';'DESTDIR' keepWaiting=: 0 sddir_close smoutput NB. Seems necessary to -> immediate execution.
)
coclass 'base'
