BBjFileChooser

Description

In BBj 7.00 and higher, the BBjFileChooser object provides methods for manipulating a GUI file chooser control, similar to the FILEOPEN Mnemonic or FILEOPEN() Function.

Implemented Interfaces

DragSource, DropTarget, Focusable, TabTraversable

Creation

BBjAPI > BBjSysGui > BBjWindow > BBjFileChooser

A BBjFileChooser object is created through the following BBjWindow methods:

 

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)

Methods of BBjFileChooser

Return Value

Method

void

addFileFilter(string name, BBjVector filters!)

void

addFileFilter(string name, string filter)

void

approveSelection()

void

cancelSelection()

void

changeToParentDirectory()

void

ensureFileNameIsVisible(string name)

string

getActiveFileFilter()

string

getApproveButtonText()

string getCancelButtonText()

boolean

getControlButtonsAreShown()

string

getCurrentDirectory()

boolean

getDropZoneVisible()

BBjVector

getFileFilterContents(string name)

BBjVector

getFileFilterNames()

int

getFileSelectionMode()

string

getRestrictedDirectory()

string

getSelectedFile()

BBjVector

getSelectedFiles()

boolean

isAcceptAllFileFilterUsed()

boolean

isMultiSelectionEnabled()

boolean

isNewFolderEnabled()

void

removeFileFilter(string name)

void

rescanCurrentDirectory()

void

setAcceptAllFileFilterUsed(boolean used)

void

setActiveFileFilter(string name)

void

setApproveButtonText(string text)

void setCancelButtonText(string text)

void

setControlButtonsAreShown(boolean shown)

void

setCurrentDirectory(string name)

void

setDropZoneVisible(boolean visible)

void

setFileSelectionMode(int mode)

void

setMultiSelectionEnabled(boolean enabled)

void

setNewFolderEnabled(boolean enabled)

void

setRestrictedDirectory(string directory)

void

setSelectedFile(string file)

void

setSelectedFiles(BBjVector files!)

void setView(boolean detail, int column, int order)

Methods of BBjFileChooser implemented for DragSource

Return Value Method
int getDragActions()
string getDragType()
void setDragActions(int actions)
void setDragType(string type)

Methods of BBjFileChooser implemented for DropTarget

Return Value Method
int getDropActions()
void setDropActions(int actions)
BBjVector getDropTypes()
void setDropTypes(BBjVector types)

Methods of BBjFileChooser implemented for Focusable

Return Value Method
boolean isFocusable()
void setFocusable(boolean focus)

Methods of BBjFileChooser implemented for TabTraversable

Return Value Method
boolean isTabTraversable()
void setTabTraversable(boolean trav)

Methods of BBjFileChooser inherited from BBjControl

Events

Callback Code

Object-oriented Event

Read Record Event

Code

ON_DROP_TARGET_DROP

BBjDropTargetDropEvent

Drop Target Drop Event

D

ON_FILECHOOSER_APPROVE

BBjFileChooserApproveEvent

FileChooser Approve Event

x

ON_FILECHOOSER_CANCEL

BBjFileChooserCancelEvent

FileChooser Cancel Event

x

ON_FILECHOOSER_CHANGE

BBjFileChooserChangeEvent

FileChooser Change Event

x

ON_FILECHOOSER_FILTER

BBjFileChooserFilterEvent

FileChooser Filter Event

x

ON_GAINED_FOCUS

BBjGainedFocusEvent

Control Focus Gained/Lost Event

f

ON_LOST_FOCUS

BBjLostFocusEvent

Control Focus Gained/Lost Event

f

ON_MOUSE_ENTER

BBjMouseEnterEvent

Mouse Enter/Exit Event

E

ON_MOUSE_EXIT

BBjMouseExitEvent

Mouse Enter/Exit Event

E

ON_POPUP_REQUEST

BBjPopupRequestEvent

Popup Request Event

r

ON_RIGHT_MOUSE_DOWN

BBjRightMouseDownEvent

Right Mouse Button Down Event

R

BUI logoCSS

The visual appearance of BUI controls is defined using CSS (cascading style sheets) rules. Easily change the default colors, border, and other settings by customizing these rules, all without changing any application code. See CSS API for a high-level overview of BUI CSS.


The BUI BBjFileChooser is really several different kinds of control, depending on the selected version: Open or save a client file, open or save a server file, or select a server directory. See Interacting with client files in BUI and DWC for a detailed discussion of the BUI client-side file choosers. The BBjFileChooser defines the following CSS style names:

.BBjChooser

.BBjFileChooser

.BBjFileChooser.bbj-client

.BBjFileChooser.bbj-directories

.BBjFileChooser.bbj-disabled

.BBjFileChooser.bbj-focused

.BBjFileChooser .bbj-selected (note the space between .BBjFileChooser and .bbj-selected)

.BBjFileChooser.bbj-server

.BBjChooser-button-panel

.BBjChooser-button

.BBjChooser-approveButton

.BBjChooser-cancelButton

 

Individual components of the .BBjFileChooser.bbj-client dialog:

.BBjFileChooser-chooseClientFileLabel

.BBjFileChooser-chooseClientFile

