G4C   

; Dir.rep - GUI for the c:Rep replace command.


; ----------------- The window

WinBig -1 -1 400 100 'Replace in selected files'
WinType 11110001

BOX    0 0 0 0 OUT ICONDROP

; ----------------- General events

xOnLoad
setscreen dir.rep $lv_fmscreen      ; it may be on another screen.
rp_from  = ""
rp_to    = ""
rp_savemode = OVER
rp_ci = ""
guiopen Dir.rep
RUN 'resident c:Rep pure add'

xOnReload
setscreen dir.rep $lv_fmscreen
guiopen dir.rep

xOnClose
delvar rp_#?
guiquit Dir.rep
run 'resident Rep remove'

; ---------------- text-in gadgets for entering..

xTextIn   80 5  310 18 'Replace:' rp_from "" 200	; string to Rep
gadid 1
setgad dir.rep 2 on   ; activate next textin


xTextIn   80 25 310 18 'With:' rp_to "" 200		; Rep with this
gadid 2

; ---------------- Do we want to add extensions to the files ?

xCycler  10 45 190 14 "" rp_savemode
gadid 3
cstr 'OVERWRITE Files'    OVER
cstr 'Add .rep extension' EXT

; ---------------- case insensitive search ?

xCycler  200 45 190 14 "" rp_ci
gadid 6
cstr 'Case Sensitive'    ""
cstr 'Case Insensitive'  I

; ---------------- A text display, telling you what's going on.

TEXT 15 65 50 14 Status: 20 NOBOX

TEXT 80 65 310 14 Waiting.. 100 BOX
gadid 4

; ---------------- Start converting..

xButton 210 80 90 14 Start
gadid 5
rp_id  = $$LV_ID
lvmulti dir.gc $rp_id first
if $lv_file = ""
   ezreq "No files selected!" OK ''
   stop
endif
if $$LV_TYPE != FILE
   ezreq 'Directories can not\nbe converted!\n\nTry again..\n' OK ""
   stop 
endif
if $rp_from = ""
   ezreq 'No "Replace:" defined!' OK ""
   stop
endif
rp_flag = 0
rp_destfile = ""
if $rp_savemode = EXT
   extract lv_file UNQUOTE rp_fname
   appvar  rp_fname .rep
   rp_destfile = \"$rp_fname\"
endif
gosub dir.rep disable
update Dir.rep 4 'REP: $lv_file'
launch 5 'Rep $lv_file $rp_from \"$rp_to\" $rp_destfile $rp_ci'

; Use of the launch command will allow the other GUIs running on
; this instance of Gui4Cli to go about their business normally

xOnReturn 5
update Dir.rep 4 'Finished.'
lvmulti Dir.gc $rp_id OFF	; set selection off
if $rp_flag != 0  		; check abort flag
   rp_flag = 0    		; reset for next time
   gosub dir.rep enable
   stop
endif
lvmulti Dir.gc $rp_id next	; get next file
if $lv_file = ""		; no more files
   lvdir Dir.gc $rp_id refresh
   gosub dir.rep enable
   stop
endif
if $rp_savemode = EXT
   extract lv_file UNQUOTE rp_fname
   appvar  rp_fname .rep
   rp_destfile = \"$rp_fname\"
endif
update Dir.rep 4 'REP: $lv_file'
launch 5 'Rep $lv_file $rp_from \"$rp_to\" $rp_destfile $rp_ci'


; --------------- Cancel the rest of the files chosen.


xButton 300 80 90 14 Stop
setvar rp_flag 1

; --------------- Routines to disables & enable guis

xRoutine disable
guiwindow dir.gc wait
setgad dir.rep 1 off
setgad dir.rep 2 off
setgad dir.rep 3 off
setgad dir.rep 5 off
setgad dir.rep 6 off

xRoutine enable
guiwindow dir.gc resume
setgad dir.rep 1 on
setgad dir.rep 2 on
setgad dir.rep 3 on
setgad dir.rep 5 on
setgad dir.rep 6 on

xOnFail
gosub dir.rep enable








