'==============
'FILESELECT.BAS
'==============
'Simple file selector box. Coded by Dav, FEB/2021
'(with the kind help of the QB64.org forum gurus)
'Navigate through directories and select a file.
'Use arrows, page up/down, home, end to scroll list.
'Press enter to select highlighted file or enter the dir.
'things to do: auto center box on screen, and ditch x/y input?
' ...will need to adjust box size based on file/dir chr length
' Add user defined colors instead...?
'=== draw stuff
a$ = FileSelect$(5, 10, 15, 55, "*.*")
PRINT "You selected: "; a$
FUNCTION FileSelect$
(y
, x
, y2
, x2
, Filespec$
)
'=== save original place of cursor
'=== save colors
'=== Save whole screen
_MEMCOPY scr1
, scr1.OFFSET
, scr1.SIZE
TO scr2
, scr2.OFFSET
loadagain:
top = 0
selection = 0
'get list...
REDIM FileNames$
(5000) 'space for 5000 filenames
'only show the ".." if not at root dir
FileNames$(0) = ".."
LineCount = 1
LineCount = 0
FileNames$(LineCount) = "[" + rl$ + "]"
LineCount = LineCount + 1
'KILL "$_TeMP_FILE_LIST"
SHELL _HIDE "dir /b /A:-D " + Filespec$
+ " > $_TeMP_FILE_LIST"
'skip the temp file...
IF rl$
<> "$_TeMP_FILE_LIST" THEN FileNames$(LineCount) = rl$
LineCount = LineCount + 1
'KILL "$_TeMP_FILE_LIST"
'draw a box
'show current working dir
'Shorten it is too long, for display purposes
CurDir$
= MID$(CurDir$
, 1, x2
- x
- 3) + "..."
'directories get a different color...
IF selection
> 0 THEN selection
= selection
- 1 IF selection
< top
THEN top
= selection
IF selection
< (LineCount
- 1) THEN selection
= selection
+ 1 IF selection
> (top
+ (y2
- 2)) THEN top
= selection
- y2
+ 1 top = top - y2
selection = selection - y2
IF selection
< 0 THEN selection
= 0 top = top + y2
selection = selection + y2
IF top
>= LineCount
- y2
THEN top
= LineCount
- y2
IF selection
>= LineCount
THEN selection
= LineCount
- 1 top = 0: selection = 0
selection = LineCount - 1
top = selection - y2 + 1
FileSelect$ = ""
'go up one dir
'see if directory
test$
= RTRIM$(FileNames$
(selection
)) test$
= MID$(test$
, 2, LEN(test$
) - 2) FileSelect$
= C$
+ RTRIM$(FileNames$
(selection
))
'=== Restore the whole screen
_MEMCOPY scr2
, scr2.OFFSET
, scr2.SIZE
TO scr1
, scr1.OFFSET
'=== restore original y,x