BBjWindow::addFileChooser

Description

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

Syntax

Return Value

Method

BBjFileChooser

addFileChooser(int ID, number x, number y, number w, number h, string directory)

BBjFileChooser

addFileChooser(int ID, number x, number y, number w, number h, string directory, string flags)

BBjFileChooser addFileChooser(int ID, string directory)
BBjFileChooser addFileChooser(int ID, string directory, string flags)
BBjFileChooser addFileChooser(string directory)
BBjFileChooser addFileChooser(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.00 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$.

If the ID parameter is not specified, a control ID is assigned dynamically using getAvailableControlID().

If the x, y, width, and height parameters are not specified, they are all initialized to 0. This is typically for use with DWC windows that dynamically arrange their contents (window creation flag $00100000$).

BUI logo

See Interacting with client files in BUI and DWC for a detailed discussion of the BUI and DWC 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.