Page 1 of 1

Building a TTreeView with all folders and files

PostPosted: Mon Feb 04, 2019 12:30 pm
by Antonio Linares
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg SIZE 300, 600

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT BuildTree( oDlg )

return nil

function BuildTree( oDlg )

   local oTreeView := TTreeView():New( 0, 0, oDlg )
   local cPath := "c:\harbour\*"

   oDlg:SetText( cPath )
   oTreeView:SetSize( oDlg:nWidth - 6, oDlg:nHeight - 30 )
   oTreeView:bChanged = { || MsgBeep() }

   ReadFiles( cPath, oTreeView )

return nil

function ReadFiles( cPath, oTreeView )

   local aFiles := Directory( cPath, "D" )
   local oTreeItem, n
   
   for n = 1 to Len( aFiles )
      if aFiles[ n ][ 1 ] != "." .and. aFiles[ n ][ 1 ] != ".."
         oTreeItem = oTreeView:Add( aFiles[ n ][ 1 ] )
         if aFiles[ n ][ 5 ] == "D"
            ReadFiles( SubStr( cPath, 1, RAt( "\", cPath ) ) + aFiles[ n ][ 1 ] + "\*", oTreeItem )
         endif
      endif  
   next

return nil


Image

Re: Building a TTreeView with all folders and files

PostPosted: Mon Feb 04, 2019 4:17 pm
by Antonio Linares
Using an ImageList for the items:

elixir.prg
Code: Select all  Expand view
#include "FiveWin.ch"

static oImageList

function Main()

   local oDlg

   DEFINE DIALOG oDlg SIZE 300, 600

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT BuildTree( oDlg )

   oImageList:End()

return nil

function BuildTree( oDlg )

   local oTreeView := TTreeView():New( 0, 0, oDlg )
   local cPath := "c:\harbour\*"
   
   oImageList := TImageList():New()

   oDlg:SetText( cPath )
   oTreeView:SetSize( oDlg:nWidth - 6, oDlg:nHeight - 30 )
   oTreeView:bChanged = { || MsgBeep() }
   
   oImageList:Add( TBitmap():Define( "folder",,  oDlg ),;
                   TBitmap():Define( "fldmask",, oDlg ) )  
   oImageList:Add( TBitmap():Define( "prg",,  oDlg ),;
                   TBitmap():Define( "prgMask",,  oDlg ) )
   oTreeView:SetImageList( oImageList )

   ReadFiles( cPath, oTreeView )

return nil

function ReadFiles( cPath, oTreeView )

   local aFiles := Directory( cPath, "D" )
   local oTreeItem, n
   
   for n = 1 to Len( aFiles )
      if aFiles[ n ][ 1 ] != "." .and. aFiles[ n ][ 1 ] != ".."
         oTreeItem = oTreeView:Add( aFiles[ n ][ 1 ], If( aFiles[ n ][ 5 ] == "D", 0, 1 ) )
         if aFiles[ n ][ 5 ] == "D"
            ReadFiles( SubStr( cPath, 1, RAt( "\", cPath ) ) + aFiles[ n ][ 1 ] + "\*", oTreeItem )
         endif
      endif  
   next

return nil


elixir.rc
Code: Select all  Expand view
#ifndef __64__
  1 24 "WinXP/WindowsXP.Manifest"
#endif

background BITMAP .\..\bitmaps\backgrnd\iosbg.bmp

New      BITMAP "../bitmaps/32x32/new.bmp"
New2     BITMAP "../bitmaps/16x16/new.bmp"
Dialog   BITMAP "../bitmaps/16x16/form.bmp"
DlgMask  BITMAP "../bitmaps/16x16/frmmask.bmp"
Open     BITMAP "../bitmaps/32x32/open.bmp"
Open2    BITMAP "../bitmaps/16x16/open.bmp"
Save     BITMAP "../bitmaps/32x32/floppy.bmp"
Run      BITMAP "../bitmaps/32x32/run.bmp"
Prg      BITMAP "../bitmaps/16x16/source.bmp"
PrgMask  BITMAP "../bitmaps/16x16/srcmask.bmp"
Exit2    BITMAP "../bitmaps/16x16/exit2.bmp"
includes BITMAP "../bitmaps/16x16/next.bmp"
bitmap   BITMAP "../bitmaps/16x16/bitmap.bmp"
bmpmask  BITMAP "../bitmaps/16x16/bmpmask.bmp"
icon     BITMAP "../bitmaps/16x16/icon.bmp"
icomask  BITMAP "../bitmaps/16x16/icomask.bmp"
folder   BITMAP "../bitmaps/16x16/folder.bmp"
fldmask  BITMAP "../bitmaps/16x16/fldmask.bmp"


Image

Re: Building a TTreeView with all folders and files

PostPosted: Mon Feb 04, 2019 6:40 pm
by Otto
Dear Antonio,
this is looking very professional. Thank you.
I tested the code and the treeview is not only good looking but very speedy too.
Best regards,
Otto

Re: Building a TTreeView with all folders and files

PostPosted: Tue Feb 05, 2019 8:44 am
by Antonio Linares
Using FWH SourceEdit() to review the files contents:

thanks to Cristobal! :-)

Code: Select all  Expand view
#include "FiveWin.ch"

static oImageList

//----------------------------------------------------------------------------//

Function Main()

   local oDlg, oGet, cText := ""

   DEFINE DIALOG oDlg SIZE 1000, 600
   oDlg:lHelpIcon := .F.
   
   //@ 0, 100 GET oGet VAR cText MEMO SIZE 350, 300 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( SourceEdit( , "", , 0, 200, 599, 799, ;
                            , , , , oDlg, , , , , , , , .T., .F., , ,  ), ;
                oGet := SourceEditor(), oGet:SetText( "" ), ;
                BuildTree( oDlg, oGet ) )

   oImageList:End()

return nil

//----------------------------------------------------------------------------//

Function BuildTree( oDlg, oGet )

   local oTreeView := TTreeView():New( 0, 0, oDlg )
   local cPath := "c:\harbour\*", oItem

   oImageList := TImageList():New()

   oDlg:SetText( cPath )
   oTreeView:SetSize( 200, oDlg:nHeight - 32 )
   oTreeView:bChanged = { || If( ( oItem := oTreeView:GetSelected() ) != nil,;
                             if( oGet:ClassName() == "TGET", ;
                             oGet:SetText( MemoRead( oItem:Cargo ) ), ;
                             ( oGet:SetText( oGet:OpenFile( oItem:Cargo, .T. ) ), oGet:GoHome() ) ), ) }

   oImageList:Add( TBitmap():Define( "folder",,  oDlg ),;
                   TBitmap():Define( "fldmask",, oDlg ) )  
   oImageList:Add( TBitmap():Define( "prg",,  oDlg ),;
                   TBitmap():Define( "prgMask",,  oDlg ) )
   oTreeView:SetImageList( oImageList )

   ReadFiles( cPath, oTreeView )

return nil

//----------------------------------------------------------------------------//

Function ReadFiles( cPath, oTreeView )

   local aFiles := Directory( cPath, "D" )
   local oTreeItem, n
   
   for n = 1 to Len( aFiles )
      if aFiles[ n ][ 1 ] != "." .and. aFiles[ n ][ 1 ] != ".."
         oTreeItem = oTreeView:Add( aFiles[ n ][ 1 ], If( aFiles[ n ][ 5 ] == "D", 0, 1 ) )
         if aFiles[ n ][ 5 ] == "D"
            ReadFiles( SubStr( cPath, 1, RAt( "\", cPath ) ) + aFiles[ n ][ 1 ] + "\*", oTreeItem )
         else
            oTreeItem:Cargo = SubStr( cPath, 1, RAt( "
\", cPath ) ) + aFiles[ n ][ 1 ]
         endif
      endif  
   next

return nil

//----------------------------------------------------------------------------//


Image

Re: Building a TTreeView with all folders and files

PostPosted: Tue Feb 05, 2019 9:09 am
by Otto
Dear Antonio,
I get following error:
Error description: Error BASE/1004 Class: 'NIL' has no exported method: EVAL
Args:
[ 1] = U
[ 2] = O TSCINTILLA

Stack Calls
===========
Called from: => EVAL( 0 )
Called from: .\source\function\MEMOEDIT.PRG => SETUPSCINT( 790 )
Called from: .\source\function\MEMOEDIT.PRG => SOURCEEDIT( 590 )

Thank you in advance
Otto

Re: Building a TTreeView with all folders and files

PostPosted: Wed Feb 06, 2019 8:24 pm
by cnavarro
Dear Otto,

But I do not understand why if this modification is in the repository, it is not included in the published version. Antonio?

Now you have
Code: Select all  Expand view

 
      Eval( bInit, oEditor1 )
 
 


Please put this code at end of Function SetupScint, and try

Code: Select all  Expand view


   if bInit != nil .and. Valtype( bInit ) == "B"
      Eval( bInit, oEditor1 )
   endif

 

Re: Building a TTreeView with all folders and files

PostPosted: Thu Feb 07, 2019 7:31 am
by Carles
Hi,

Code: Select all  Expand view
  if Valtype( bInit ) == "B"
     Eval( bInit, oEditor1 )
  endif

Re: Building a TTreeView with all folders and files

PostPosted: Thu Feb 07, 2019 10:34 am
by cnavarro
Carles, thanks :D

Re: Building a TTreeView with all folders and files

PostPosted: Sat Feb 09, 2019 9:33 pm
by cnavarro
Better, replace this function

Code: Select all  Expand view

//----------------------------------------------------------------------------//

Function ReadFiles( cPath, oTreeView )

   local aFiles := Directory( cPath, "D" )
   local oTreeItem, n

   for n = 1 to Len( aFiles )
      if aFiles[ n ][ 1 ] != "." .and. aFiles[ n ][ 1 ] != ".."
         oTreeItem = oTreeView:Add( if( "D" $ aFiles[ n ][ 5 ], ;
                                        Upper( aFiles[ n ][ 1 ] ), aFiles[ n ][ 1 ] ), ;
                                    if( "D" $ aFiles[ n ][ 5 ], 0, 1 ) )
         if "D" $ aFiles[ n ][ 5 ]
            ReadFiles( SubStr( cPath, 1, RAt( "\", cPath ) ) + aFiles[ n ][ 1 ] + "\*", oTreeItem )
         else
            oTreeItem:Cargo = SubStr( cPath, 1, RAt( "
\", cPath ) ) + aFiles[ n ][ 1 ]
         endif
      endif  
   next

return nil

//----------------------------------------------------------------------------//

Re: Building a TTreeView with all folders and files

PostPosted: Wed Mar 06, 2019 6:36 pm
by Silvio.Falconi
Code: Select all  Expand view
Application
===========
   Path and name: C:\Work\Errori\FileMidi\elixir.Exe (32 bits)
   Size: 3,773,440 bytes
   Compiler version: Harbour 3.2.0dev (r1703231115)
   FiveWin  version: FWH 18.12
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.2, Build 9200

   Time from start: 0 hours 0 mins 0 secs
   Error occurred at: 03/06/19, 19:35:08
   Error description: Error FiveWin/6  Cannot create window or control:
Class: TSCINTILLA
Caption:
System Error: Impossibile trovare la classe della finestra.


Stack Calls
===========
   Called from: .\source\classes\WINDOW.PRG => WNDCREATEERROR( 848 )
   Called from: .\source\classes\WINDOW.PRG => TSCINTILLA:CREATE( 831 )
   Called from: .\source\classes\SCINTILA.PRG => TSCINTILLA:NEW( 786 )
   Called from: .\source\function\MEMOEDIT.PRG => SOURCEEDIT( 594 )
   Called from: elixir.prg => (b)MAIN( 20 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:INITIATE( 864 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 1120 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 304 )
   Called from: elixir.prg => MAIN( 20 )


why I not have this ?

Re: Building a TTreeView with all folders and files

PostPosted: Wed Mar 06, 2019 9:37 pm
by cnavarro
For this error
Download this file in your path application, rename to SciLexer.DLL and try
https://bitbucket.org/fivetech/fivewin- ... ll_X86.dll