FileFilter

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>

Constructors

this
this(void* ptr, Flag!"Take" take)
this
this()

Creates a new #GtkFileFilter with no rules added to it. Such a filter doesn’t accept any files, so is not particularly useful until you add rules with gtk.file_filter.FileFilter.addMimeType, gtk.file_filter.FileFilter.addPattern, or gtk.file_filter.FileFilter.addCustom. To create a filter that accepts any file, use:

Members

Functions

addCustom
void addCustom(gtk.types.FileFilterFlags needed, gtk.types.FileFilterFunc func)

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.

addMimeType
void addMimeType(string mimeType)

Adds a rule allowing a given mime type to filter.

addPattern
void addPattern(string pattern)

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

addPixbufFormats
void addPixbufFormats()

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

filter
bool filter(gtk.file_filter_info.FileFilterInfo filterInfo)

Tests whether a file should be displayed according to filter. The #GtkFileFilterInfo filter_info should include the fields returned from gtk.file_filter.FileFilter.getNeeded.

getName
string getName()

Gets the human-readable name for the filter. See gtk.file_filter.FileFilter.setName.

getNeeded
gtk.types.FileFilterFlags getNeeded()

Gets the fields that need to be filled in for the #GtkFileFilterInfo passed to gtk.file_filter.FileFilter.filter

self
FileFilter self()

Returns this, for use in with statements.

setName
void setName(string name)

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.

toGvariant
glib.variant.Variant toGvariant()

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

Properties

_gType
GType _gType [@property getter]

Static functions

_getGType
GType _getGType()
builder
FileFilterGidBuilder builder()

Get builder for gtk.file_filter.FileFilter

newFromGvariant
gtk.file_filter.FileFilter newFromGvariant(glib.variant.Variant variant)

Deserialize a file filter from an a{sv} variant in the format produced by gtk.file_filter.FileFilter.toGvariant.

Mixed In Members

From mixin BuildableT!()

addChild
void addChild(gtk.builder.Builder builder, gobject.object.ObjectWrap child, string type)

Adds a child to buildable. type is an optional string describing how the child should be added.

constructChild
gobject.object.ObjectWrap constructChild(gtk.builder.Builder builder, string name)

Constructs a child of buildable with the name name.

customFinished
void customFinished(gtk.builder.Builder builder, gobject.object.ObjectWrap child, string tagname, void* data)

This is similar to gtk.buildable.Buildable.parserFinished but is called once for each custom tag handled by the buildable.

customTagStart
bool customTagStart(gtk.builder.Builder builder, gobject.object.ObjectWrap child, string tagname, glib.types.MarkupParser parser, void* data)

This is called for each unknown element under <child>.

getInternalChild
gobject.object.ObjectWrap getInternalChild(gtk.builder.Builder builder, string childname)

Get the internal child called childname of the buildable object.

getName
string getName()

Gets the name of the buildable object.

parserFinished
void parserFinished(gtk.builder.Builder builder)

Called when the builder finishes the parsing of a [GtkBuilder UI definition][BUILDER-UI]. Note that this will be called once for each time gtk.builder.Builder.addFromFile or gtk.builder.Builder.addFromString is called on a builder.

setBuildableProperty
void setBuildableProperty(gtk.builder.Builder builder, string name, gobject.value.Value value)

Sets the property name name to value on the buildable object.

setName
void setName(string name)

Sets the name of the buildable object.

Inherited Members

From InitiallyUnowned

_getGType
GType _getGType()
_gType
GType _gType [@property getter]
self
InitiallyUnowned self()

Returns this, for use in with statements.

builder
InitiallyUnownedGidBuilder builder()

Get builder for gobject.initially_unowned.InitiallyUnowned

From Buildable

_getGType
GType _getGType()
addChild
void addChild(gtk.builder.Builder builder, gobject.object.ObjectWrap child, string type)

Adds a child to buildable. type is an optional string describing how the child should be added.

constructChild
gobject.object.ObjectWrap constructChild(gtk.builder.Builder builder, string name)

Constructs a child of buildable with the name name.

customFinished
void customFinished(gtk.builder.Builder builder, gobject.object.ObjectWrap child, string tagname, void* data)

This is similar to gtk.buildable.Buildable.parserFinished but is called once for each custom tag handled by the buildable.

customTagStart
bool customTagStart(gtk.builder.Builder builder, gobject.object.ObjectWrap child, string tagname, glib.types.MarkupParser parser, void* data)

This is called for each unknown element under <child>.

getInternalChild
gobject.object.ObjectWrap getInternalChild(gtk.builder.Builder builder, string childname)

Get the internal child called childname of the buildable object.

getName
string getName()

Gets the name of the buildable object.

parserFinished
void parserFinished(gtk.builder.Builder builder)

Called when the builder finishes the parsing of a [GtkBuilder UI definition][BUILDER-UI]. Note that this will be called once for each time gtk.builder.Builder.addFromFile or gtk.builder.Builder.addFromString is called on a builder.

setBuildableProperty
void setBuildableProperty(gtk.builder.Builder builder, string name, gobject.value.Value value)

Sets the property name name to value on the buildable object.

setName
void setName(string name)

Sets the name of the buildable object.