FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour cGetFile replacement
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
cGetFile replacement
Posted: Thu Feb 27, 2014 03:43 PM

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

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

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: cGetFile replacement
Posted: Thu Feb 27, 2014 03:58 PM

Marco,

If you just want one directory, then why not just read the directory and display the list in a browse?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: cGetFile replacement
Posted: Thu Feb 27, 2014 04:27 PM

Sorry, I would like the user can navigate inside the subfolders but only for some path provided because I don't want it goes inside desktop or reserved folders.
Essentially like the sample make using logical disks I would provide network path like \server1\c , \server2\c etc. and the user can select a network path and navigate inside.

Best Regards,



Marco Turco

SOFTWARE XP LLP

Continue the discussion