G4C   - Rep.gc - Gui4Cli GUI for the Rep replace command.


; This is a GUI script for the "Replace" command.
; It needs an other program I've written, called Gui4Cli (V2.1+)
; This program is a GUI runner and is available on Aminet under 
; Dev/Gui/Gui4Cli.lha - and it's *very* good :)

; With this GUI the replace command becomes very usefull
; having the ability to easily change the same string in multiple
; files, with extreme ease..

; You run it by clicking on it's icon, or typing from the CLI
; > run c:Gui rep.gc


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

WinBig -1 -1 400 165 'Replace - SYS:'
WinType 11110001  ; it's resizable & font sensitive with all gadgets

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

xOnLoad
setvar rp_from ""
setvar rp_to ""
setvar rp_todir ""
setvar rp_ci ""
guiopen rep.gc
;RUN 'resident c:Rep pure add'

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

; ---------------- The directory listview for choosing files to convert

xListview   0 0 200 165 "" rp_file SYS: 10 DIR
GadID 1
lvdirhook 1
GadFont topaz.font 8 000	; change the font if you like..

xlvdirhook 1
setvar rp_curdir $$LV_DIR
setwintitle rep.gc '$rp_curdir                              '

; ---------------- move about buttons for the dir listview

xButton  210 5 30 15 P
lvdir rep.gc 1 parent

xButton  240 5 30 15 D
lvdir rep.gc 1 disks

xButton  270 5 30 15 A
lvdir rep.gc 1 all

xButton  300 5 30 15 N
lvdir rep.gc 1 none

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

xTextIn   210 35 180 16 From: rp_from "" 100		; string to Rep
GadTitle ABOVE

xTextIn   210 65 180 16 To: rp_to "" 100		; Rep with this
GadTitle ABOVE

; --- Dir to save file in. If this is the same dir as the file being
; --- converted, then the file will be overwriten.

xTextIn   210 95 180 16 "Save dir:" rp_todir "" 100
GadTitle ABOVE


; ---------------- Case insensitive switch

xCycler   210 115 180 14 "" rp_ci
cstr "Case Sensitive"   ""
cstr "Case Insensitive" I

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

TEXT 210 130 180 14 Waiting.. 100 BOX
gadid 2

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

xButton 210 145 90 14 Start
lvmulti rep.gc 1 first
if $rp_file = ""
   stop
endif
if $rp_from = ""
   ezreq 'No "From" defined!' OK ""
   stop
endif
if $rp_to = ""
   ezreq 'No "To" defined!' OK ""
   stop
endif
setvar rp_flag 0
setvar rp_destfile ""
if $rp_todir > " "
   extract rp_file FILE rp_fname
   setvar  rp_dest $rp_todir
   joinfile $rp_dest $rp_fname rp_destfile
endif
update rep.gc 2 '$rp_file'
launch 5 'rad:Rep $rp_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 rep.gc 2 'OK - $rp_file'
lvmulti rep.gc 1 OFF
if $rp_flag != 0
   stop
endif
lvmulti rep.gc 1 next
if $rp_file = ""
   lvdir rep.gc 1 refresh
   stop
endif
if $rp_todir > " "
   extract rp_file FILE rp_fname
   setvar  rp_dest $rp_todir
   joinfile $rp_dest $rp_fname rp_destfile
endif
update rep.gc 2 '$rp_file'
launch 5 'rad:Rep $rp_file $rp_from $rp_to $rp_destfile $rp_ci'


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


xButton 300 145 90 14 Stop
setvar rp_flag 1


