iup_get_file.e 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. class IUP_GET_FILE
  2. -- Shows a modal dialog of the native interface system to select a filename.
  3. -- Uses the IUP_FILE_DIALOG element.
  4. --
  5. -- The function does not allocate memory space to store the complete filename
  6. -- entered by the user. Therefore, the filename parameter must be large enough
  7. -- to contain the directory and file names. The string is limited to 4096
  8. -- characters.
  9. --
  10. -- The function will reuse the directory from one call to another, so in the
  11. -- next call will open in the directory of the last selected file.
  12. --
  13. -- The dialog uses a global attribute called "PARENTDIALOG" as the parent
  14. -- dialog if it is defined. It also uses a global attribute called "ICON" as
  15. -- the dialog icon if it is defined.
  16. --
  17. -- For a more controlled dialog use directly the IUP_FILE_DIALOG element.
  18. inherit
  19. IUP_WIDGET
  20. create {ANY}
  21. get_file
  22. feature {ANY}
  23. get_file (dir, filter: STRING)
  24. -- dir parameter is used to define the default directory, for
  25. -- example "../docs/". And filter is used to define the default
  26. -- filter, for example "*.txt".
  27. do
  28. create filename.make(4096)
  29. if dir.has_suffix("/") then
  30. filename.append_string(dir)
  31. filename.append_string(filter)
  32. else
  33. filename.append_string(dir)
  34. filename.append_string("/")
  35. filename.append_string(filter)
  36. end
  37. end
  38. launch: TUPLE[INTEGER, STRING]
  39. -- Returns: a status code, whose values can be:
  40. --
  41. -- "1": New file.
  42. -- "0": Normal, existing file.
  43. -- "-1": Operation cancelled.
  44. --
  45. -- And the selected file.
  46. local
  47. p: POINTER
  48. i: INTEGER
  49. fl: STRING
  50. tup: TUPLE[INTEGER, STRING]
  51. do
  52. p := filename.to_external
  53. i := int_get_file(p)
  54. create fl.from_external_copy(p)
  55. tup := [i, fl]
  56. Result := tup
  57. end
  58. feature {}
  59. filename: STRING
  60. -- Internal
  61. int_get_file (fn: POINTER): INTEGER
  62. external "plug_in"
  63. alias "{
  64. location: "${sys}/plugins"
  65. module_name: "iup"
  66. feature_name: "IupGetFile"
  67. }"
  68. end
  69. end
  70. -- The MIT License (MIT)
  71. -- Copyright (c) 2016, 2017 by German A. Arias
  72. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  73. -- of this software and associated documentation files (the "Software"), to deal
  74. -- in the Software without restriction, including without limitation the rights
  75. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  76. -- copies of the Software, and to permit persons to whom the Software is
  77. -- furnished to do so, subject to the following conditions:
  78. --
  79. -- The above copyright notice and this permission notice shall be included in
  80. -- all copies or substantial portions of the Software.
  81. --
  82. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  83. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  84. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  85. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  86. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  87. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  88. -- SOFTWARE.