I try to extend xbrwdisk.prg to change directory with a click on a button.
I use :SetTree.
But then inside xBrowse it adds a new column item.
Can you please help me.
Best regards,
Otto
- Code: Select all Expand view RUN
#include "FiveWin.ch"
#include "xbrowse.ch"
static aDrives := {}
//----------------------------------------------------------------------------//
function Main()
local oDlg, oBrw, oTree, oFont, b
aDrives := aDrives( 2 )
SET DATE ITALIAN
SET CENTURY ON
oTree := MakeTree()
DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
DEFINE DIALOG oDlg SIZE 640,440 PIXEL ;
TITLE 'Directory' ;
FONT oFont
@ 0,0 ;
BUTTON "Change directory" ;
ACTION ( aDrives := { "c:\fwh\samples\"}, oTree := MakeTree( aDrives ), oBrw:SetTree( oTree) );
OF oDlg
@ 25,10 XBROWSE oBrw SIZE 300,200 PIXEL OF oDlg NOBORDER
oBrw:SetTree( oTree, { "\fwh\bitmaps\open2.bmp", ;
"\fwh\bitmaps\16x16\folder.bmp", ;
"\fwh\bitmaps\16x16\onepage2.bmp" } )
oBrw:bKeyChar := { |nKey| If( nKey == VK_RETURN .and. ! Empty( oBrw:oTreeItem:bAction ), ;
Eval( oBrw:oTreeItem:bAction, oBrw:oTreeItem ), nil ) }
WITH OBJECT oBrw:aCols[ 1 ]
:AddBmpFile( "\fwh\bitmaps\hdrive.bmp" )
:nWidth := 300
:cHeader := 'File/Folder'
b := :bLDClickData
:bLDClickData := { |r,c,f,o| ToggleFolder( r,c,f,o,b ) }
:bBmpData := { || If( ':' $ oBrw:oTreeItem:cPrompt, 4, ;
If( 'D' $ oBrw:oTreeItem:Cargo[ 5 ], ;
If( oBrw:oTreeItem:lOpened, 1, 2 ), 3 ) ) }
END
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] ;
PICTURE '@EZ 999,999,999' HEADER 'Bytes'
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 3 ] HEADER 'Date'
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 4 ] HEADER 'Time'
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 5 ] HEADER 'Attr'
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTER
return nil
//----------------------------------------------------------------------------//
static function ToggleFolder( r, c, f, oCol, b )
local oBrw := oCol:oBrw
local oItem := oBrw:oTreeItem
If ! oItem:lOpened .and. ! Empty( oItem:bAction )
Eval( oItem:bAction, oItem )
endif
if b != nil
Eval( b, r, c, f, oCol )
endif
return nil
//----------------------------------------------------------------------------//
static function MakeTree()
local oTree, oItem, n
TREE oTree
for n := 1 to Len( aDrives )
TREEITEM oItem PROMPT aDrives[ n ]
oItem:Cargo := { aDrives[ n ], 0, CtoD( '' ), Space( 8 ), 'D', ;
aDrives[ n ] }
oItem:bAction := { |o| o:SetTree( SubTree( o ) ), o:bACtion := nil }
next
ENDTREE
return oTree
//----------------------------------------------------------------------------//
static function SubTree( oParent )
local oTree, n, oItem, nLevel, nItems := 0
local cFolder := oParent:Cargo[ 6 ]
local aDir := Directory( cFolder + '\*.*', 'D' )
nLevel := oParent:nLevel + 1
TREE oTree
for n := 1 to Len( aDir )
if ! ( aDir[ n ][ 1 ] = '.' )
TREEITEM oItem PROMPT aDir[ n ][ 1 ]
oItem:nlevel := nLevel
oItem:Cargo := aDir[ n ]
AAdd( oItem:Cargo, cFolder + Chr(92) + aDir[ n ][ 1 ] )
if 'D' $ aDir[ n ][ 5 ]
oItem:bAction := { |o| o:SetTree( SubTree( o ) ), o:bACtion := nil }
else
oItem:bAction := { |o| MsgInfo( o:cPrompt ) }
endif
nItems++
endif
next
if nItems == 0
n--
TREEITEM oItem PROMPT ''
oItem:nlevel := nLevel
aDir[ n ][ 5 ] := 'A'
oItem:Cargo := { '', 0, CToD( '' ), Space(8), ' ', '' }
AAdd( oItem:Cargo, cFolder + Chr(92) + aDir[ n ][ 1 ] )
endif
ENDTREE
return oTree
//----------------------------------------------------------------------------//