Copyright (c) 2012-2016 Hyperion Entertainment and contributors.

ASL File Requester

From AmigaOS Documentation Wiki
Jump to: navigation, search

The ASL library contains a file requester. First, allocate a requester structure with AllocAslRequest() or AllocAslRequestTags(). The type should be set to ASL_FileRequest in order to get a FileRequester structure:

struct FileRequester    {          /* (from <libraries/asl.h>)     */
        APTR    rf_Reserved1;
        BYTE    *rf_File;          /* Filename pointer             */
        BYTE    *rf_Dir;           /* Directory name pointer       */
        CPTR    rf_Reserved2;
        UBYTE   rf_Reserved3;
        UBYTE   rf_Reserved4;
        APTR    rf_Reserved5;
        WORD    rf_LeftEdge,rf_TopEdge; /* Preferred window pos   */
        WORD    rf_Width,rf_Height;     /* Preferred window size  */
        WORD    rf_Reserved6;
        LONG    rf_NumArgs;        /* A-la WB Args, for multiselects */
        struct WBArg *rf_ArgList;
        APTR    rf_UserData;       /* Applihandle (you may write!!)  */
        APTR    rf_Reserved7;
        APTR    rf_Reserved8;
        BYTE    *rf_Pat;           /* Pattern match pointer          */
        };                         /* note - more reserved fields follow */

Once the requester is set up, call AslRequest() or AslRequestTags() to make the requester appear on screen.

The ASL File Requester

When the requester is no longer needed, call FreeAslRequest() to deallocate the requester data structure.

Specifying Requester Options With TagItems

The file requester is specified with a TagItem list. There are several tags that are specific to the file requester:

File Requester Tag Name Used For
ASLFR_Window Specifies the parent window of the requester
ASLFR_TitleText String to place in the title bar of the requester window
ASLFR_InitialWidth Requester window width
ASLFR_InitialHeight Requester window height
ASLFR_InitialLeftEdge Requester window y origin
ASLFR_InitialTopEdge Requester window x origin
ASLFR_PositiveText String to place in OK gadget of requester
ASLFR_NegativeText String to place in Cancel gadget of requester
ASLFR_InitialFile Default file name (for file requesters only)
ASLFR_InitialDrawer Default directory name (for file requesters only)
ASLFR_InitialPattern Initial pattern-matching string
ASLFR_DoSaveMode Specifies that this file requester is a save requester (this replaces the FILF_SAVE flag in the ASL_FuncFlags tag used in V37).
ASLFR_DoMultiSelect Enables multiple selection of files (this replaces the FILF_MULTISELECT flag in ASL_FuncFlags used in V37).
ASLFR_DoPatterns Causes a pattern gadget to be included in the requester (this replaces the FILF_PATGAD flag in ASL_FuncFlags used in V37).
ASLFR_DrawersOnly Causes the requester to only display drawers (this replaces the FIL1F_NOFILES flag in ASL_ExtFlags1 used in V37).
ASLFR_RejectIcons Causes the requester not to display Workbench icons.
ASLFR_RejectPattern Specifies an AmigaDOS pattern used to reject files.
ASLFR_AcceptPattern Specifies an AmigaDOS pattern used to accept files.
ASLFR_FilterDrawers Makes ASLFR_RejectPattern and ASLFR_AcceptPattern apply to drawer names.

Simple ASL File Requester Example

Here's a short example showing how to create a file requester with asl.library. If AslRequest() returns TRUE then the rf_File and rf_Dir fields of the requester data structure contain the name and directory of the file the user selected. Note that the user can type in the a name for the file and directory, which makes it possible for a file requester to return a file and directory that do not (currently) exist.

