FileFilter


Object Hierarchy:

Gtk.FileFilter Gtk.FileFilter Gtk.FileFilter GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.FileFilter GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.FileFilter

Description:

[ CCode ( type_id = "gtk_file_filter_get_type ()" ) ]
public sealed class FileFilter : InitiallyUnowned, Buildable

A GtkFileFilter can be used to restrict the files being shown in a FileChooser.

Files can be filtered based on their name (with add_pattern), on their mime type (with add_mime_type), or by a custom filter function (with 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 FileFilter 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 FileChooser, see add_filter, but it is also possible to manually use a filter on a file with 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 add_mime_type or 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>

Example: FileFilter:

public static int main (string[] args) {
Gtk.init (ref args);

Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog ("Select a File", null, Gtk.FileChooserAction.OPEN);

Gtk.FileFilter filter = new Gtk.FileFilter ();
filter.set_filter_name ("All Files");
filter.add_pattern ("*");
dialog.add_filter (filter);

filter = new Gtk.FileFilter ();
filter.set_filter_name ("Images");
filter.add_pattern ("*.png");
filter.add_pattern ("*.jpg");
filter.add_pattern ("*.bmp");
dialog.add_filter (filter);

filter = new Gtk.FileFilter ();
filter.set_filter_name ("Audio");
filter.add_pattern ("*.ogg");
filter.add_pattern ("*.flac");
dialog.add_filter (filter);

dialog.run ();
dialog.destroy ();
return 0;
}

valac --pkg gtk+-3.0 Gtk.FileFilter.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Creation methods:

Methods:

Inherited Members: