BBjFileChooser::addFileFilter

Description

In BBj 7.00 and higher, this method adds a file filter to the BBjFileChooser dialog.

Syntax

Return Value Method
void addFileFilter(String name, String filter)
void addFileFilter(String name, BBjVector filters!)

Parameters

Parameter Description
name The name of the filter to identify it in other methods and to show a label to the user. See Remarks for more details.
filter A file glob description.
filters! A vector of "file glob" descriptions. See Remarks for more details.

Return Value

None.

Remarks

The name of the filter will be the description shown to the user in addition to the identifier BBj uses to add and remove the file filter.

The filters can be any characters, following standard "file glob" syntax. The '*' character corresponds to any number of characters (including zero). The '?' character corresponds to a single character. The backslash "\" may be used to escape either character. See the example code.

The BBjVector form of the method allows combining multiple file filters under one name. For instance *.jpg" and *.png" could both be named Image Files.

BUI logo

With the BUI client-side file chooser, setting a filter does not affect which files may be selected by the user. When the user clicks OK, the selected filename(s) are compared to the current filter; the selection is only allowed if all selected filename(s) match the filter. See Interacting with client files in BUI and DWC for a detailed discussion of the BUI and DWC client-side file choosers.

Example

sg = unt
open(sg)"X0"
DIM ev$:TMPL(sg)
DIM GES_ev$:TMPL(sg)

api! = BBjAPI()
sg! = api!.getSysGui()
window! = sg!.addWindow(100, 100, 500, 350, "File Chooser", $00010083$, $$)
fc! = window!.addFileChooser(101, 0, 0, 500, 300, $$, $0004$)
button! = window!.addButton(102, 200, 310, 100, 30, "Select files")
vec! = BBjAPI().makeVector()
vec!.add("*.gif")
vec!.add("*.jpg")
vec!.add("*.png")
vec!.add("*.bmp")
vec!.add("*.ico")
fc!.addFileFilter("Image Files", vec!)
fc!.addFileFilter("Text Files", "*.txt")
fc!.setActiveFileFilter("Text Files")
fc!.setMultiSelectionEnabled(1)
fc!.setControlButtonsAreShown(0)

button!.setCallback(api!.ON_BUTTON_PUSH, "SELECT_FILES")
fc!.setCallback(api!.ON_FILECHOOSER_APPROVE, "DO_APPROVE")
fc!.setCallback(api!.ON_FILECHOOSER_CANCEL, "DO_CANCEL")
fc!.setCallback(api!.ON_FILECHOOSER_CHANGE, "DO_CHANGE")

fc!.setCallback(api!.ON_GAINED_FOCUS, "PRINT_EVENT")
fc!.setCallback(api!.ON_LOST_FOCUS, "PRINT_EVENT")

window!.setCallback(api!.ON_CLOSE, "DO_CLOSE")

process_events

DO_CLOSE:
    GOSUB PRINT_EVENT
release

DO_CHANGE:
    ? api!.getLastEvent().getSelectedFiles()
return

SELECT_FILES:
    dirCh = UNT
    pwd$ = DIR("")
    open(dirCh)pwd$
    readrecord(dirCh)file1$
    readrecord(dirCh)file2$
    vec! = api!.makeVector()
    vec!.addItem(pwd$ + "/" + file1$)
    vec!.addItem(pwd$ + "/" + file2$)
    fc!.setSelectedFiles(vec!)
return

DO_APPROVE:
    GOSUB PRINT_EVENT

    ev! = BBjAPI().getLastEvent()
    vec! = ev!.getSelectedFiles()
    for idx = 0 to vec!.size() - 1
        if (vec!.size() > 0)
            file$ = vec!.get(idx)
            window!.addStaticText(101 + idx, 10, 10 + (30 * idx), 200, 30, file$)
        endif
    next idx
    window!.destroy()
return

DO_DIALOG_CANCEL:
    GOSUB PRINT_EVENT
    fc!.cancelSelection()
return

DO_CANCEL:
    GOSUB PRINT_EVENT
    window!.addStaticText(102, 10, 10, 200, 30, "File selection cancelled")
return

PRINT_EVENT:
    ev$ = BBjAPI().getSysGui().getLastEventString()
    PRINT fnGetEventString$(ev$)
return

DEF fnGetEventString$(GES_ev$)
RESULT$ = GES_ev.code$ + " "
RESULT$ = RESULT$ + STR(GES_ev.context) + ":"
RESULT$ = RESULT$ + STR(GES_ev.id) + ", ("
RESULT$ = RESULT$ + STR(GES_ev.x) + ", "
RESULT$ = RESULT$ + STR(GES_ev.y) + "): $"
RESULT$ = RESULT$ + HTA(BIN(GES_ev.flags)) + "$"
return RESULT$
FNEND

See Also

BBjAPI

BBjSysGui

BBjWindow

BBjFileChooser

   BBjFileChooser::getActiveFileFilter

   BBjFileChooser::getFileFilterContents

   BBjFileChooser::getFileFilterNames

   BBjFileChooser::removeFileFilter

   BBjFileChooser::setActiveFileFilter

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