// filereq.c
#include <exec/types.h>
#include <exec/libraries.h>
#include <libraries/asl.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/asl.h>
#define MYLEFTEDGE 0
#define MYTOPEDGE  0
#define MYWIDTH    320
#define MYHEIGHT   400
struct AslIFace *IAsl = NULL;
struct TagItem frtags[] =
    ASL_Hail,       (uint32)"The Amiga file requester",
    ASL_Height,     MYHEIGHT,
    ASL_Width,      MYWIDTH,
    ASL_LeftEdge,   MYLEFTEDGE,
    ASL_TopEdge,    MYTOPEDGE,
    ASL_OKText,     (uint32)"O KAY",
    ASL_CancelText, (uint32)"not OK",
    ASL_File,       (uint32)"asl.library",
    ASL_Dir,        (uint32)"libs:",
int main(int argc, char **argv)
    struct Library *AslBase = IExec->OpenLibrary("asl.library", 50);
    IAsl = (struct AslIFace*)IExec->GetInterface(AslBase, "main", 1, NULL);
    if (IAsl != NULL)
        struct FileRequester *fr = IAsl->AllocAslRequest(ASL_FileRequest, frtags);
        if (fr != NULL)
            if (IAsl->AslRequest(fr, NULL))
                IDOS->Printf("PATH=%s  FILE=%s\n", fr->rf_Dir, fr->rf_File);
                IDOS->Printf("To combine the path and filename, copy the path\n");
                IDOS->Printf("to a buffer, add the filename with Dos AddPart().\n");
        else IDOS->Printf("User Cancelled\n");
    DropInterface((struct Interface*)IAsl);
    return 0;

File Pattern Matching and Multiple Selects

A file requester can filter out certain file and directory entries using the "wildcard" feature of AmigaDOS. To activate the wildcard feature for a file requester, you use the ASL_FuncFlags tag. Each bit in the ASL_FuncFlags tag item controls a special option of the requester depending on its type (file or font). See <libraries/asl.h> for a complete listing of the options that the ASL_FuncFlags tag controls.

File Requester Flag Used For
FILF_PATGAD Enables the file name pattern matching gadget
FILF_MULTISELECT Enables multiple selection of files
FILF_NEWIDCMP Use separate IDCMP for requester sharing a custom screen (see below)
FILF_SAVE Makes the file requester a save requester (see below)

If the FILF_PATGAD bit of the ASL_FuncFlags tag is set, the file requester will appear with a "Pattern" gadget in addition to the usual file name and directory name gadgets. The user can type an AmigaDOS wildcard pattern into this gadget and the pattern will be used to limit the file names that appear in the requester. An application can also supply a default pattern using the ASL_Pattern tag item. A hidden unchangeable pattern can be created by supplying an ASL_Pattern without a FILF_PATGAD gadget. Such invisible patterns should not be used if there is any reason that the user may need to access a file which does not match the pattern.

Another feature of the ASL file requester is multiple selection. When multiple selection is enabled, the user can choose more than one file name in a single directory by selecting names in the requester's scrolling list gadget with the mouse. This option, like pattern matching, is set up with the ASL_FuncFlags tag.

If the FILF_MULTISELECT bit of the ASL_FuncFlags tag is set, the file requester will allow multiple selection. When the user selects several file names through the multiple selection feature, the FileRequester's rf_NumArgs field contains the number of files selected and the rf_ArgList field contains a pointer to an array of WBArg structures (defined in <workbench/startup.h>). There is a WBArg structure containing a file name for each file the user selected.

The following example illustrates a file requester with both a pattern matching gadget and multiple selection enabled.

