Post by tsh73 on Apr 21, 2021 10:06:17 GMT
Folder Dialog (select a folder) reworked
used ideas from UncleBen's, FreeFormJ, xxxgeek's
* single click/double click logic from UncleBen's version
' while in a folder, you can change last folder in a path with single click
' double click to drill down
' double click on (..) to move up
' it was supposed that second single click acts as double click. But it feels inconsistent.
* bigger text (well, xxxgeek version beats me with it)
* removed button for going up, added upper line ".." for going to parent folder,
' personal choice from old DOS days I guess
' well, it is not exactly dots - dots are visible only in Bold text - but looks close
* wider (paths are long, and new button takes space)
' sometimes paths are still longer then bottom part (especially id started from Desktop etc)
' but in dire need you can scroll (and making wider lessens that need)
* make it start with given folder
' so you don't always have to start from c:\
' with caveat - it does not check that folder exist.
' I can try to check for folder with mkdir() (183 == folder already exists), but it will not work on say CD-ROM
* add "Make New Folder" button
' actually now it works so real I want to delete folder/remove folder as well. But I'll abstain ;)
* allows to enter folder by Ctrl-V
' (well, it already does this in all other versions)
' caveat: if you start with existing path and select folders by (double)clicks, you'll get existing folder
' but if you Ctrl-V "Secret Santa Base" and press Enter - function will return what you said.
There could be bugs, but all I found so far I shot.
Screenshots!
used ideas from UncleBen's, FreeFormJ, xxxgeek's
* single click/double click logic from UncleBen's version
' while in a folder, you can change last folder in a path with single click
' double click to drill down
' double click on (..) to move up
' it was supposed that second single click acts as double click. But it feels inconsistent.
* bigger text (well, xxxgeek version beats me with it)
* removed button for going up, added upper line ".." for going to parent folder,
' personal choice from old DOS days I guess
' well, it is not exactly dots - dots are visible only in Bold text - but looks close
* wider (paths are long, and new button takes space)
' sometimes paths are still longer then bottom part (especially id started from Desktop etc)
' but in dire need you can scroll (and making wider lessens that need)
* make it start with given folder
' so you don't always have to start from c:\
' with caveat - it does not check that folder exist.
' I can try to check for folder with mkdir() (183 == folder already exists), but it will not work on say CD-ROM
* add "Make New Folder" button
' actually now it works so real I want to delete folder/remove folder as well. But I'll abstain ;)
* allows to enter folder by Ctrl-V
' (well, it already does this in all other versions)
' caveat: if you start with existing path and select folders by (double)clicks, you'll get existing folder
' but if you Ctrl-V "Secret Santa Base" and press Enter - function will return what you said.
There could be bugs, but all I found so far I shot.
Screenshots!
'new ver of FolderDialog
' tsh73 April 2021
'v.1.00 2021 04 21
'based on
'JBFolderdialog by UncleBen (nice single/double click, uses upper line for back action)
'to do:
'(+) bigger text
'(+) change upper line to ".."
' ~~ , not exactly dots - they are visible only in Bold text
'(+) wider (paths are long, and new button takes space)
'(+) make it start with given folder
'(+) add "Make New Folder" button
'(~) allow to enter folder by Ctrl-V (well, it does this already)
dim info$(1,1)
dim FolderDlg$(10)
'old way: start with drive list
'print ">";FolderDialog$("");"<"
'new way: start with some folder (pre-saved, or DefaultDir$)
print ">";FolderDialog$(DefaultDir$);"<"
'print ">";FolderDialog$("C:\progs\Just BASIC v1.01\");"<"
' if path does not exist you can move up until part that exist (or drive list)
'print ">";FolderDialog$("y:\does\not\exists\");"<"
'print "press a key"
'dummy$ = input$(1)
print "press Enter to finish"
input "";dummy$
print "*finished*"
end
function FolderDialog$(startPath$)
level = 1
'basePath$
path$= startPath$
folder$ = ""
doubleClick = 0
backChars$="••" 'ok for normal font?
'backChars$=".." 'nice with bold
'backChars$="<-" 'original UncleBen's code
'backChars$="<=" '
call ReadDrives
if path$<>"" then
if right$(path$, 1)<>"\" then path$=path$+"\"
for i = 1 to len(path$)
if mid$(path$,i,1)="\" then level = level+1
next
call ListFolders path$, backChars$
end if
WindowWidth = 450
WindowHeight = 350
button #folderdlg.default, "OK", [FolderOk], UL, 260, 290, 80, 25
button #folderdlg, "Cancel", [FolderCancel], UL, 350, 290, 80, 25
button #folderdlg.mkNew, "Make New Folder", [FoldermkNew], UL, 10, 290, 150, 25
listbox #folderdlg.lb, FolderDlg$(, [DblSelectFolder], 10, 10, 420, 240
textbox #folderdlg.tb, 10, 260, 420, 25
open "Browse For Folder" for dialog_modal as #folderdlg
#folderdlg "font 10" 'bigger font
'#folderdlg "font 10 bold" 'even bolder
#folderdlg, "trapclose [FolderCancel]"
#folderdlg.lb, "singleclickselect [SelectFolder]"
#folderdlg.tb, path$; folder$
wait
[DblSelectFolder]
#folderdlg.lb, "selection? a$"
if a$ = "" then wait
'print "dbl", a$, level, path$, folder$
if a$ = backChars$ then
level = level-1
folder$ = word$(path$, level, "\")
path$ = left$(path$, len(path$)-len(folder$)-1)
folder$ = folder$; "\"
if level = 1 then
call ReadDrives
#folderdlg.lb, "reload"
else
call ListFolders path$, backChars$
#folderdlg.lb, "reload"
end if
#folderdlg.lb, "select "; left$(folder$, len(folder$)-1)
lastA$ = "" 'prevent instant return on next upper click
#folderdlg.tb, path$; folder$
else
level = level+1
path$ = path$; a$; "\"
folder$ = ""
call ListFolders path$, backChars$
#folderdlg.lb, "reload"
#folderdlg.lb, "selectindex 0"
#folderdlg.tb, path$; folder$
end if
'print "dbl>", a$, level, path$, folder$
wait
[SelectFolder]
#folderdlg.lb, "selection? a$"
if a$ = "" then wait
'print "sngl", a$, level, path$, folder$
if lastA$=a$ then [DblSelectFolder] 'double (second) Click
if a$ = backChars$ then
folder$ = ""
else
folder$ = a$; "\"
end if
#folderdlg.tb, path$; folder$
lastA$=a$
'print "sngl>", a$, level, path$, folder$
wait
[FoldermkNew]
new$="NewFolder"
prompt "New folder"+chr$(13)+"Create new folder";new$
if new$="" then wait 'Cancelled
result = mkdir(path$;new$ )
select case result
case 267: notice "Failed to create folder";chr$(13);"Bad name"
case 183: notice "Failed to create folder";chr$(13);"Name already exists"
case 123: notice "Failed to create folder";chr$(13);"Name syntax is incorrect"
case 21: notice "Failed to create folder";chr$(13);"Device not exist"
case 2: notice "Failed to create folder";chr$(13);"File not found"
case 3: notice "Failed to create folder";chr$(13);"Path not found"
case 5: notice "Failed to create folder";chr$(13);"Access denied"
case 0
call ListFolders path$, backChars$
#folderdlg.lb, "reload"
#folderdlg.lb, "select "; new$
a$=new$
case else: notice "Failed to create folder";chr$(13);"Error ";result
end select
wait
[FolderOk]
#folderdlg.tb, "!contents? FolderDialog$"
close #folderdlg
exit function
[FolderCancel]
close #folderdlg
end function
sub ReadDrives
while word$(Drives$, c+1) <> ""
c = c+1
wend
redim FolderDlg$(c)
for i = 1 to c
FolderDlg$(i) = word$(Drives$, i)
next i
end sub
sub ListFolders path$, backChars$
files path$, "*.*", info$(
n = val(info$(0,0))
q = val(info$(0,1))
redim FolderDlg$(q+1)
FolderDlg$(1) = backChars$
for i = 1 to q
FolderDlg$(i+1) = info$(n+i, 1)
next i
'#folderdlg.lb, "reload"
end sub