Retrieving a file from an EV_FILE_OPEN_DIALOG
- Recently, we have received a few similar questions regarding retrieval of
file names from file open dialogs. Below is some sample code which
demonstrates retrieving a file name from an EV_FILE_OPEN_DIALOG:
-- Set up main window of test and display.
create dialog_button.make_with_text ("Show File Dialog")
dialog_button.select_actions.extend (agent show_file_dialog)
-- Display `file_open_dialog' modally to `a_window'
-- and connect actions on file selection.
file_open_dialog.open_actions.extend (agent process_file_name)
-- Process filename of `file_open_dialog'.
A little information regarding this example. `process_file_name' is the
feature executed to process the file name returned from the dialog. The
feature `show_file_dialog' connects `process_file_name' to the dialog in two
different ways, so you can select which method you wish to use. As a result
of this, `process_file_name' is currently executed twice.
When a dialog is displayed modally to a window, it means that the dialog
blocks all events on the window. You must close the dialog in order to be
able to manipulate the window again. This also blocks the execution of the
current code, so for example, in `show_file_dialog', we display the dialog
modally to the window in the third line, and the fourth line will not be
executed until the dialog is closed.
I hope that this is of some use.
- Dear Julian,
your code example was very helpful to me.
I understand it as follows:
It is impossible to delay opening
a file using this scheme:
(agent open_file (File_open_dialog.file_name))
because the argument
to a one-argument `open_file' procedure
is an empty string at the agent's construction
time and hence at call time, too.
I decided to go your first way (agent way):
using an agent of the argumentless procedure
-- Open the file `file_name'
-- of `File_open_dialog'
-- and print its size.
File_open_dialog.file_name /= Void
create file.make_open_read (fn)
print ("Size of open file: "
+ file.count.out + " bytes.%N")
1) Is my understanding (construction vs
call time) correct?
2) Is there a way to fill the open operand
(agent open_file (?))
Thank you very much.
- Hi Karsten,
> I understand it as follows:Yes, this is correct.
> It is impossible to delay opening
> a file using this scheme:
> (agent open_file (File_open_dialog.file_name))
> because the argument
> to a one-argument `open_file' procedure
> is an empty string at the agent's construction
> time and hence at call time, too.
> 2) Is there a way to fill the open operandNo, this is not possible. It is the responsibility of the caller to provide
> (agent open_file (?))
> during execution?
the open operands. The EiffelVision2 implementation will call `open_actions'
and does not know how to fill in your open operand for `open_actions'.
It is possible to pass a closed operand as follows:
File_open_dialog.open_actions.extend (agent open_file (File_open_dialog))
open_file (dialog: EV_FILE_OPEN_DIALOG) is
You may then query dialog.file_name to retrieve the selected filename from
the dialog. However, if you already have access to the dialog, passing the
dialog as a closed operand is unnecessary.
- Dear Julian,
thank you for the reply.
I am sure your information
is helpful for others, too.
Did you also notice message #1905 ;-)