** filepat.c
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/screens.h>
#include <graphics/displayinfo.h>
#include <libraries/asl.h>
#include <workbench/startup.h>
#include <proto/asl.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
struct AslIFace *IAsl = NULL;
struct IntuitionIFace *IIntuition = NULL;
struct Screen *screen = NULL;
struct Window *window = NULL;
int main(int argc, char **argv)
    struct FileRequester *fr;
    struct WBArg *frargs;
    int x;
    struct Library *AslBase = IExec->OpenLibrary("asl.library", 50);
    IAsl = (struct AslIFace*)IExec->GetInterface(AslBase, "main", 1, NULL);
    struct Library *IntuitionBase = IExec->OpenLibrary("intuition.library", 50);
    IIntuition = (struct IntuitionIFace*)IExec->GetInterface(IntuitionBase, "main", 1, NULL);
    if (IAsl != NULL && IIntuition != NULL)
       if (screen = IIntuition->OpenScreenTags(NULL,
               SA_DisplayID, HIRESLACE_KEY,
               SA_Title, "ASL Test Screen",
           if (window = IIntuition->OpenWindowTags(NULL,
                   WA_CustomScreen, screen,
                   WA_Title, "Demo Customscreen, File Pattern, Multi-select",
                   WA_Flags, WINDOWDEPTH | WINDOWDRAG,
               if (fr = (struct FileRequester *)
                       ASL_Hail, "FilePat/MultiSelect Demo",
                       ASL_Dir,  "libs:",
                       ASL_File, "asl.library",
                       /* Initial pattern string for pattern matching */
                       ASL_Pattern, "~(rexx#?|math#?)",
                       /* Enable multiselection and pattern match gadget */
                       ASL_FuncFlags, FILF_MULTISELECT | FILF_PATGAD,
                       /* This requester comes up on the screen of this
                       ** window (and uses window's message port, if any).
                       ASL_Window, window,
                   /* Put up file requester */
                   if (IAsl->AslRequest(fr, 0L))
                       /* If the file requester's rf_NumArgs field
                       ** is not zero, the user multiselected. The
                       ** number of files is stored in rf_NumArgs.
                       if (fr->rf_NumArgs)
                           /* rf_ArgList is an array of WBArg structures
                           ** (see <workbench/startup.h>). Each entry in
                           ** this array corresponds to one of the files
                           ** the user selected (in alphabetical order).
                           frargs = fr->rf_ArgList;
                           /* The user multiselected, step through
                           ** the list of selected files.
                           for ( x=0;  x < fr->rf_NumArgs;  x++ )
                               IDOS->Printf("Argument %ld: PATH=%s FILE=%s\n",
                                   x, fr->rf_Dir, frargs[x].wa_Name);
                           /* The user didn't multiselect, use the
                           ** normal way to get the file name.
                           IDOS->Printf("PATH=%s FILE=%s\n", fr->rf_Dir, fr->rf_File);
                   /* Done with the FileRequester, better return it */
    IExec->DropInterface((struct Interface*)IIntuition);
    IExec->DropInterface((struct Interface*)IAsl);
    return 0;

The Save Requester

The save requester is a special type of file requester used for save operations. It differs from the regular ASL file requester in several ways.

A save requester does not allow the user to select an existing file name by double-clicking on an entry in the scrolling list gadget. This helps prevent the user from accidentally overwriting the wrong file.

Save requesters can also create directories. If the user types a directory name into the save requester and the directory doesn't exist, the save requester will create that directory (after getting the user's permission via another requester).

To create a save requester, set the ASLFR_DoSaveMode tag to TRUE. Note that it does not make sense to have multiselection in a save requester, so the ASLFR_DoSaveMode tag overrides the ASLFR_DoMultiSelect tag.

The Directory Requester

Sometimes a program may only require a directory name from the user. There is another variation on asl.library's file requester that allows this. If the ASLFR_DrawersOnly tag is set to TRUE, the requester will appear without a string gadget for file names and will display only directory names in the scrolling list gadget. When AslRequest() (or AslRequestTags() ) returns successfully, the rf_Dir field of the FileRequester structure contains the name of the directory the user selected.

Another flag defined for ASL_ExtFlags1 is FIL1F_MATCHDIRS. If file pattern matching is on (see the FILF_PATGAD flag for ASL_FuncFlags), setting FIL1F_MATCHDIRS tells the file requester to pattern match directory names as well as file names. Of course, if both of these ASL_ExtFlags1 flags are set, the requester will only pattern match directory names.