.BBjFileChooser-fileTypeLabel

.BBjFileChooser-fileTypeList

.BBjFileChooser-uploadProgressBar

.BBjFileChooser-uploadStatusMessage

.BBjFileChooser-dropzone

 

Individual components of the .BBjFileChooser.bbj-server dialog:

.BBjFileChooser-directoryList

.BBjFileChooser-directoryUpButton

.BBjFileChooser-directoryDownButton

.BBjFileChooser-summaryViewButton

.BBjFileChooser-detailViewButton

.BBjFileChooser-fileGridPanel

.BBjFileChooser-detailFileGrid

.BBjFileChooser-summaryFileGrid

.BBjFileChooser-fileNameLabel

.BBjFileChooser-fileName

.BBjFileChooser-fileTypeLabel

.BBjFileChooser-fileTypeList

 

Individual components of the .BBjFileChooser.bbj-directories dialog:

.BBjFileChooser-directoryTree

.BBjFileChooser-directoryTreeItem

 

The sample program can produce any of the different BBjFileChooser styles:

rem ' filechooser.txt
flags$ = $0000$
width = 800
if msgbox("Client filesystem?",7+32,"filechooser","&Client","&Server")=1 then
   flags$ = ior(flags$,$0004$)
   title$ = "Client"
   height = 400
else
   title$ = "Server"
   height = 600
endif
if msgbox("Save-style dialog?",7+32+256,"filechooser","&Save","&Open")=1 then
   flags$ = ior(flags$,$0100$)
   title$ = title$ + " Save"
else
   title$ = title$ + " Open"
endif
if msgbox("Directory chooser?",7+32+256,"filechooser","&Directory","&File")=1 then
   flags$ = ior(flags$,$0008$)
   title$ = title$ + " Directory"
else
   title$ = title$ + " File"
endif
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(25,25,width,height,title$,$00090003$)
window!.setCallback(window!.ON_RESIZE,"resize")
window!.setCallback(window!.ON_CLOSE,"eoj")
status! = window!.addStatusBar(99)
directory$ = dsk("") + dir("")
directory$ = System.getProperty("user.home")
chooser! = window!.addFileChooser(101,25,25,width-50,height-75,directory$,flags$)
vector! = bbjapi().makeVector()
vector!.add("*.gif")
vector!.add("*.jpg")
vector!.add("*.png")
vector!.add("*.bmp")
vector!.add("*.ico")
chooser!.addFileFilter("Image Files", vector!)
chooser!.addFileFilter("Text Files", "*.txt")
chooser!.setActiveFileFilter("Text Files")
chooser!.setCallback(chooser!.ON_FILECHOOSER_CHANGE,"change")
chooser!.setCallback(chooser!.ON_FILECHOOSER_APPROVE,"approve")
chooser!.setCallback(chooser!.ON_FILECHOOSER_CANCEL,"cancel")
chooser!.setCallback(chooser!.ON_FILECHOOSER_FILTER,"filter")
chooser!.setCallback(chooser!.ON_GAINED_FOCUS,"event")
chooser!.setCallback(chooser!.ON_LOST_FOCUS,"event")
chooser!.setCallback(chooser!.ON_MOUSE_ENTER,"event")
chooser!.setCallback(chooser!.ON_MOUSE_EXIT,"event")
process_events
eoj:
  release
change:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$+": "+str(event!.getSelectedFiles())+"; "+str(chooser!.getText())
  print status$
  status!.setText(status$)
return
approve:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$+": "+str(event!.getSelectedFiles())+"; "+str(chooser!.getText())
  print status$
  status!.setText(status$)
return
cancel:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$+"; "+str(chooser!.getText())
  print status$
  status!.setText(status$)
return
filter:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  status$ = event$+": "+str(event!.getActiveFileFilter())+"; "+str(chooser!.getText())
  print status$
  status!.setText(status$)
return
event:
  event! = sysgui!.getLastEvent()
  event$ = event!.getEventName()
  control! = event!.getControl()
  control$ = control!.toString(), control$ = control$(1,pos("@"=control$)-1)
  status$ = control$+" "+event$+"; "+str(chooser!.getText())
  print status$
return
resize:
  event! = sysgui!.getLastEvent()
  chooser!.setSize(event!.getWidth()-50,event!.getHeight()-50)
return

Remarks

The BBjFileChooser is a complex control provided as-is from a GUI control library. As such, the installed LookAndFeel determines much of its presentation and behavior, attempting to adhere to the platform expectations as much as possible. Developers should avoid depending on specific functionality in the choosers.

Also, when using a filechooser connected to the server filesystem, the remote representation of the filesystem may not support all of the functionality available from the displayed filechooser.

Constants of BBjFileChooser

File Selection Mode Constants:

 

FILES_ONLY

 

FILES_AND_DIRECTORIES

 

DIRECTORIES_ONLY

Constants inherited from BBjControl

Example

rem ' BBjFileChooser 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

BBjWindow

FILEOPEN

FILEOPEN Mnemonic

CALLBACK Verb - Register BBj Subroutine

DWC Components: dwc-file-save, dwc-file-chooser, and dwc-upload

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