Hi all,
I'm looking for a replacement for the cGetFile function because I want to restrict the directory where the user can select the file.
I have found the xbrwdisk sample in FWH that with some changes should be fine.
My problem: I have no experience using trees, at the moment doing a dblclick on the file name a msginfo with the name appears
but how can I get the full path ?
Source code is below, anyway it is the xbrwdisk.prg code of fwh\samples
Thank you in advance.
#include "FiveWin.ch"
#include "xbrowse.ch"
//----------------------------------------------------------------------------//
function Main()
local oDlg, oBrw, oTree, oFont, b
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
@ 10,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 XBROWSE oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] ;
PICTURE '@EZ 999,999,999' HEADER 'Bytes'
ADD TO XBROWSE oBrw DATA oBrw:oTreeItem:Cargo[ 3 ] HEADER 'Date'
ADD TO XBROWSE oBrw DATA oBrw:oTreeItem:Cargo[ 4 ] HEADER 'Time'
ADD TO XBROWSE 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
local aDrives := aDrives( 2 ) // Hard disks
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
//----------------------------------------------------------------------------//