FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Building a TTreeView with all folders and files
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Building a TTreeView with all folders and files
Posted: Mon Feb 04, 2019 12:30 PM
Code (fw): Select all Collapse
#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


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Building a TTreeView with all folders and files
Posted: Mon Feb 04, 2019 04:17 PM
Using an ImageList for the items:

elixir.prg
Code (fw): Select all Collapse
#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 (fw): Select all Collapse
#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"


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Building a TTreeView with all folders and files
Posted: Mon Feb 04, 2019 06: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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Building a TTreeView with all folders and files
Posted: Tue Feb 05, 2019 08:44 AM
Using FWH SourceEdit() to review the files contents:

thanks to Cristobal! :-)

Code (fw): Select all Collapse
#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

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


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Building a TTreeView with all folders and files
Posted: Tue Feb 05, 2019 09: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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Building a TTreeView with all folders and files
Posted: Wed Feb 06, 2019 08: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 (fw): Select all Collapse
聽
聽 聽 聽 Eval( bInit, oEditor1 )


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

Code (fw): Select all Collapse
聽 聽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
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Building a TTreeView with all folders and files
Posted: Thu Feb 07, 2019 07:31 AM
Hi,

Code (fw): Select all Collapse
 聽 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
HIX -> https://github.com/carles9000/hix
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Building a TTreeView with all folders and files
Posted: 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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Building a TTreeView with all folders and files
Posted: Sat Feb 09, 2019 09:33 PM
Better, replace this function

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Building a TTreeView with all folders and files
Posted: Wed Mar 06, 2019 06:36 PM
Code (fw): Select all Collapse
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 March-April 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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Building a TTreeView with all folders and files
Posted: Wed Mar 06, 2019 09: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

Continue the discussion