Filters files by name or mime type.
GtkFileFilter can be used to restrict the files being shown in a file chooser. 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 file chooser (see [methodGtk.FileDialog.set_filters]), 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:
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> ```
function "+"
(Widget : access Gtk_File_Filter_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_File_Filter
procedure Add_Mime_Type
(Self : not null access Gtk_File_Filter_Record;
Mime_Type : UTF8_String)
Adds a rule allowing a given mime type.
name of a MIME type
procedure Add_Mime_Types
(Self : not null access Gtk_File_Filter_Record;
Mime_Types : GNAT.Strings.String_List)
Adds a rule allowing a given array of mime types. It can for example be used with Gly.Loader.get_mime_types. This is equivalent to calling [methodGtk.FileFilter.add_mime_type] for all the supported mime types. Since: gtk+ 4.22
a null-terminated array of mime types
procedure Add_Pattern
(Self : not null access Gtk_File_Filter_Record;
Pattern : UTF8_String)
Adds a rule allowing a shell style glob pattern. Note that it depends on the platform whether pattern matching ignores case or not. On Windows, it does, on other platforms, it doesn't.
a shell style glob pattern
procedure Add_Pixbuf_Formats
(Self : not null access Gtk_File_Filter_Record)
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. Deprecated since 4.20, 1
procedure Add_Suffix
(Self : not null access Gtk_File_Filter_Record;
Suffix : UTF8_String)
Adds a suffix match rule to a filter. This is similar to adding a match for the pattern "*.Suffix" An exaple to filter files with the suffix ".sub": c gtk_file_filter_add_suffix (filter, "sub"); Filters with multiple dots are allowed. In contrast to pattern matches, suffix matches are always case-insensitive. Since: gtk+ 4.4
filename suffix to match
function Get_Attributes
(Self : not null access Gtk_File_Filter_Record)
return GNAT.Strings.String_List
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 for use in file chooser implementation.
the attributes
function Get_Name
(Self : not null access Gtk_File_Filter_Record) return UTF8_String
Gets the human-readable name for the filter. See [methodGtk.FileFilter.set_name].
the human-readable name of the filter
function Get_Type return Glib.GType
type Gtk_File_Filter is access all Gtk_File_Filter_Record'Class;
function Gtk_File_Filter_New return Gtk_File_Filter
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 [methodGtk.FileFilter.add_mime_type], [methodGtk.FileFilter.add_pattern], [methodGtk.FileFilter.add_suffix] or [methodGtk.FileFilter.add_pixbuf_formats]. To create a filter that accepts any file, use: c GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*");
function Gtk_File_Filter_New_From_Gvariant
(Variant : Glib.Variant.Gvariant) return Gtk_File_Filter
Deserialize a file filter from a GVariant. The variant must be in the format produced by [methodGtk.FileFilter.to_gvariant].
an a{sv}GVariant
type Gtk_File_Filter_Record is new Gtk_Filter_Record with null record;
procedure Gtk_New (Self : out Gtk_File_Filter)
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 [methodGtk.FileFilter.add_mime_type], [methodGtk.FileFilter.add_pattern], [methodGtk.FileFilter.add_suffix] or [methodGtk.FileFilter.add_pixbuf_formats]. To create a filter that accepts any file, use: c GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*"); Initialize does nothing if the object was already created with another call to Initialize* or G_New.
procedure Gtk_New_From_Gvariant
(Self : out Gtk_File_Filter;
Variant : Glib.Variant.Gvariant)
Deserialize a file filter from a GVariant. The variant must be in the format produced by [methodGtk.FileFilter.to_gvariant]. Initialize_From_Gvariant does nothing if the object was already created with another call to Initialize* or G_New.
an a{sv}GVariant
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_File_Filter_Record, Gtk_File_Filter);
procedure Initialize
(Self : not null access Gtk_File_Filter_Record'Class)
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 [methodGtk.FileFilter.add_mime_type], [methodGtk.FileFilter.add_pattern], [methodGtk.FileFilter.add_suffix] or [methodGtk.FileFilter.add_pixbuf_formats]. To create a filter that accepts any file, use: c GtkFileFilter *filter = gtk_file_filter_new (); gtk_file_filter_add_pattern (filter, "*"); Initialize does nothing if the object was already created with another call to Initialize* or G_New.
procedure Initialize_From_Gvariant
(Self : not null access Gtk_File_Filter_Record'Class;
Variant : Glib.Variant.Gvariant)
Deserialize a file filter from a GVariant. The variant must be in the format produced by [methodGtk.FileFilter.to_gvariant]. Initialize_From_Gvariant does nothing if the object was already created with another call to Initialize* or G_New.
an a{sv}GVariant
Name_Property : constant Glib.Properties.Property_String;
The human-readable name of the filter.
This is the string that will be displayed in the user interface if there is a selectable list of filters.
procedure Set_Name
(Self : not null access Gtk_File_Filter_Record;
Name : UTF8_String := "")
Sets a human-readable name of the filter. This is the string that will be displayed in the user interface if there is a selectable list of filters.
the human-readable name for the filter
function To_Gvariant
(Self : not null access Gtk_File_Filter_Record)
return Glib.Variant.Gvariant
Serialize a file filter to an a{sv} variant.
a new, floating, GVariant. Has transfer-ownership='none'.