LIBRARY rexxgui
guierr = "ERROR"
guiheading = 1
guicreatewindow('NORMAL')
CALL init
CALL recent_files
CALL current_files
again:
DO FOREVER
guigetmsg()
IF EXISTS('GuiObject') == 0 THEN DO
IF EXISTS('GuiSignal') THEN DO
END
END
ELSE DO
IF EXISTS('GuiSignal') == 0 THEN DROP (guiobject)
ELSE SELECT guiobject
WHEN 0 THEN NOP
OTHERWISE
END
END
CATCH SYNTAX
CONDITION()
SIGNAL again
CATCH HALT
FINALLY
terminate:
guidestroywindow()
END
RETURN
current_files:
ERROR = guiremovectltext("RegFiles")
ERROR = guisendmsg("RegFiles", "DIR", , regdir||"*.rex")
ERROR = guiaddctltext("Regbox", regdir)
RETURN
recent_files:
LOADTEXT('old','RecentFiles.txt','B')
j=0
recfile.0=0
DO i=old.0 TO 1 BY -1
IF old.i='' THEN ITERATE
PARSE VALUE old.i WITH rfile ';' rdir
rfile=STRIP(rfile)
rdir=STRIP(rdir)
IF search(recfile.,rfile,,,'M','UPPER')>0 THEN DO
old.i=''
ITERATE
END
j=j+1
recfile.j=rfile
recdir.j=rdir
recfile.0=j
END
guiaddctltext("Recent", "Recfile")
LOADTEXT('old','RecentFiles.txt','SB')
RETURN
init:
initdir=DIRECTORY()
regdir=regread('SourceDirectory')
IF regdir='' THEN regdir=DIRECTORY()||'\'
bckdir=regread('BackupDirectory')
IF bckdir='' THEN DO
ERROR=guifile('bckdir','BROWSE|ENTRY|NEWFOLDER' , 'Intial Set up of Backup Directory',,regdir)
IF bckdir='' THEN EXIT 8
IF SUBSTR(bckdir,LENGTH(bckdir),1) \='\' THEN bckdir=bckdir||'\'
regwrite('BackupDirectory',bckdir)
END
RETURN
wm_dblclk_recent:
guigetctlvalue("Recent")
IF recent.0='' THEN RETURN
DO si=1 TO recent.0
ri=search(recfile.,recent.si,,,'M','UPPER')
IF ri<1 THEN ITERATE
CALL open(recdir.ri||recfile.ri)
END
SIGNAL terminate
RETURN
wm_dblclk_regfiles:
guigetctlvalue("Regfiles")
IF regfiles.0='' THEN RETURN
DO si=1 TO regfiles.0
CALL open(regfiles.si)
END
SIGNAL terminate
RETURN
open:
PARSE ARG ofile
IF POS('\',ofile)=0 THEN ofile=regdir||ofile
CALL archive(ofile,bckdir)
CALL addtorecent(ofile)
editopendoc(ofile,)
RETURN
wm_click_other:
file='*.rex'
ERROR = guifile('File', , 'Select REX To Open')
IF file='' | file='*.rex' THEN RETURN
CALL open(file)
SIGNAL terminate
RETURN
wm_click_clear:
old.0=0
guiaddctltext("Recent", "Old")
LOADTEXT('old','RecentFiles.txt','SB')
RETURN
wm_click_reduce:
rmax=MIN(10,recent.i)
j=rmax+1
DO i=1 TO rmax
j=j-1
old.j=recent.i
END
recent.0=rmax
old.0=rmax
guiaddctltext("Recent", "Recent")
LOADTEXT('old','RecentFiles.txt','SB')
RETURN
wm_click_cancel:
SIGNAL terminate
RETURN
wm_click_open:
rc=guigetctlvalue("Regfiles")
IF rc='' THEN DO si=1 TO regfiles.0
CALL open(regfiles.si)
END
rc=guigetctlvalue("Recent")
IF rc='' THEN DO si=1 TO recent.0
CALL open(recent.si)
END
SIGNAL terminate
RETURN
addtorecent:
PARSE ARG sfile
rc=PATH('Ffile', sfile)
file=ffile.2||ffile.3
spath=ffile.0||ffile.1
sr=search(old.,file ';',,,'M','UPPER')
IF sr>0 THEN old.sr=''
rmax=old.0+1
old.rmax=file ';' spath
old.0=rmax
LOADTEXT('old','RecentFiles.txt','SB')
RETURN
regwrite: PROCEDURE
PARSE ARG key,regval
ERROR=VALUE("OpenRex\", , "WIN32")
previous=VALUE("OpenRex\"||key, regval,"WIN32")
RETURN 0
regread: PROCEDURE
PARSE ARG key
RETURN VALUE("OpenRex\"||key, ,"WIN32")
regdel: PROCEDURE
PARSE ARG key
RETURN VALUE('',"OpenRex\"||key,"WIN32")
sd:
ERROR = guifile('File','BROWSE|ENTRY|NEWFOLDER' , 'Change Source Directory (now 'regdir')',,regdir)
IF EXISTS('file')=0 THEN RETURN
IF file \='' THEN DO
regdir=file
IF SUBSTR(regdir,LENGTH(regdir),1) \='\' THEN regdir=regdir||'\'
regwrite('SourceDirectory',regdir)
CALL current_files
END
RETURN
bd:
ERROR = guifile('File','BROWSE|ENTRY|NEWFOLDER' , 'Change Backup Directory (now 'bckdir')',,regdir)
IF EXISTS('file')=0 THEN RETURN
IF file \='' THEN DO
bckdir=file
IF SUBSTR(bckdir,LENGTH(bckdir),1) \='\' THEN bckdir=bckdir||'\'
regwrite('BackupDirectory',bckdir)
END
RETURN
sres:
regdel('SourceDirectory')
CALL init
CALL current_files
RETURN
bres:
regdel('BackupDirectory')
RETURN
help:
guisay('Help not yet defined')
RETURN
search:procedure
USE ARG stemin.,sstr,from,tohi,match,case
hi=stemin.0
IF DATATYPE(hi) \= 'NUM' THEN RETURN -1
IF ARG(1,'E')=0 THEN RETURN -1
IF ARG(2,'E')=0 THEN RETURN 0
IF ARG(3,'E')=0 THEN from=1
IF ARG(4,'E')=0 THEN tohi=hi
IF ARG(5,'E')=0 THEN match=''
IF ARG(6,'E')=0 THEN case=''
IF hi=0 THEN RETURN 0
up=TRANSLATE(case)
IF up='NO' | SUBSTR(up,1,1)='U' THEN OPTIONS 'CASELESS'
ELSE OPTIONS 'NOCASELESS'
IF TRANSLATE(match)='M' THEN DO i=from TO tohi
IF sstr=stemin.i THEN RETURN i
END
ELSE DO i=from TO tohi
IF POS(sstr,stemin.i)>0 THEN RETURN i
END
RETURN 0
archive:procedure
PARSE ARG file,backupdir,maxversion,VERSION
CALL arcinit
IF version>=maxversion THEN DO
DELETEFILE(file)
RETURN 4
END
vext='.V'RIGHT(VERSION,2,0)
newfile=ffile.2||ffile.3||vext
IF backupdir \='' THEN newfile=backupdir||newfile
IF STATE(newfile)=0 THEN CALL archive(newfile,backupdir,maxversion,version)
IF VERSION='00' THEN rc=COPYFILE(file,newfile)
ELSE rc=MOVEFILE(file,newfile)
IF rc \= '' THEN RETURN 8
RETURN 0
arcinit:
IF maxversion='' THEN maxversion=99
rc=PATH('Ffile', file,'V')
IF VERSION='' THEN DO
pref=SUBSTR(ffile.3,1,1)
VERSION=SUBSTR(ffile.3,2)
IF pref='V' & DATATYPE(version)='NUM' THEN NOP
ELSE VERSION='00'
pref='V'
END
ELSE DO
lpos=LASTPOS('.',ffile.3)
IF lpos>1 THEN ffile.3=SUBSTR(ffile.3,1,lpos-1)
VERSION=version+1
END
IF backupdir \= '' THEN IF SUBSTR(backupdir,LENGTH(backupdir),1) \='\' THEN backupdir=backupdir||'\'
RETURN
|
|