Class: Gtk::FileFilter
- Extended by:
- GLib::Deprecatable
- Defined in:
- lib/gtk4/deprecated.rb
Overview
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>
Instance Method Summary collapse
-
#add_mime_type(mime_type) ⇒ nil
Adds a rule allowing a given mime type to filter.
-
#add_pattern(pattern) ⇒ nil
Adds a rule allowing a shell style glob to a filter.
-
#add_pixbuf_formats ⇒ nil
Adds a rule allowing image files in the formats supported by GdkPixbuf.
-
#add_suffix(suffix) ⇒ nil
Adds a suffix match rule to a filter.
-
#attributes ⇒ Array<String>
Gets the attributes that need to be filled in for the
GFileInfopassed to this filter. -
#initialize(variant) ⇒ Gtk::FileFilter
constructor
Deserialize a file filter from a
GVariant. -
#mime_types=(mime_types) ⇒ Gtk::
The MIME types that this filter matches.
-
#name ⇒ String
The human-readable name of the filter.
-
#name=(name) ⇒ String
The human-readable name of the filter.
-
#patterns=(patterns) ⇒ Gtk::
The patterns that this filter matches.
-
#suffixes=(suffixes) ⇒ Gtk::
The suffixes that this filter matches.
-
#to_gvariant ⇒ GLib::Variant
Serialize a file filter to an
a{sv}variant.
Methods inherited from Filter
Constructor Details
#initialize(variant) ⇒ Gtk::FileFilter
Deserialize a file filter from a GVariant.
The variant must be in the format produced by [methodGtk.FileFilter.to_gvariant].
Instance Method Details
#add_mime_type(mime_type) ⇒ nil
Adds a rule allowing a given mime type to filter.
#add_pattern(pattern) ⇒ nil
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.
#add_pixbuf_formats ⇒ nil
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.
#add_suffix(suffix) ⇒ nil
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.
#attributes ⇒ Array<String>
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.
#mime_types=(mime_types) ⇒ Gtk::
The MIME types that this filter matches.
#name ⇒ String
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.
#name=(name) ⇒ String
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.
#patterns=(patterns) ⇒ Gtk::
The patterns that this filter matches.
#suffixes=(suffixes) ⇒ Gtk::
The suffixes that this filter matches.
#to_gvariant ⇒ GLib::Variant
Serialize a file filter to an a{sv} variant.