Gnome::Gtk4::FileFilter
Description
Gnome::Gtk4::FileFilter filters files by name or mime type.
Gnome::Gtk4::FileFilter can be used to restrict the files being shown in a Gnome::Gtk4::R-FileChooser. Files can be filtered based on their name (with .add-pattern()
or .add-suffix()
) or on their mime type (with .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 Gnome::Gtk4::FileFilter 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 Gnome::Gtk4::R-FileChooser (see .add-filter() in class Gnome::Gtk4::R-FileChooser
), but it is also possible to manually use a file filter on any Gnome::Gtk4::FilterListModel containing Gnome::Gio::FileInfo objects.
GtkFileFilter as GtkBuildable
The Gnome::Gtk4::FileFilter implementation of the Gnome::Gtk4::R-Buildable 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 .add-mime-type()
or .add-pattern()
or .add-suffix()
.
An example of a UI definition fragment specifying Gnome::Gtk4::FileFilter rules:
Class initialization
new
:native-object
Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object :$native-object! )
new-filefilter
Creates a new Gnome::Gtk4::FileFilter with no rules added to it.
Such a filter doesn’t accept any files, so is not particularly useful until you add rules with .add-mime-type()
, .add-pattern()
, .add-suffix()
or .add-pixbuf-formats()
.
To create a filter that accepts any file, use:
method new-filefilter ( --> Gnome::Gtk4::FileFilter \)
new-from-gvariant
Deserialize a file filter from a Gnome::Glib::N-Variant.
The variant must be in the format produced by .to-gvariant()
.
method new-from-gvariant ( N-Object $variant --> Gnome::Gtk4::FileFilter \)
$variant; an a{sv}` Gnome::Glib::N-Variant
Methods
add-mime-type
Adds a rule allowing a given mime type to $filter
.
method add-mime-type ( Str $mime-type )
$mime-type; name of a MIME type.
add-pattern
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.
method add-pattern ( Str $pattern )
$pattern; a shell style glob.
add-pixbuf-formats
Adds a rule allowing image files in the formats supported by GdkPixbuf.
This is equivalent to calling .add-mime-type()
for all the supported mime types.
method add-pixbuf-formats ( )
add-suffix
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.
method add-suffix ( Str $suffix )
$suffix; filename suffix to match.
get-attributes
Gets the attributes that need to be filled in for the Gnome::Gio::FileInfo passed to this filter.
This function will not typically be used by applications; it is intended principally for use in the implementation of Gnome::Gtk4::R-FileChooser.
method get-attributes (--> Array[Str] )
Return value; the attributes.
get-name
Gets the human-readable name for the filter.
See .set-name()
.
method get-name (--> Str )
Return value; The human-readable name of the filter.
set-name
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.
method set-name ( Str $name )
$name; the human-readable-name for the filter, or undefined to remove any existing name..
to-gvariant
Serialize a file filter to an a{sv}` variant.
method to-gvariant (--> N-Object )
Return value; a new, floating, Gnome::Glib::N-Variant.