Building a TTreeView with all folders and files

Building a TTreeView with all folders and files

Postby Antonio Linares » Mon Feb 04, 2019 12:30 pm

Code: Select all  Expand view  RUN
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Building a TTreeView with all folders and files

Postby Antonio Linares » Mon Feb 04, 2019 4:17 pm

Using an ImageList for the items:

elixir.prg
Code: Select all  Expand view  RUN
#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  RUN
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Building a TTreeView with all folders and files

Postby Otto » Mon Feb 04, 2019 6:40 pm

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: Building a TTreeView with all folders and files

Postby Antonio Linares » Tue Feb 05, 2019 8:44 am

Using FWH SourceEdit() to review the files contents:

thanks to Cristobal! :-)

Code: Select all  Expand view  RUN
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Building a TTreeView with all folders and files

Postby Otto » Tue Feb 05, 2019 9:09 am

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: Building a TTreeView with all folders and files

Postby cnavarro » Wed Feb 06, 2019 8:24 pm

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  RUN

 
      Eval( bInit, oEditor1 )
 
 


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

Code: Select all  Expand view  RUN


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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Building a TTreeView with all folders and files

Postby Carles » Thu Feb 07, 2019 7:31 am

Hi,

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

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1139
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Building a TTreeView with all folders and files

Postby cnavarro » Thu Feb 07, 2019 10:34 am

Carles, thanks :D
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Building a TTreeView with all folders and files

Postby cnavarro » Sat Feb 09, 2019 9:33 pm

Better, replace this function

Code: Select all  Expand view  RUN

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

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

//----------------------------------------------------------------------------//
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Building a TTreeView with all folders and files

Postby Silvio.Falconi » Wed Mar 06, 2019 6:36 pm

Code: Select all  Expand view  RUN
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 ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: Building a TTreeView with all folders and files

Postby cnavarro » Wed Mar 06, 2019 9:37 pm

For this error
Download this file in your path application, rename to SciLexer.DLL and try
https://bitbucket.org/fivetech/fivewin- ... ll_X86.dll
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 39 guests