Here is one with the following properties/shortcoming:
- only files from the current directory may be listed
- a filter on file extension may be used (empty filter "" lists all files)
- background under the selector window is untouched (using "page" mechanism)
- filenames are displayed in a scrollable list
Button are used to add "lines" to the selector page, as normal lines always are drawn on the base page.
An alternative would be to use the "sprite scan" statement to temporarely save the background under the selector window and put is back using the "sprite stamp" statement upon termination of the file selector. In that case, normal lines could be used, but all objects like buttons should have to be hidden or deleted explicitely.
Code: Select all
graphics ! graphics clear ! draw color 0,0,0
f$ = file_select$("sB files","sb",100,100,200,300,.8,.9,.6,1)
pause 1
text ! print f$
end
' paged filesector
' list files with extension ext$ from current directory
' background remains unchanged after fileselector closes
' title$ = title of the fileselector window
' ext$ = file extension filter.
' If ext$="" then all files will be selected
'
def file_select$(title$,ext$,xs,ys,ww,hh,R,G,B,alpha)
name$="dh%ur/sp"
page name$ set
page name$ frame xs,ys,ww,hh
page name$ color R,G,B,alpha
button name$&"bottom" text "" at -6,hh-3 size ww+12,3
button name$&"left" text "" at 0,-6 size 3,hh+12
button name$&"right" text "" at ww-3,-6 size 3,hh+12
button name$&"upper1" text "" at -6,0 size ww+12,3
button name$&"upper2" text "" at -6,30 size ww+12,3
button name$&"title" text title$ at 40,3 size 120,27
button name$&"cancel" text " Cancel " at 10,hh-50 size 80,40
button name$&"ok" text " OK " at ww-90,hh-50 size 80,40
dir "" list files fil$,nfiles
dim ff$(nfiles) ! nf=0
for i=0 to nfiles-1 ! f$=fil$(i) ! pos=instr(f$,".")
if pos>-1 then
e$=right$(f$,len(f$)-pos-1)
if e$=ext$ then ! nf+=1 ! ff$(nf-1)=f$ ! end if
end if
next i
if nf then
dim fil$(nf) ! for i=0 to nf-1 ! fil$(i)=ff$(i) ! next i
end if
set lists custom ! fill color R,G,B
list name$ text fil$ at 3,33 size ww-7,hh-96
page name$ show
nr=-1 ! fsel$=""
do slowdown
if bp(name$&"cancel") then ! fsel$="" ! break ! end if
nr=list_selected(name$) ! if nr=-1 then continue
if bp(name$&"ok") then ! fsel$=fil$(nr) ! break ! end if
until forever
page name$ hide ! page "" set ! return fsel$
end def
def bp(a$) = button_pressed(a$)