BBjWindow::addFileChooser

Description

In BBj 7.0 and higher, this method creates a BBjFileChooser in the BBjWindow.

Syntax

Return Value

Method

BBjFileChooser

addFileChooser(int ID, int x, int y, int width, int height, string directory)

BBjFileChooser

addFileChooser(int ID, int x, int y, int width, int height, string directory, string flags)

Parameters

Variable

Description

ID

Specifies the Control ID number. It must be an integer between 1 and 32767 and be unique within a given top level window.

x

Horizontal position of the upper-left corner of the control in current units.

y

Vertical position of the upper-left corner of the control in current units.

width

Width of the control in current units.

height

Height of the control in current units.

directory

Initial directory of the FileChooser

flags

Control flags, as follows:

 

Flag 

Description

 

$0001$

Sets the control to be initially disabled.

 

$0002$

In BBj 16 and higher, show a drop zone to drag and drop files to a client file chooser.  Only meaningful for the 'Open' dialog type in conjunction with $0004$ (client filesystem).

 

$0004$

Use the client's filesystem.

 

$0008$

Only allow selection of directories.

 

$0010$

Sets the control to be initially invisible.

 

$0100$

'Save' dialog type.

 

$0800$

Draws a recessed client edge around the control.

 

$1000$

Draws a raised edge around the control

Return Value

Returns the created BBjFileChooser object.

Remarks

A FileChooser control provides an object-oriented, SYSGUI-managed version of the FILEOPEN/FILESAVE functions. Emulate FILESAVE() using the $0100$ flag.

Use the BBjClientFilesystem object in concert with flag $0004$.

See BUI: Interacting with client files for a detailed discussion of the BUI client-side file choosers.

Example

REM Open SYSGUI channel
sg = unt
open(sg)"X0"

REM Get BBj objects
api! = BBjAPI()
sg! = api!.getSysGui()

REM Create main window
mainWindow! = sg!.addWindow(100, 100, 300, 500, "File Chooser Demo", $00010083$, $$)

REM Button for normal file chooser
fileChooserButton! = mainWindow!.addButton(101, 50, 10, 120, 30, "File Chooser", $$)

REM Button for directory chooser
dirChooserButton! = mainWindow!.addButton(102, 50, 50, 120, 30, "Directory Chooser", $$)

REM Set callbacks to create the choosers
fileChooserButton!.setCallback(api!.ON_BUTTON_PUSH, "OPEN_FILECHOOSER")
dirChooserButton!.setCallback(api!.ON_BUTTON_PUSH, "OPEN_DIRCHOOSER")

REM Set close callback on mainWindow!
mainWindow!.setCallback(api!.ON_CLOSE, "DO_CLOSE")

PROCESS_EVENTS

REM Callback for BBjButton fileChooserButton!
OPEN_FILECHOOSER:
    flags$ = $0000$
    GOSUB CREATE_FC
    RETURN

REM Callback for BBjButton dirChooserButton!
OPEN_DIRCHOOSER:
    flags$ = $0008$
    GOSUB CREATE_FC
    RETURN

REM Utility subroutine to create the appropriate chooser type with flags$
CREATE_FC:
    FOR i = 0 TO idx
        mainWindow!.getControl(201 + i,ERR=*BREAK).destroy()
    NEXT i
    REM Create new window for the file chooser.
    sg!.setContext(1)
    window! = sg!.addWindow(110, 110, 500, 300, "File Chooser", $00090002$, $$)

    REM Create new file chooser with appropriate flags
    fc! = window!.addFileChooser(101, 0, 0, 500, 300, $$, flags$)

    REM Set the callbacks for interaction with the File Chooser.
    window!.setCallback(api!.ON_CLOSE, "DO_DIALOG_CANCEL")
    fc!.setCallback(api!.ON_FILECHOOSER_APPROVE, "DO_APPROVE")
    fc!.setCallback(api!.ON_FILECHOOSER_CANCEL, "DO_CANCEL")
    RETURN

REM Callback for mainWindow! ON_CLOSE
DO_CLOSE:
    RELEASE

REM Callback for FileChooser approve event
DO_APPROVE:
    REM add a static text for each selected file
    window!.destroy()
    ev! = BBjAPI().getLastEvent()
    vec! = ev!.getSelectedFiles()
    for idx = 0 to vec!.size() - 1
        if (vec!.size() > 0)
            file$ = vec!.get(idx)
            mainWindow!.addStaticText(201 + idx, 10, 80 + (25 * idx), 200, 25, file$)
        endif
    next idx
    RETURN

REM Callback for FileChooser cancel event
DO_CANCEL:
    REM Destroy the window with the file chooser
    window!.destroy()

    REM add a static text with the selected files
    mainWindow!.addStaticText(201, 10, 80, 200, 30, "File selection cancelled")
    idx = 0
    RETURN

REM Callback for dialog close box
DO_DIALOG_CANCEL:
    fc!.cancelSelection()
    RETURN

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.