GtkFileFilter

A GtkFileFilter can be used to restrict the files being shown in a #GtkFileChooser. Files can be filtered based on their name (with gtk.file_filter.FileFilter.addPattern), on their mime type (with gtk.file_filter.FileFilter.addMimeType), or by a custom filter function (with gtk.file_filter.FileFilter.addCustom).

Filtering by mime types handles aliasing and subclassing of mime types; e.g. a filter for text/plain also matches a file with mime type application/rtf, since application/rtf is a subclass of text/plain. Note that #GtkFileFilter allows wildcards for the subtype of a mime type, so you can e.g. filter for image/\*.

Normally, filters are used by adding them to a #GtkFileChooser, see gtk.file_chooser.FileChooser.addFilter, but it is also possible to manually use a filter on a file with gtk.file_filter.FileFilter.filter.

GtkFileFilter as GtkBuildable

The GtkFileFilter implementation of the GtkBuildable interface supports adding rules using the <mime-types>, <patterns> and <applications> elements and listing the rules within. Specifying a <mime-type> or <pattern> has the same effect as as calling gtk.file_filter.FileFilter.addMimeType or gtk.file_filter.FileFilter.addPattern.

An example of a UI definition fragment specifying GtkFileFilter rules:

<object class="GtkFileFilter">
  <mime-types>
    <mime-type>text/plain</mime-type>
    <mime-type>image/ *</mime-type>
  </mime-types>
  <patterns>
    <pattern>*.txt</pattern>
    <pattern>*.png</pattern>
  </patterns>
</object>
struct GtkFileFilter