A POP-UP FILE SELECTOR

Graham Crow presents a Basic function to implement a pop-up file selection box.

Because of space constraints, this program is included on the magazine disc only.

While the RISC OS Desktop provides a consistent and simple-to-use interface for loading and saving files, not everyone will want to write their programs to use the WIMP. However, this doesn't mean that you cannot have a consistent and user-friendly file selector, as this program shows. The basic principle is that whenever a program wishes to access a file, it calls the generalised file selector which allows the user to move between discs, and up and down directories, ultimately selecting a file. The full pathname of this file is then returned to the program, which is free to do whatever it likes with the file.

USING THE PROCEDURE

The file selector function is contained on disc as part of a demonstration program. When this is run you will be presented with a blank screen with the file selector in the centre. This box will be similar to that shown in figure 1. Working round the box: at the top is a title which can be specified by the main program. Below this are two boxes, a small one showing the drive number, and a larger one with the name of the currently displayed directory. To the left of these are two arrows which can be used to step through the available drives. This is done using the pointer and the Select button. At the right is an arrow which can be used to move up a level in the directory tree. If you change the disc in the drive, clicking on the drive number window will mount the new drive.

The large area in the centre of the selector shows the entries in the current directory. Files are shown by name, along with their filetype in both hex and as a name. Entries will be greyed out if their filetype doesn't match that specified by the main program. Sub-directories are shown in red, with a down-arrow to the right of the name. Pressing Tab will change the display to show the access and length of each file, instead of the filetype. A further press of Tab reverts back again. Clicking on a non-grey filename will select it and cause its name to appear in the bottom box, while clicking on a sub-directory will display its contents. Once a file has been selected, the name in the lower box can be edited, and clicking on OK will return the full pathname to the main program. Clicking on CANCEL will return without a name. The demonstration program will merely display the selected filename. If there are more files than can be fitted on the display, then the two arrows to the right of CANCEL will move up and down by a page.

USING THE SELECTOR IN YOUR OWN PROGRAMS

Incorporating the file selector function into your own program is relatively easy. The best way to understand how this is done is to study the demonstration program. You will need to include all the code from line 320 onwards in your own program. The main function is FNfiler, but before calling this you must call the initialising procedures, as in line 150. This sets up various variables, and also the colour palette. The function FNfiler takes five parameters thus:
path$=FNfiler(left,top,lines,head$,type)
The parameters left and top specify the position of the top left of the window in terms of characters, while lines specifies the number of lines to use for the file display. head$ is the heading to give to the window, and type is the particular filetype that should be recognised. A value of -1 indicates that all file types are valid. The function returns the full pathname of the selected file, or a null string if cancel is selected.