A simple tool made with the 'appealling' window9.bi library .
Listbox 1 : list of dirs and files . the file name , if selected , is copied to the clipboard as #Include "file.bi"
Listbox2 : view of the file just selected in lbox1 . When selected , a line is copied to the clipboard .
enjoy
Code: Select all
' BiFiles by enform 11/2017 Freeware , free code
#Include Once "window9.bi"
Type w0
As HWND hwnd_0
Declare Function OpenWindow_0() As HWND
Declare Sub Sub_Load_bi(sFile As String,sMainDir As String)
Declare Sub Sub_LBClicked11(sMainDir As String) ' ListBox :
Declare Sub ExamDir(sDirectory As String,lDirNb As Long)
End Type
Dim win0 As w0
Dim As String sMainDir
Function w0.OpenWindow_0() As HWND
hwnd_0 = OpenWindow("Bi-Files Reader by enform 11/2017",15,36,940,680)
WindowColor(hwnd_0,BGR(20,150,170))
SetGadgetFont(,CInt(LoadFont("Courier New",9)))
WindowBounds(hwnd_0,940,675,940,675)
' icon made with junior iconedit freeware
Var HIMAGE = Load_icon(ExePath + "\bi.ico")
SendMessage(hwnd_0,WM_SETICON,ICON_BIG,Cast(LPARAM,HIMAGE))
ListBoxGadget(1,220,5,695,650)
SetGadgetColor(1,BGR(220,220,250),BGR(0,0,0),3)
'SetGadgetFont(1,CInt(LoadFont("Tahoma",9)))
SendMessage(GadgetID(1),LB_SETHORIZONTALEXTENT,1900,0)
ListBoxGadget(2,10,5,200,650) ' on left
SetGadgetColor(2,BGR(220,220,200),BGR(0,0,0),3)
'SetGadgetFont(2,CInt(LoadFont("Tahoma",9)))
SendMessage(GadgetID(2),LB_SETHORIZONTALEXTENT,600,0)
Return hwnd_0
End Function
Sub w0.Sub_Load_bi(sFile As String,sMainDir As String) ' Load selected file
Dim As String sFileName,sSt,sItm,sDir
Dim As Long file_num,lItm,lDir
If Left(sFile,3) = " " Then ' file in a dir
lItm = GetItemListBox(2)
Do
lItm -= 1 : If lItm < 1 Then Exit Do
sItm = GetListBoxText(2,lItm)
lDir = InStr(LCase(sItm),"dir ---") ' the title
If lDir Then
sDir = GetListBoxText(2,lItm-1) ' real path + file
Exit Do
EndIf
Loop
sFileName = Trim(sDir)+Trim(sFile)
Else ' root of /inc
sFileName = sMainDir + Trim(sFile)
EndIf
If sFileName <> "" Then
file_num = FreeFile( )
If( Open((sFileName) For Input As #file_num ) )= 0 Then
HideGadget(1,1)
ResetAllListBox(1)
Do Until EOF( file_num )
Line Input #file_num ,sSt
AddListboxItem(1,sSt)
Loop
HideGadget(1,0)
Else
MessBox("","Problem with the file")
EndIf
Close #file_num
EndIf
End Sub
Sub w0.Sub_LBClicked11(sMainDir As String) ' ListBox on left
Dim As String sItm,sClip
sItm = GetListBoxText(2,GetItemListBox(2))
If sItm <> "" And Len(sItm) < 50 And InStr(LCase(sItm),"dir ---") =0 Then
sClip = GetListBoxText(2,GetItemListBox(2))
SetClipBoardText("#Include """+sClip+"""")
Sub_Load_bi(sItm,sMainDir)
EndIf
End Sub
Sub w0.ExamDir(sDirectory As String,lDirNb As Long)
Dim As String sDirname
Dim As Long lDir,lSlash1,lSlash2
lDir = ExamineDirectory (sDirectory,"*.*")
Do
If DirectoryEntryAttributes (lDir) And FILE_ATTRIBUTE_DIRECTORY Then
sDirname = DirectoryEntryName (lDir)
If Left(sDirname,1) <> "." And Left(sDirname,2) <> ".." Then
If Right(sDirname, 1) <> "\" Then sDirname &= "\"
AddListBoxItem(2,Space(30)+sDirectory+sDirname) ' complete path
lSlash1 = InStr(sDirectory,"\inc") +5 ' main dir
lSlash2 = InStr(lSlash1,sDirectory,"\")' sub dir or sub/sub... dir
If lSlash2 = 0 Then
AddListBoxItem(2,"DIR --- "+DirectoryEntryName(lDir) + " ---")
Else
AddListBoxItem(2,"dir --- "+DirectoryEntryName(lDir) + " ---")
EndIf
lDirNb += 1
ExamDir(sDirectory+sDirname,lDirNb) ' recursive
lDirNb = 0
EndIf
ElseIf DirectoryEntryAttributes (lDir) And FILE_ATTRIBUTE_NORMAL Then
If lDirNb = 0 Then
AddListBoxItem(2,DirectoryEntryName(lDir)) ' root level
Else
AddListBoxItem(2," "+DirectoryEntryName(lDir)) ' dir level
EndIf
EndIf
Loop While NextDirectoryEntry (lDir)
FinishDirectory (lDir)
End Sub
sMainDir = "c:\FreeBASIC-1.05.0-win32\inc\" ' <-- change the path
win0.hwnd_0 = win0.OpenWindow_0()
HideGadget(1,1)
win0.ExamDir(sMainDir,0)
HideGadget(1,0)
Do
Var event = WaitEvent
Select Case event
Case EventClose
Exit Do ' End
Case EventGadget
Select Case EventNumber
Case 1 ' ListBox copy selected line to clipboard
Var sClip = GetListBoxText(1,GetItemListBox(1))
Var lClip = Len(sClip) - 8
If InStr(LCase(sClip),"declare ") Then
SetClipBoardText(Right(sClip,lClip))
Else
SetClipBoardText(sClip)
EndIf
Case 2 ' ListBox
win0.Sub_LBClicked11(sMainDir)
End Select
End Select
Loop
'