/* my includes */

#include <exec/types.h>
#include <libraries/multireq.h>
#include <clib/multireq_protos.h>
#include <pragmas/multireq_lib.h>

/* some Functions not defined yet */

extern struct MultiReqBase *OpenLibrary();
extern UWORD FileRequester();
extern void InitFileReq(), FreeFileReq();


/* a pointer to the multireq.library base */

struct MultiReqBase *MultiReqBase;


/* memory for the pointer to the FileReq-structure */

struct FileReq *fr;


/* the main program */

main(argc,argv)
int argc;
char **argv;
{
  register UWORD erg;


  /* open the multireq.library */

  if(!(MultiReqBase=OpenLibrary("multireq.library",0L)))
  {
    puts("Can't open multireq.library !");
    exit(0);
  }


  /* Create a FileReq-structure */

  InitFileReq(&fr,2L);		/* 2 allways as second argument, cause no other
				   number of filelists suported yet */

  if(fr)			/* FileReq-structure ok ? */
  {
    /* Set some sample parameters */
    
    SetParameters();

    do
    {
      /* start FileRequester on WorkBench-screen */

      erg=FileRequester(fr,NULL);


      /* Say how the FileRequester was ended */

      WriteAction();

    }while(erg==RET_OKAY);	/* should I start again ? */


    /* Delete the FileReq-structure and free the memory */

    FreeFileReq(&fr);

  }
  else
    puts("Unable to create FileReq-structure !");


  /* Close the multireq.library */

  CloseLibrary(MultiReqBase);


  if(argc==0)
    Delay(200L);		/* I'm started from WBench, so I wait 2 Seconds */


  /* everything done, bye ! */
}


/* This routine is a example how to interpret the ReturnStatus of the */
/* FileRequester (notice the value ReturnStatus is identical to that returned */
/* by the FileRequester-function */

WriteAction()
{
  switch(fr->ReturnStatus)
  {
    case RET_ERROR:	/* start successfull ? */
      puts("Unable to open FileRequester !");
      break;

    case RET_CANCEL:	/* Cancel-gadget pressed */
      puts("You've clicked on the Cancel-gadget");
      break;

    case RET_CLOSE:	/* Close-gadget pressed */
      puts("You've clicked on the Close-gadget");
      break;

    case RET_FILE:	/* RETURN pressed */
      puts("You've pressed <RETURN> in the File-gadget");
      break;

    case RET_DOUBLE:	/* DoubleClick on File */
      puts("You've done a DoubleClick on a File");
      break;

    case RET_OKAY:	/* Okay-gadget pressed */
      puts("You've pressed on the Okay-gadget");
      puts("  => the FileRequester is started again");
      break;
  }

  puts("\nThe follwing file was selected:");
  puts(fr->FileNameBuff);
  puts("");		/* write a free line after the filename */
}


/* the following part contains some parameters for the FileRequester */
/* all this parameters are optional, cause FileRequester also works, when no */
/* parameters are set (InitFileReq has done this for you) */

static UBYTE Title[]="The multitasking FileRequester by Andreas Krebs";
static UBYTE Okay[]="go on";

static UBYTE Dir1[]="SYS:";
static UBYTE Dir2[]="DEVS:";
static UBYTE File[]="SampleFile";
static UBYTE Show[]="*.*|*-*";		/* Show all files with a . or - in it */
static UBYTE Hide[]="*+*";		/* Hide all files with a + in it */

SetParameters()
{
  fr->TitleString=Title;	/* Set title of FileRequester */
  fr->OkayString=Okay;		/* Set text of Okay-gadget */

  fr->LeftEdge=20;		/* Set LeftEdge of FileRequester */
  fr->TopEdge=10;		/* Set TopEdge of FileRequester */

  fr->ActiveList=1;		/* Show filelist 2 first */
  fr->ShowInfo=HIDE_INFO;	/* Don't show .info-files */

  strcpy(fr->FileBuff,File);	/* File to be displayed in File-Gadget */
  strcpy(fr->ShowBuff,Show);	/* Files to be shown */
  strcpy(fr->HideBuff,Hide);	/* Files to be hidden */

  strcpy(fr->FileList[0].DrawerBuff,Dir1);
				/* Set name of first directory */
  fr->FileList[0].AutoRead=NO_AUTOREAD;
				/* Do not automatically readin first directory */

  strcpy(fr->FileList[1].DrawerBuff,Dir2);
				/* Set name of second directory */
  fr->FileList[1].AutoRead=DO_AUTOREAD;
				/* Do automatically readin second directory */
}
