iup_get_file.e 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.head(1).is_equal("/") 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 := get_pointer(filename.to_c)
  53. i := int_get_file(p)
  54. create fl.make_from_c(p)
  55. tup := [i, fl]
  56. Result := tup
  57. end
  58. feature {NONE}
  59. filename: STRING
  60. -- Internal
  61. int_get_file (fn: POINTER): INTEGER
  62. external
  63. "C inline use %"eiffel-iup.h%""
  64. alias
  65. "return IupGetFile ($fn);"
  66. end
  67. end
  68. -- The MIT License (MIT)
  69. -- Copyright (c) 2016, 2017, 2019 by German A. Arias
  70. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  71. -- of this software and associated documentation files (the "Software"), to deal
  72. -- in the Software without restriction, including without limitation the rights
  73. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  74. -- copies of the Software, and to permit persons to whom the Software is
  75. -- furnished to do so, subject to the following conditions:
  76. --
  77. -- The above copyright notice and this permission notice shall be included in
  78. -- all copies or substantial portions of the Software.
  79. --
  80. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  81. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  82. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  83. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  84. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  85. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  86. -- SOFTWARE.