FileFilterProtocol

public protocol FileFilterProtocol : InitiallyUnownedProtocol, BuildableProtocol

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_add_pattern()), on their mime type (with gtk_file_filter_add_mime_type()), or by a custom filter function (with gtk_file_filter_add_custom()).

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_add_filter(), but it is also possible to manually use a filter on a file with gtk_file_filter_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_add_mime_type() or gtk_file_filter_add_pattern().

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>

The FileFilterProtocol protocol exposes the methods and properties of an underlying GtkFileFilter instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see FileFilter. Alternatively, use FileFilterRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkFileFilter instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • file_filter_ptr Default implementation

    Typed pointer to the underlying GtkFileFilter instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkFileFilter instance.

    Declaration

    Swift

    var file_filter_ptr: UnsafeMutablePointer<GtkFileFilter>! { get }
  • Required Initialiser for types conforming to FileFilterProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

FileFilter Class: FileFilterProtocol extension (methods and fields)

  • 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.

    Declaration

    Swift

    @inlinable
    func addCustom(needed: FileFilterFlags, func: GtkFileFilterFunc?, data: gpointer! = nil, notify: GDestroyNotify?)
  • add(mimeType:) Extension method

    Adds a rule allowing a given mime type to filter.

    Declaration

    Swift

    @inlinable
    func add(mimeType: UnsafePointer<gchar>!)
  • add(pattern:) Extension method

    Adds a rule allowing a shell style glob to a filter.

    Declaration

    Swift

    @inlinable
    func add(pattern: UnsafePointer<gchar>!)
  • addPixbufFormats() Extension method

    Adds a rule allowing image files in the formats supported by GdkPixbuf.

    Declaration

    Swift

    @inlinable
    func addPixbufFormats()
  • filter(filterInfo:) Extension method

    Tests whether a file should be displayed according to filter. The GtkFileFilterInfo filter_info should include the fields returned from gtk_file_filter_get_needed().

    This function will not typically be used by applications; it is intended principally for use in the implementation of GtkFileChooser.

    Declaration

    Swift

    @inlinable
    func filter<FileFilterInfoT>(filterInfo: FileFilterInfoT) -> Bool where FileFilterInfoT : FileFilterInfoProtocol
  • getName() Extension method

    Gets the human-readable name for the filter. See gtk_file_filter_set_name().

    Declaration

    Swift

    @inlinable
    func getName() -> String!
  • getNeeded() Extension method

    Gets the fields that need to be filled in for the GtkFileFilterInfo passed to gtk_file_filter_filter()

    This function will not typically be used by applications; it is intended principally for use in the implementation of GtkFileChooser.

    Declaration

    Swift

    @inlinable
    func getNeeded() -> FileFilterFlags
  • set(name:) Extension method

    Sets the human-readable name of the filter; this is the string that will be displayed in the file selector user interface if there is a selectable list of filters.

    Declaration

    Swift

    @inlinable
    func set(name: UnsafePointer<gchar>? = nil)
  • toGvariant() Extension method

    Serialize a file filter to an a{sv} variant.

    Declaration

    Swift

    @inlinable
    func toGvariant() -> GLib.VariantRef!
  • name Extension method

    Gets the human-readable name for the filter. See gtk_file_filter_set_name().

    Declaration

    Swift

    @inlinable
    var name: String! { get nonmutating set }
  • needed Extension method

    Gets the fields that need to be filled in for the GtkFileFilterInfo passed to gtk_file_filter_filter()

    This function will not typically be used by applications; it is intended principally for use in the implementation of GtkFileChooser.

    Declaration

    Swift

    @inlinable
    var needed: FileFilterFlags { get }