G4C

; FILEREQ.GC
; A multiselect File Requester with Favourites etc..

; GuiLoad guis:tools/filereq.gc  GuiName Routine Path FavFile  -or
; GuiOpen filereq.gc  GuiName Routine Path FavFile

; GuiName  - Name of your gui
; Routine  - Routine in your gui that will be called
; Path     - (optional) path to open at - if you want..
; FavFile  - (optional) name of the Favourites file

; ====================================================================

;               Globals

; ====================================================================

WINBIG 185 16 291 213 'Choose file(s) :'
WinType 11110001
varpath ''

BOX 0 0 0 0 in icondrop


; ====================================================================

;               System events

; ====================================================================

xONLOAD  gui routine path favfile 
guiopen $gui $routine $path $favfile

xONRELOAD  gui routine path favfile 
guiopen $gui $routine $path $favfile


XONOPEN  gui routine path favfile 
setgad filereq.gc 52/53 off
if $path > ''
   lvuse filereq.gc 1
   LVDir '#$path'
   update filereq.gc 2 $$lv.dir      
endif
if $favfile = ""
   favfile = guis:tools/fav/default
endif


xOnRMB
if $mode = FAV
   setgad filereq.gc 52/53 off
   setgad filereq.gc 2/16 on
   setgad filereq.gc 50/51 on
   lvuse filereq.gc 1
   lvmode DIR
   lvdir #$$lv.dir
else
   status
endif


; ====================================================================

;               The Listview

; ====================================================================

XLISTVIEW 9 5 213 190 "" filename "" 10 DIR
GADID 1
GADFONT #mono 8 000
if $mode = FAV
   setgad filereq.gc 52/53 off
   setgad filereq.gc 2/16 on
   setgad filereq.gc 50/51 on
   mode = ''
   lvmode DIR
   lvdir #$filename
else
   guiclose filereq.gc
   gosub $gui $routine $filereq.gc/filename  ; Give FULL variable path!
endif


; directory hook
xlvdirhook 1
update filereq.gc 2 $filename       


; single click hook
xlvhook 1
update filereq.gc 2 $filename


XTEXTIN 9 194 273 14 "" txtfile "" 100
GADID 2
gadhelp 'Shows file chosen - Change the name & hit enter, to Rename it'
ifexists file $txtfile
   guiclose filereq.gc
   gosub $gui $routine $filereq.gc/filename
else
   ezreq 'Rename $filename\nto $txtfile ?' Rename|CANCEL choice
   if $choice = 1
      rename $filename $txtfile
      lvuse filereq.gc 1
      lvdir refresh
   endif
endif


; ====================================================================

;               Listview control buttons

; ====================================================================

XBUTTON 224 5 58 14 "Parent"
gadid 10
gadhelp 'CD to Parent of current dir'
lvuse filereq.gc 1
LVDir parent
update filereq.gc 2 $$lv.dir      


XBUTTON 224 19 58 14 "Root"
gadid 11
gadhelp 'CD to Root of current dir'
lvuse filereq.gc 1
LVDir root
update filereq.gc 2 $$lv.dir      


XBUTTON 224 33 58 14 "Disks"
gadid 12
gadhelp 'Show device list'
lvuse filereq.gc 1
LVDir disks
update filereq.gc 2 $$lv.dir      


XBUTTON 224 47 58 14 "All"
gadid 13
gadhelp 'Select all items'
lvuse filereq.gc 1
LVDir all
update filereq.gc 2 $$lv.dir      


XBUTTON 224 61 58 14 "None"
gadid 14
gadhelp 'Unselect all items'
lvuse filereq.gc 1
LVDir none
update filereq.gc 2 $$lv.dir      

; ====================================================================

;               Copy & delete

; ====================================================================

XBUTTON 224 92 58 14 "Copy"
gadid 14
gadhelp 'Copy selected files (destination chosen through requester)'
dest = ''
ReqFile -1 -1 300 -40 'Choose destination:' DIR dest ''
if $dest > ' '
   lvuse filereq.gc 1
   lvaction copy $dest
endif

XBUTTON 224 78 58 14 "Delete"
gadid 14
gadhelp 'Delete selected files'
lvuse filereq.gc 1
lvaction delete REQ


; ====================================================================

;               Favourites control

; ====================================================================

XBUTTON 224 110 58 14 "Fav"
gadid 50
gadhelp 'Shows Favourites listing ($favfile\)'
setgad filereq.gc 2/16 off
setgad filereq.gc 50/51 off
setgad filereq.gc 52/53 on
lvuse filereq.gc 1
lvmode MULTI
lvchange $favfile
lvsort asc
mode = FAV


XBUTTON 224 124 29 14 "+"       ; add to favourites
gadid 51                        ; create file if it doesn't exist
gadhelp 'Add current dir to Favourites'
ifexists file $favfile
   ; ok
else
   .dummy = 'GUIs:'             ; got to have this one :)
   copy env:.dummy $favfile
endif
lvuse filereq.gc 1
append $favfile '\n$$lv.dir'


XBUTTON 253 124 29 14 "-"     ; delete from favourites
gadid 52
gadhelp 'Deleted selected favourites entries'
lvuse filereq.gc 1
lvmulti first
while $filename > ''
    lvdel -1
    lvmulti first      ; since we deleted the old 1st one
endwhile


XBUTTON 224 138 58 14 "Save"  ; save favourites
gadid 53
gadhelp 'Save Favourites as $favfile'
lvuse filereq.gc 1
lvsave $favfile

; ====================================================================

;               OK & Cancel

; ====================================================================

XBUTTON 224 157 58 19 "OK"
gadid 15
gadhelp 'Selected files will be sent to calling gui'
guiclose filereq.gc
lvuse filereq.gc 1
lvmulti first
while $filename > ''
   gosub $gui $routine $filereq.gc/filename
   lvmulti off
   lvmulti next
endwhile

XBUTTON 224 176 58 17 "Cancel"
gadid 16
guiclose filereq.gc



