Scripts/SDDir.ijs
< Scripts
Jump to navigation
Jump to search
NB.* SDDir.ijs: Source/Destination directory specification. usuinit=: 0 : 0 load '~User/code/SDDir.ijs' NB. Assumes my own User area. coinsert_srcdest_ 'base' DEBUGON_srcdest_=: 1 NB. Display events as they happen. sd=. sddir_handler_srcdest_ <i> ) coclass 'srcdest' load 'dirbrowse logger' NB. See "Scripts/logger.ijs" DEBUGON=: 0 NB. 0 no debug, 1 debug NB. INITFL=: 'SDDir.ini',~getTempDir </i> 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>' end. if. 0>4!:0 <'DESTDIR' do. DESTDIR=: '<destination or target directory>' 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,'".' end. 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 <i> NB. Treat enter in an input field just like pressing OK. case. 'SDdestd' do. sddir_ok_button </i> case. 'SDsrcd' do. sddir_ok_button <i> case. 'brwsSrc' do. wd 'set inpBoxMsg "Enter Directory or press OK"' sddir_brwsSrc_button </i> case. 'brwsDest' do. sddir_brwsDest_button <i> case. 'cancel' do. sddir_cancel_button </i> 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,'.' end. wd 'reset' [ sddir_close <i> smoutput </i> 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,'.' end. SRCDIR=: dirbrowse_jdirbrowse_ <i> if. 0=#SRCDIR do. SRCDIR=: sv end. if. DEBUGON do. smoutput 'brwsSrc_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.' end. wd 'set SDsrcd "',SRCDIR,'"' ) sddir_brwsDest_button=: 3 : 0 sv=. DESTDIR if. DEBUGON do. smoutput 'brwsDest_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.' end. DESTDIR=: dirbrowse_jdirbrowse_ </i> if. 0=#DESTDIR do. DESTDIR=: sv end. if. DEBUGON do. smoutput 'brwsDest_button: Source dir: ',SRCDIR,'; dest dir: ',DESTDIR,'.' end. wd 'set SDdestd "',DESTDIR,'"' ) sddir_close=: 3 : 0 wd'pclose' ) sddir_cancel_button=: 3 : 0 4!:55&><&.>'SRCDIR';'DESTDIR' keepWaiting=: 0 sddir_close<i> smoutput </i> NB. Seems necessary to -> immediate execution. ) coclass 'base'