Loading ...
Sorry, an error occurred while loading the content.
 

Retrieving a file from an EV_FILE_OPEN_DIALOG

Expand Messages
  • Julian Rogers [ES]
    Recently, we have received a few similar questions regarding retrieval of file names from file open dialogs. Below is some sample code which demonstrates
    Message 1 of 6 , Sep 2, 2002
      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:

      file_open_dialog: EV_PRINT_DIALOG
      a_window: EV_TITLED_WINDOW
      dialog_button: EV_BUTTON

      file_open_dialog_test is
      -- Set up main window of test and display.
      do
      create dialog_button.make_with_text ("Show File Dialog")
      create a_window
      a_window.extend (dialog_button)
      dialog_button.select_actions.extend (agent show_file_dialog)
      create dialog
      a_window.show
      end

      show_file_dialog is
      -- Display `file_open_dialog' modally to `a_window'
      -- and connect actions on file selection.
      do
      create file_open_dialog
      file_open_dialog.open_actions.extend (agent process_file_name)
      file_open_dialog.show_modal_to_window (a_window)
      process_file_name
      end

      process_file_name is
      -- Process filename of `file_open_dialog'.
      do
      io.putstring (file_open_dialog.file_name)
      end

      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.

      Julian
    • Karsten Heusser
      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:
      Message 2 of 6 , May 5, 2003
        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:
        File_open_dialog.open_actions.extend
        (agent open_file (File_open_dialog.file_name))
        because the argument
        `File_open_dialog.file_name'
        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):

        File_open_dialog.open_actions.extend
        (agent open_file)

        using an agent of the argumentless procedure
        `open_file'.

        --

        file: RAW_FILE

        open_file is
        -- Open the file `file_name'
        -- of `File_open_dialog'
        -- and print its size.
        require
        file_name_exists:
        File_open_dialog.file_name /= Void
        file_name_not_empty:
        not File_open_dialog.file_name.is_empty
        local
        fn: FILE_NAME
        do
        create fn.make_from_string
        (File_open_dialog.file_name)
        create file.make_open_read (fn)
        print ("Size of open file: "
        + file.count.out + " bytes.%N")
        end

        --

        1) Is my understanding (construction vs
        call time) correct?
        2) Is there a way to fill the open operand
        File_open_dialog.open_actions.extend
        (agent open_file (?))
        during execution?

        Thank you very much.
        Karsten
      • Julian Rogers [ES]
        Hi Karsten, ... Yes, this is correct. ... No, this is not possible. It is the responsibility of the caller to provide the open operands. The EiffelVision2
        Message 3 of 6 , May 5, 2003
          Hi Karsten,

          > I understand it as follows:
          > It is impossible to delay opening
          > a file using this scheme:
          > File_open_dialog.open_actions.extend
          > (agent open_file (File_open_dialog.file_name))
          > because the argument
          > `File_open_dialog.file_name'
          > to a one-argument `open_file' procedure
          > is an empty string at the agent's construction
          > time and hence at call time, too.

          Yes, this is correct.

          > 2) Is there a way to fill the open operand
          > File_open_dialog.open_actions.extend
          > (agent open_file (?))
          > during execution?

          No, this is not possible. It is the responsibility of the caller to provide
          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.

          Julian
        • Karsten Heusser
          Dear Julian, thank you for the reply. I am sure your information is helpful for others, too. Did you also notice message #1905 ;-) Regards, Karsten
          Message 4 of 6 , May 6, 2003
            Dear Julian,

            thank you for the reply.
            I am sure your information
            is helpful for others, too.

            Did you also notice message #1905 ;-)

            Regards,
            Karsten
          Your message has been successfully submitted and would be delivered to recipients shortly.