Class XbpFileDialog() Foundation
Class function of the XbpFileDialog class.
Superclass
Description
The XbpFileDialog class provides objects that manage dialog windows for selecting files. The file dialog window is a system dialog that allows the user to specify drives and directories to search for particular files. This dialog can be displayed using either the method :open() or the method :saveAs(). Both return a file name including the drive and directory. :open() may also be set up to return a list of files selected.
Class methods
:new()
Creates an instance of the XbpFileDialog class.
Life cycle
:create()
Requests system resources for the XbpFileDialog object.
:configure()
Reconfigures the XbpFileDialog object after :create() has been executed.
:destroy()
Releases the system resources of the XbpFileDialog object.
Instance variables
:bufferSize
Size of the buffer reserved for file names
:center
Determines whether the file dialog is centered in the parent window.
:defExtension
Default extension of a file selected by the user
:fileFilters
Filters to apply to the files browsed in the file dialog
:noWriteAccess
Controls validation techniques applied by the file dialog
:openReadOnly
Specifies whether files should be opened with write protection
:restoreDir
Specifies whether the original current directory should be restored
:title
The title for the file dialog.
:validatePath
Controls validation of paths entered by the user
Examples
// This example shows a text editor that runs in an
// XbpCrt window. The window has a menu bar that
// includes a submenu for processing text files. This
// menu includes the items "New", "Open", "Save" and
// "Save As". A file dialog is used for these menu
// options. The actual text editor is provided by an
// XbpMLE object whose :cargo instance variable contains
// the file name of the current file.
#include "Xbp.ch"
#include "Appevent.ch"
#pragma library("XppUi2")
PROCEDURE Main
LOCAL nEvent, mp1, mp2, oXbp
LOCAL oMLE, oFileDlg
SetColor("N/W")
CLS
// Create file dialog with desktop as parent
oFileDlg := XbpFileDialog():new()
oFileDlg:create( AppDesktop() )
// Create MLE
oMLE := XbpMLE():new():create( ,, {50,50}, {550,300} )
oMLE:cargo := ""
// Default menu for managing text files
TextFileMenu( SetAppWindow():menuBar(), oFileDlg, oMLE )
// Event loop
nEvent := 0
DO WHILE nEvent <> xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @oXbp )
oXbp:HandleEvent( nEvent, mp1, mp2 )
ENDDO
RETURN
// *************************************************
// This function creates a default menu for opening
// and saving text files
//
FUNCTION TextFileMenu( oMenuBar, oFileDlg, oMLE )
LOCAL oMenu := XbpMenu():new(oMenuBar):create()
oMenu:title := "~File"
oMenu:addItem( { "~New", ;
{|| oMLE:setData(""), oMLE:cargo := "", ;
SetAppWindow():setTitle( "No name" ), ;
oMenu:disableItem(4) } } )
oMenu:addItem( { "~Open...", ;
{|| ReadFile( oFileDlg, oMLE ), ;
IIf( Empty(oMLE:cargo), NIL, oMenu:enableItem(4)) } } )
oMenu:addItem( { ,, XBPMENUBAR_MIS_SEPARATOR,0 } )
oMenu:addItem( { "~Save", ;
{|| WriteFile( oMLE:cargo, oMLE ) }, ;
0, XBPMENUBAR_MIA_DISABLED } )
oMenu:addItem( { "Save ~as...", ;
{|| WriteFile( oFileDlg:saveAs( oMLE:cargo ), oMLE ) } } )
oMenuBar:addItem( {oMenu, NIL} )
RETURN oMenu
// *******************************************
// The procedure activates the file dialog for
// selecting a file. Reads selected files and
// copies into MLE.
//
PROCEDURE ReadFile( oFileDlg, oMLE )
LOCAL cFile := oFileDlg:open( oMLE:cargo )
IF ! Empty( cFile )
oMLE:cargo := cFile
oMLE:setData( MemoRead( cFile ) )
SetAppWindow():setTitle( cFile )
ENDIF
RETURN
// **************************************
// Write text buffer of the MLE to file
//
PROCEDURE WriteFile( cFile, oMLE )
IF ! Empty( cFile )
oMLE:cargo := cFile
MemoWrit( cFile, oMLE:getData() )
SetAppWindow():setTitle( cFile )
ENDIF
RETURN
Feedback
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.