/src/wrappers/gtk/library/gtk_file_filter.e

http://github.com/tybor/Liberty · Specman e · 182 lines · 83 code · 36 blank · 63 comment · 3 complexity · d9c54d89794e7249341dd7880e2110a9 MD5 · raw file

  1. indexing
  2. description: "GtkFileFilter - used to restrict the files shown in a GtkFileChoose."
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. date: "$Date:$"
  19. revision: "$Revision:$"
  20. class GTK_FILE_FILTER
  21. -- A GtkFileFilter can be used to restrict the files being shown in
  22. -- a GtkFileChooser. Files can be filtered based on their name
  23. -- (with `add_pattern'), on their mime type (with `add_mime_type'),
  24. -- or by a custom filter function (with TODO: `add_custom').
  25. -- Filtering by mime types handles aliasing and subclassing of mime
  26. -- types; e.g. a filter for text/plain also matches a file with
  27. -- mime type application/rtf, since application/rtf is a subclass
  28. -- of text/plain. Note that GtkFileFilter allows wildcards for the
  29. -- subtype of a mime type, so you can e.g. filter for image/*.
  30. -- Normally, filters are used by adding them to a GtkFileChooser,
  31. -- see GTK_FILE_CHOOSER's `add_filter', but it is also possible to
  32. -- manually use a filter on a file with (TODO) `filter'.
  33. inherit
  34. GTK_OBJECT
  35. insert
  36. GTK_FILE_FILTER_EXTERNALS
  37. GTK_FILE_FILTER_INFO_EXTERNALS
  38. GTK_FILE_FILTER_FLAGS
  39. creation make, with_pattern, with_mime_type, from_external_pointer
  40. feature {} -- Creation
  41. make is
  42. -- Creates a new GtkFileFilter with no rules added to
  43. -- it. Such a filter doesn't accept any files, so is not
  44. -- particularly useful until you add rules with
  45. -- `add_mime_type', `add_pattern', or `add_custom'. To create
  46. -- a filter that accepts any file, use:
  47. -- create a_filter.make; a_filter.add_pattern ("*")
  48. -- See also `with_pattern', `with_mime_type'
  49. do
  50. from_external_pointer (gtk_file_filter_new)
  51. end
  52. with_pattern (a_pattern: STRING) is
  53. -- Creates a new GtkFileFilter with `a_pattern' rule.
  54. require pattern_not_void: a_pattern /= Void
  55. do
  56. make; add_pattern (a_pattern)
  57. end
  58. with_mime_type(a_mime_type: STRING) is
  59. -- Creates a new GtkFileFilter with `a_mime_type' rule
  60. require valid_mime_type: a_mime_type /= Void
  61. do
  62. make; add_mime_type(a_mime_type)
  63. end
  64. feature -- Filter name
  65. set_name (a_name: STRING) is
  66. -- Sets the human-readable name of the filter; this is the
  67. -- string that will be displayed in the file selector user
  68. -- interface if there is a selectable list of filters.
  69. require a_name /= Void
  70. do
  71. gtk_file_filter_set_name (handle, a_name.to_external)
  72. end
  73. unset_name is
  74. -- Remove any human-readable name of the filter, the string
  75. -- that will be displayed in the file selector user interface
  76. -- if there is a selectable list of filters.
  77. do
  78. gtk_file_filter_set_name (handle, default_pointer)
  79. end
  80. name: STRING is
  81. -- The human-readable name for the filter. See `set_name'.
  82. local cstr: POINTER
  83. do
  84. cstr := gtk_file_filter_get_name (handle)
  85. -- Returns : The human-readable name of the filter, or
  86. -- NULL. This value is owned by GTK+ and must not be modified
  87. -- or freed.
  88. if cstr.is_not_null
  89. then create Result.from_external_copy (cstr)
  90. end
  91. end
  92. feature -- Mime type filter
  93. add_mime_type (a_mime_type: STRING) is
  94. -- Adds a rule allowing the given `a_mime_type' to filter.
  95. require valid_mime_type: a_mime_type /= Void
  96. do
  97. gtk_file_filter_add_mime_type (handle, a_mime_type.to_external)
  98. end
  99. feature -- Pattern filter
  100. add_pattern (a_pattern: STRING) is
  101. -- Adds a rule allowing a shell style glob to a filter.
  102. require pattern_not_void: a_pattern /= Void
  103. do
  104. gtk_file_filter_add_pattern (handle, a_pattern.to_external)
  105. end
  106. feature -- Image filter
  107. add_pixbuf_formats is
  108. -- Adds a rule allowing image files in the formats supported by GdkPixbuf.
  109. do
  110. gtk_file_filter_add_pixbuf_formats (handle)
  111. end
  112. -- TODO: gtk_file_filter_add_custom ()
  113. -- void gtk_file_filter_add_custom (GtkFileFilter *filter,
  114. -- GtkFileFilterFlags needed,
  115. -- GtkFileFilterFunc func,
  116. -- gpointer data,
  117. -- GDestroyNotify notify);
  118. -- Adds rule to a filter that allows files based on a custom callback function. The bitfield needed which is passed in provides information about what sorts of information that the filter function needs; this allows GTK+ to avoid retrieving expensive information when it isn't needed by the filter.
  119. -- filter : a GtkFileFilter
  120. -- needed : bitfield of flags indicating the information that the custom filter function needs.
  121. -- func : callback function; if the function returns TRUE, then the file will be displayed.
  122. -- data : data to pass to func
  123. -- notify : function to call to free data when it is no longer needed.
  124. -- Since 2.4
  125. -- TODO gtk_file_filter_get_needed ()
  126. -- GtkFileFilterFlags gtk_file_filter_get_needed
  127. -- (GtkFileFilter *filter);
  128. -- Gets the fields that need to be filled in for the structure passed to gtk_file_filter_filter()
  129. -- This function will not typically be used by applications; it is intended principally for use in the implementation of GtkFileChooser.
  130. -- filter : a GtkFileFilter
  131. -- Returns : bitfield of flags indicating needed fields when calling gtk_file_filter_filter()
  132. -- Since 2.4
  133. -- gtk_file_filter_filter ()
  134. -- gboolean gtk_file_filter_filter (GtkFileFilter *filter,
  135. -- const GtkFileFilterInfo *filter_info);
  136. -- Tests whether a file should be displayed according to filter. The GtkFileFilterInfo structure filter_info should include the fields returned from gtk_file_filter_get_needed().
  137. -- This function will not typically be used by applications; it is intended principally for use in the implementation of GtkFileChooser.
  138. -- filter : a GtkFileFilter
  139. -- filter_info : a GtkFileFilterInfo structure containing information about a file.
  140. -- Returns : TRUE if the file should be displayed
  141. feature
  142. struct_size: INTEGER is
  143. external "C inline use <gtk/gtk.h>"
  144. alias "sizeof(GtkFileFilter)"
  145. end
  146. end