class Gtk::FileFilter
- Gtk::FileFilter
- Gtk::Filter
- GObject::Object
- Reference
- Object
Overview
Gtk::FileFilter
filters files by name or mime type.
Gtk::FileFilter
can be used to restrict the files being shown in a
Gtk::FileChooser
. Files can be filtered based on their name (with
Gtk::FileFilter#add_pattern
or Gtk::FileFilter#add_suffix
)
or on their mime type (with Gtk::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 Gtk::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 Gtk::FileChooser
(see Gtk::FileChooser#add_filter
), but it is also possible to
manually use a file filter on any Gtk::FilterListModel
containing
GFileInfo
objects.
Gtk::FileFilter as Gtk::Buildable
The Gtk::FileFilter
implementation of the Gtk::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
Gtk::FileFilter#add_mime_type
or
Gtk::FileFilter#add_pattern
or
Gtk::FileFilter#add_suffix
.
An example of a UI definition fragment specifying Gtk::FileFilter
rules:
WARNING ⚠️ The following code is in xml ⚠️
<object class="Gtk::FileFilter">
<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>
Included Modules
Defined in:
lib/gi-crystal/src/auto/gtk-4.0/file_filter.crConstructors
-
.new : self
Creates a new
Gtk::FileFilter
with no rules added to it. - .new(*, name : String? = nil)
-
.new_from_gvariant(variant : _) : self
Deserialize a file filter from a
GVariant
.
Class Method Summary
-
.g_type : UInt64
Returns the type id (GType) registered in GLib type system.
Instance Method Summary
-
#add_mime_type(mime_type : String) : Nil
Adds a rule allowing a given mime type to @filter.
-
#add_pattern(pattern : String) : 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 Gdk::Pixbuf.
-
#add_suffix(suffix : String) : Nil
Adds a suffix match rule to a filter.
-
#attributes : Enumerable(String)
Gets the attributes that need to be filled in for the
GFileInfo
passed to this filter. -
#name : String?
Gets the human-readable name for the filter.
- #name=(value : String) : String
-
#name=(name : String?) : Nil
Sets a human-readable name of the filter.
-
#to_gvariant : GLib::Variant
Serialize a file filter to an
a{sv}
variant.
Instance methods inherited from module Gtk::Buildable
buildable_id : String?
buildable_id,
to_unsafe
to_unsafe
Class methods inherited from module Gtk::Buildable
g_type : UInt64
g_type
Instance methods inherited from class Gtk::Filter
changed(change : Gtk::FilterChange) : Nil
changed,
changed_signal
changed_signal,
match(item : GObject::Object) : Bool
match,
strictness : Gtk::FilterMatch
strictness
Constructor methods inherited from class Gtk::Filter
new
new
Class methods inherited from class Gtk::Filter
g_type : UInt64
g_type
Instance methods inherited from class GObject::Object
bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding
bind_property,
bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding
bind_property_full,
data(key : String) : Pointer(Void)?
data,
finalize
finalize,
freeze_notify : Nil
freeze_notify,
getv(names : Enumerable(String), values : Enumerable(_)) : Nil
getv,
notify(property_name : String) : Nil
notify,
notify_by_pspec(pspec : GObject::ParamSpec) : Nil
notify_by_pspec,
notify_signal
notify_signal,
property(property_name : String, value : _) : Nil
property,
qdata(quark : UInt32) : Pointer(Void)?
qdata,
ref_count : UInt32
ref_count,
run_dispose : Nil
run_dispose,
set_data(key : String, data : Pointer(Void)?) : Nil
set_data,
set_property(property_name : String, value : _) : Nil
set_property,
steal_data(key : String) : Pointer(Void)?
steal_data,
steal_qdata(quark : UInt32) : Pointer(Void)?
steal_qdata,
thaw_notify : Nil
thaw_notify,
to_unsafe : Pointer(Void)
to_unsafe,
watch_closure(closure : GObject::Closure) : Nil
watch_closure
Constructor methods inherited from class GObject::Object
cast(obj : GObject::Object) : self
cast,
cast?(obj : GObject::Object) : self?
cast?,
new(pointer : Pointer(Void), transfer : GICrystal::Transfer)new new, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv
Class methods inherited from class GObject::Object
compat_control(what : UInt64, data : Pointer(Void)?) : UInt64
compat_control,
g_type : UInt64
g_type,
interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec
interface_find_property,
interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec)
interface_list_properties
Constructor Detail
Creates a new Gtk::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
Gtk::FileFilter#add_mime_type
,
Gtk::FileFilter#add_pattern
,
Gtk::FileFilter#add_suffix
or
Gtk::FileFilter#add_pixbuf_formats
.
To create a filter that accepts any file, use:
WARNING ⚠️ The following code is in c ⚠️
Gtk::FileFilter *filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, "*");
Deserialize a file filter from a GVariant
.
The variant must be in the format produced by
Gtk::FileFilter#to_gvariant
.
Class Method Detail
Instance Method Detail
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.
Adds a rule allowing image files in the formats supported by Gdk::Pixbuf.
This is equivalent to calling Gtk::FileFilter#add_mime_type
for all the supported mime types.
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.
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 Gtk::FileChooser
.
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.