BBjFileChooserApproveEvent::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 Print filechooser's current active filter
myFileChooser! = ev!.getFileChooser()
PRINT myFileChooser!.getActiveFileFilter()

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:
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

BBjFileChooserApproveEvent

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