' B+ started 2019-08-22 restart 2020-06-24
' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
' 2019-08-23_13-25 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
' For some reason Windows won't write to a fully pathed file in my user folder???from a SHELL command
' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
' and now I can chDir anywhere!!!!
' 2019-08-23_14-25 Take Steve's Advice to use users tmp directory for temp files
' 2019-08-23_23+ Have files window working for file selection
' 2020-06-24 restart using DirEntry.h, wow looks like Steve's fix helped ALLOT! Thanks SMcNeill
' I am hitting glitches where Windows wont let me access I think. So I am offering a c enter option
' to restart at the root but this might not work cross platform.
' 2020-06-26 another fix to DirEntry.h usage add CHR$(0) to string when calling a C program. This fixed a snag
' between marka and next folder up when heading to root with .. calls.
' 2020-07-04 Use this to Kill some pesky .ogg files
' direntry.h needs to be in QB64 folder ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< IMPORTANT
_TITLE "Tiny Navigator File Name Retriever: press f to start File Selection List of current directory"
' for GetFileName$()
DIM done
, myFile$
, again$
COLOR &HFF000000, &HFFFFFFFF DO 'test our new function scnState 0
myFile$ = GetFileName$
scnState -1
PRINT "You selected: "; myFile$
INPUT "Test another File Selection (y for yes) "; again$
IF again$
<> "y" THEN done
= -1
'you might try srnState before and after calling this function to restore conditions
' uses: SUB GetLists (SearchDirectory AS STRING, DirList() AS STRING, FileList() AS STRING) for getting dirs a nd files
' uses: FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING) for display large arrays and selecting
' share these with Main Code section:
' 'for GetFileName$() and GetLists
'DIM SHARED selectedFile AS STRING
'REDIM SHARED DIRs(0) AS STRING, FILs(0) AS STRING
DIM mySelection&
, done$
, i
, t$
_TITLE "Tiny Navigator File Name Retriever: press f to start File Selection List of current directory" t$
= "Current Directory: " + _CWD$ GetLists
_CWD$, DIRs
(), FILs
() FOR i
= 0 TO UBOUND(FILs
) ' this just offers a sample listing of files mySelection& = getArrayItemNumber&(5, 5, 50, 30, DIRs())
GetFileName$ = selectedFile: done$ = "y"
GetFileName$ = "": done$ = "y" ' cancelled or error
selectedFile = ""
'put this block in main code section of your program close to top
'' direntry.h needs to be in QB64 folder
'DECLARE CUSTOMTYPE LIBRARY ".\direntry"
' FUNCTION load_dir& (s AS STRING)
' FUNCTION has_next_entry& ()
' SUB close_dir ()
' SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
'END DECLARE
DirCount = 0: FileCount = 0
length = has_next_entry
get_next_entry nam$, flags, file_size
DirCount = DirCount + 1
DirList(DirCount) = nam$
FileCount = FileCount + 1
FileList(FileCount) = nam$
'close_dir 'move to after end if might correct the multi calls problem
close_dir 'this might correct the multi calls problem
' "Escape or Red X box returns -1719 to allow a Cancel function and signal no slection."
FUNCTION getArrayItemNumber&
(locateRow
, locateColumn
, boxWidth
, boxHeight
, arr
() AS STRING) 'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
'boxWidth and boxHeight are in character units, again for locate and print at correct places.
'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
'save old settings to restore at end ofsub
maxWidth = boxWidth ' number of characters in box
maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
page = 0
hlite = 0 ' line in display ready for selection by spacebar or if no number is started, enter
clrStr$
= SPACE$(maxWidth
) 'clearing a display line
GOSUB update
' show the beginning of the array items for selection
'signal cancel selection process, exit sub with this unlikely index to signal canel
choice = -1719 'primes 7 and 8, not likely to be a select index of an array
DO 'until get a selection or demand exit
'handle the key stuff
'REDIM FILs(0) AS STRING 'hopefully this is already ready
'loadFiles FILs()
selNum& = getArrayItemNumber&(5, 60, 60, 30, FILs())
CLS 'need to signal out of file selection 'back to directory select
IF kh&
= 13 THEN 'enter pressed check if number is being entered? ELSE 'clear b$ to show some response to enter b$
= "":
GOSUB update
'clear the value that doesn't work choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
IF kh&
= 27 THEN EXIT DO 'escape clause offered to Cancel selection process IF kh&
= 32 THEN choice
= hlite
+ page
* maxHeight
+ lba
'best way to choose highlighted selection IF kh&
= 8 THEN 'backspace to edit number SELECT CASE kh&
'choosing sections of array to display and highlighted item IF (page
+ 1) * maxHeight
+ lba
<= uba
THEN page
= page
+ 1:
GOSUB update
IF (page
- 1) * maxHeight
+ lba
>= lba
THEN page
= page
- 1:
GOSUB update
page
= page
- 1: hlite
= maxHeight
- 1:
GOSUB update
hlite
= hlite
- 1:
GOSUB update
IF (hlite
+ 1) + page
* maxHeight
+ lba
<= uba
THEN 'ok to move up IF hlite
+ 1 > maxHeight
- 1 THEN page
= page
+ 1: hlite
= 0:
GOSUB update
hlite
= hlite
+ 1:
GOSUB update
page
= 0: hlite
= 0:
GOSUB update
page
= INT((uba
- lba
) / maxHeight
): hlite
= maxHeight
- 1:
GOSUB update
'handle the mouse stuff
page
= page
- 1: hlite
= maxHeight
- 1:
GOSUB update
hlite
= hlite
- 1:
GOSUB update
IF (hlite
+ 1) + page
* maxHeight
+ lba
<= uba
THEN 'ok to move up IF hlite
+ 1 > maxHeight
- 1 THEN page
= page
+ 1: hlite
= 0:
GOSUB update
hlite
= hlite
+ 1:
GOSUB update
'clear mouse clicks
choice = my + page * maxHeight + lba - 1 'select item clicked
IF my
= 0 AND (mx
<= maxWidth
AND mx
>= maxWidth
- 2) THEN 'exit sign EXIT DO 'escape plan for mouse click top right corner of display box IF (page
- 1) * maxHeight
+ lba
>= lba
THEN page
= page
- 1:
GOSUB update
ELSEIF mx
>= 1 AND mx
<= maxWidth
AND my
= maxHeight
+ 1 THEN 'page down bar clicked IF (page
+ 1) * maxHeight
+ lba
<= uba
THEN page
= page
+ 1:
GOSUB update
ELSE ' mouse over highlighting, only if mouse has moved! IF my
- 1 <> hlite
AND (my
- 1 + page
* maxHeight
+ lba
<= uba
) THEN hlite = my - 1
lastMX = mx: lastMY = my
getArrayItemNumber& = choice
'clear key presses
'clear mouse clicks
update: '--------------- display of array sections and controls on screen
'fix hlite if it has dropped below last array item
WHILE hlite
+ page
* maxHeight
+ lba
> uba
hlite = hlite - 1
'main display of array items at page * maxHeight (lines high)
FOR row
= 0 TO maxHeight
- 1 IF hlite
= row
THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255) index = row + page * maxHeight + lba
LOCATE locateRow
+ row
, locateColumn
'make page up and down bars to click, print PgUp / PgDn if available
'make exit sign for mouse click
LOCATE locateRow
- 1, locateColumn
+ maxWidth
- 3
'if a number selection has been started show it's build = b$
LOCATE locateRow
+ maxHeight
, locateColumn
+ maxWidth
- LEN(b$
) - 1
' for saving and restoring screen settins
COLOR DefaultColor
, BackGroundColor