FileFilterProtocol

public protocol FileFilterProtocol : BuildableProtocol, FilterProtocol

GtkFileFilter filters files by name or mime type.

GtkFileFilter can be used to restrict the files being shown in a GtkFileChooser. Files can be filtered based on their name (with [methodGtk.FileFilter.add_pattern] or [methodGtk.FileFilter.add_suffix]) or on their mime type (with [methodGtk.FileFilter.add_mime_type]).

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, file filters are used by adding them to a GtkFileChooser (see [methodGtk.FileChooser.add_filter]), but it is also possible to manually use a file filter on any [classGtk.FilterListModel] containing GFileInfo objects.

GtkFileFilter as GtkBuildable

The GtkFileFilter implementation of the GtkBuildable interface supports adding rules using the <mime-types> and <patterns> and <suffixes> elements and listing the rules within. Specifying a <mime-type> or <pattern> or <suffix> has the same effect as as calling [methodGtk.FileFilter.add_mime_type] or [methodGtk.FileFilter.add_pattern] or [methodGtk.FileFilter.add_suffix].

An example of a UI definition fragment specifying GtkFileFilter rules:

<object class="GtkFileFilter">
  <property name="name" translatable="yes">Text and Images</property>
  <mime-types>
    <mime-type>text/plain</mime-type>
    <mime-type>image/ *</mime-type>
  </mime-types>
  <patterns>
    <pattern>*.txt</pattern>
  </patterns>
  <suffixes>
    <suffix>png</suffix>
  </suffixes>
</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

  • Bind a FileFilterPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: FileFilterPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a FileFilter property

    Declaration

    Swift

    @inlinable
    func get(property: FileFilterPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a FileFilter property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: FileFilterPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

FileFilter Class: FileFilterProtocol extension (methods and fields)

  • add(mimeType:) Extension method

    Adds a rule allowing a given mime type to filter.

    Declaration

    Swift

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

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

    Note that it depends on the platform whether pattern matching ignores case or not. On Windows, it does, on other platforms, it doesn’t.

    Declaration

    Swift

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

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

    This is equivalent to calling [methodGtk.FileFilter.add_mime_type] for all the supported mime types.

    Declaration

    Swift

    @inlinable
    func addPixbufFormats()
  • add(suffix:) Extension method

    Adds a suffix match rule to a filter.

    This is similar to adding a match for the pattern “*.suffix”.

    In contrast to pattern matches, suffix matches are always case-insensitive.

    Declaration

    Swift

    @inlinable
    func add(suffix: UnsafePointer<CChar>!)
  • getAttributes() Extension method

    Gets the attributes that need to be filled in for the GFileInfo passed to this 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 getAttributes() -> UnsafeMutablePointer<UnsafePointer<CChar>?>!
  • getName() Extension method

    Gets the human-readable name for the filter.

    See [methodGtk.FileFilter.set_name].

    Declaration

    Swift

    @inlinable
    func getName() -> String!
  • set(name:) Extension method

    Sets a human-readable name of the filter.

    This is the string that will be displayed in the file chooser if there is a selectable list of filters.

    Declaration

    Swift

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

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

    Declaration

    Swift

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

    Gets the attributes that need to be filled in for the GFileInfo passed to this 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 attributes: UnsafeMutablePointer<UnsafePointer<CChar>?>! { get }
  • name Extension method

    The human-readable name of the filter.

    This is the string that will be displayed in the file chooser user interface if there is a selectable list of filters.

    Declaration

    Swift

    @inlinable
    var name: String! { get nonmutating set }