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 'Set callbacks to create the choosers
fileChooserButton!.setCallback(api!.ON_BUTTON_PUSH, "OPEN_FILECHOOSER")
rem 'Set close callback on mainWindow!
mainWindow!.setCallback(api!.ON_CLOSE, "DO_CLOSE")
process_events
rem 'Callback for BBjButton fileChooserButton!
OPEN_FILECHOOSER:
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
originalDir$ = DIR("")
fc! = window!.addFileChooser(101, 0, 0, 500, 250, originalDir$, flags$)
fc!.setControlButtonsAreShown(0)
rem 'Use three buttons instead of two
okButton! = window!.addButton(1, 290, 260, 60, 30, "OK", $$)
cancelButton! = window!.addButton(2, 360, 260, 60, 30, "Cancel", $$)
resetButton! = window!.addButton(3, 430, 260, 60, 30, "Reset", $$)
rem 'Set callbacks for our custom buttons to do the appropriate
rem 'filechooser actions
okButton!.setCallback(api!.ON_BUTTON_PUSH, "OK_BUTTON")
cancelButton!.setCallback(api!.ON_BUTTON_PUSH, "CANCEL_BUTTON")
resetButton!.setCallback(api!.ON_BUTTON_PUSH, "RESET_BUTTON")
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
OK_BUTTON:
fc!.approveSelection()
return
CANCEL_BUTTON:
fc!.cancelSelection()
return
RESET_BUTTON:
fc!.setCurrentDirectory(originalDir$)
return
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
|