BiFiles : FB bi files browser/viewer

User projects written in or related to FreeBASIC.
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

BiFiles : FB bi files browser/viewer

Postby enform » Nov 12, 2017 22:02

Hi,
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
'

lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: BiFiles : FB bi files browser/viewer

Postby lizard » Nov 12, 2017 23:39

With fltk-c it would be only two lines:

Code: Select all

#include once "fltk-c.bi"
dim file as zstring ptr = flFileChooser("select a file","*.bas", ExePath(), 1)


https://imgur.com/a/vTNdb

Works in both, win and linux. :-)
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

Re: BiFiles : FB bi files browser/viewer

Postby enform » Nov 13, 2017 11:15

2 years ago , i'have been working on a Gui code translator from Fltk Fluid to fltk-c FB with good results but with no success on our forum .
Coded with fltk-c.bi , interesting to study .

Maybe FLTK is more simple in the flFileChooser case , but in general , window9 is very easy to manage.
And Linux ... not on my new PC .

bcohio ,3 years of work , do you know fltk ? ;-)
your 033 & 099 zip files looks like 'damaged' here when i try to unzip.
I don't explore all the forum/projects when i need a simple tool ... DIY is not a bad idea , no ?..
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: BiFiles : FB bi files browser/viewer

Postby lizard » Nov 13, 2017 11:35

To be honest, flFileChooser shows only a preview, not the whole textfile. Windows9 ist good too, i have tried a little. Each library has its drawbacks. The big advantage of fltk-c is it has so much examples. Makes it easy to create something out of it.

And linux becomes better and better. Still often the problems with the drivers. But with Kubuntu one has all he needs (except games). Once you are familiar with it, some things are better. Almost no problems with viruses and spyware. Much less harddrive activity. Have you noticed, win makes about 10 times more! And the HD is often the first to become broken. With a dual boot i can visit win 10 whenever i want.
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

Re: BiFiles : FB bi files browser/viewer

Postby enform » Nov 13, 2017 15:17

To be honest, win 10 is not my first choice as OS ... if it is for free , there is a good reason , like Android .
And maybe i will return back to fltk-c one of theses days ...
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: BiFiles : FB bi files browser/viewer

Postby lizard » Nov 13, 2017 15:22

What is your first choice as OS?
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

Re: BiFiles : FB bi files browser/viewer

Postby enform » Nov 13, 2017 17:56

This summer , i bought a second-hand PC with w7 pro installed , it's a good version .
I removed a 'nb' of KB.... known to collect datas , and i hope ...
No , i don't like personal ' data collection' , private is private .

Using Firefox with NoScript and looking at the running ip's , i have been surprised to see ( just after launching ) adresses like
Amazo... and other ip's like that . I went to Noscript Options and removed a lot of 'authorized by default' ip's ;
also in about:config , searching for Amaz... or Goo... , i found several places .

In w7 settings , removed all data collection for a 'better experience' , reports ...
Well , it is not the thread for that :-)
greetings
MrSwiss
Posts: 3127
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: BiFiles : FB bi files browser/viewer

Postby MrSwiss » Nov 13, 2017 18:18

lizard wrote:Windows9 ist good too, i have tried a little. Each library has its drawbacks.
Well, Windows9's drawback is: 32bit, only (not a bright future, therefore).
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: BiFiles : FB bi files browser/viewer

Postby lizard » Nov 13, 2017 20:18

MrSwiss wrote:
lizard wrote:Windows9 ist good too, i have tried a little. Each library has its drawbacks.
Well, Windows9's drawback is: 32bit, only (not a bright future, therefore).


Same with wx-c. Thats one further advantage of fltk-c, Works in all, 32, 64, win, linux and mac i believe.
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

Re: BiFiles : FB bi files browser/viewer

Postby enform » Nov 13, 2017 23:13

window9 32bits : what are the difficulties for a 64 bits modif.
my w7 is 64b , i'm running fb32 bits , no pb .
MrSwiss
Posts: 3127
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: BiFiles : FB bi files browser/viewer

Postby MrSwiss » Nov 13, 2017 23:31

enform wrote:my w7 is 64b , i'm running fb32 bits , no pb .
Of course not, I'm referring to: FBC 64bit.
enform wrote:what are the difficulties for a 64 bits modif.
You'll have to ask VANYA, the author, of the lib.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: BiFiles : FB bi files browser/viewer

Postby lizard » Nov 14, 2017 0:08

enform wrote:window9 32bits : what are the difficulties for a 64 bits modif.
my w7 is 64b , i'm running fb32 bits , no pb .


One can run 32 on 64, but not 64 on 32. So at the moment it would be best to do everything with 32, i think. With the option to switch to 64 in the near future. I personally want to have my project in 6 versions: win, linux and mac, each with 32 and 64. With freebasic and fltk-c it seems possible.
bcohio2001
Posts: 524
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: BiFiles : FB bi files browser/viewer

Postby bcohio2001 » Nov 15, 2017 5:40

enform wrote:bcohio ,3 years of work , do you know fltk ? ;-)
your 033 & 099 zip files looks like 'damaged' here when i try to unzip.
I don't explore all the forum/projects when i need a simple tool ... DIY is not a bad idea , no ?..

If you look at the first post, I mention that this is a deviation off another "Project".
That one started in October of 2008. So is over nine years. (Subtract a year or two for off time.)

I have not used FLTK at all. Just needed a large library for testing.

I will look into that about the files. Would rather "git" them over to GitHub or SourceForge. (SORRY FOR THE PUN)
But I am on Win10 and most of the tutorials and YouTube videos are using Linux.

Return to “Projects”

Who is online

Users browsing this forum: Bing [Bot] and 6 guests