54 lines
2.9 KiB
Plaintext
54 lines
2.9 KiB
Plaintext
File Dialog sample
|
|
------------------
|
|
|
|
This example tries to work like the Windows File Open box as closely as possible
|
|
(but omits the Favorites/Desktop etc buttons at the left hand side and the Search combo at the top; this is really platform-dependent).
|
|
To use the file dialog, fill a predefined record with the desired title, file patterns, etc., and then call the functions
|
|
filedlg_open() or filedlg_save() with the record as the parameter.
|
|
|
|
This works similar to the windows common dialog C-library (comdlg32.dll).
|
|
|
|
The advantage in using a record (FILEDLG_RECORD) instead of a large numer of parameters to those functions is that it's possible to use the autocompletion feature.
|
|
|
|
The DIALOG construct is used in FUNCTION _filedlg_doDlg() to let a DISPLAY ARRAY and an INPUT run in parallel to display the list of files, and to be able to enter the filename and switch between several file types using a combobox ( for example between *.per and *.*).
|
|
|
|
The accept action works in a special way in this dialog:
|
|
|
|
It determines first where the focus is, and then does the following:
|
|
|
|
1.focus is in the DISPLAY ARRAY
|
|
a)If a file is highlighted, the dialog terminates and returns the file name
|
|
b)If a directory is highlighted, the dialog switches to that directory and
|
|
reloads the file array
|
|
|
|
2. focus is in the INPUT
|
|
a)if the typed name is an existing file, the dialog terminates and returns the file name.
|
|
b)if the typed name is a directory, the code tries to switch to that directory, and to reload the file array.
|
|
c) if the typed name is neither -> failure box in open mode, return file name in save mode
|
|
|
|
The new DIALOG.getCurrentItem() built-in function is used to determine where the focus is, because INFIELD does not work for DISPLAY ARRAY.
|
|
DIALOG.getCurrentItem() returns a string thst is a field name for the usual input fields. and the screen record name for the DISPLAY ARRAY.
|
|
|
|
As an example, you can choose (as in the Windows original) that a file in the dialog can be deleted with the "Del" key if the focus is in the DISPLAY ARRAY.
|
|
This is achieved by a sub dialog action in the DISPLAY ARRAY sub dialog statement:
|
|
DIALOG
|
|
DISPLAY ARRAY
|
|
...
|
|
ON ACTION del
|
|
--perform code to delete the current highlighted file
|
|
--the action is only active if the focus is inside this display array
|
|
..
|
|
|
|
END DISPLAY
|
|
END DIALOG
|
|
The runtime system ensures that this action is only active when the focus is inside the DISPLAY ARRAY, in contradiction to the global actions below the sub dialog statements.
|
|
|
|
(If the action was also active in the INPUT sub dialog, the result would be conflicting accelerators; the 'Del' key should erase the text in the edit fields)
|
|
|
|
|
|
$FGLDIR/demo/tools/fglped makes use of this file dialog.
|
|
|
|
In $FGLDIR/demo/tools/fgltlib/fgltfiledlg.4gl there is a similar file dialog that uses a larger parameter list for the dialog.
|
|
|
|
Use whichever method is appropriate for you.
|