BBjFileChooserCancelEvent::getFileChooser

Description

In BBj 7.0 and later, this method returns the BBjFileChooser on which this event occurred.

Syntax

Return Value

Method

BBjFileChooser

getFileChooser()

Parameters

None.

Return Value

Returns a BBjVector containing the absolute file names of the selected files.

Remarks

None.

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:
    ev! = BBjAPI().getLastEvent()

    rem 'add a static text for each selected file
    window!.destroy()

    rem 'Get selected files from BBjFileChooserApproveEvent
    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:
    ev! = BBjAPI().getLastEvent()

    rem 'Print filechooser's current selection on quit
    myFileChooser! = ev!.getFileChooser()
    PRINT myFileChooser!.getSelectedFiles()

    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

BBj Object Syntax

BBjFileChooser

BBj Object Diagram for an illustration of the relationship between BBjObjects.