Class FileFilter
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
addPattern(String) or addSuffix(String))
or on their mime type (with addMimeType(String)).
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 FileDialog.setFilters(ListModel)), but it is also possible to
manually use a file filter on any 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
addMimeType(String) or
addPattern(String) or
addSuffix(String).
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>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFileFilter.Builder<B extends FileFilter.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class Filter
Filter.ChangedCallback, Filter.FilterClassNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface Buildable
Buildable.Buildable$Impl, Buildable.BuildableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new FileFilter.FileFilter(MemorySegment address) Create a FileFilter instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMimeType(String mimeType) Adds a rule allowing a given mime type.voidaddMimeTypes(@Nullable String @Nullable [] mimeTypes) Adds a rule allowing a given array of mime types.voidaddPattern(String pattern) Adds a rule allowing a shell style glob pattern.voidDeprecated.Use the api of your image loading framework (e.g. glycin) to enumerate supported formatsvoidAdds a suffix match rule to a filter.protected FileFilterasParent()Return this instance as if it were its parent type.static FileFilter.Builder<? extends FileFilter.Builder> builder()AFileFilter.Builderobject constructs aFileFilterwith the specified properties.static FileFilterfromGvariant(Variant variant) Deserialize a file filter from aGVariant.String[]Gets the attributes that need to be filled in for theGFileInfopassed to this filter.static MemoryLayoutThe memory layout of the native struct.@Nullable StringgetName()Gets the human-readable name for the filter.static @Nullable TypegetType()Get the GType of the FileFilter class.voidSets a human-readable name of the filter.Serialize a file filter to ana{sv}variant.Methods inherited from class Filter
changed, emitChanged, getStrictness, match, onChangedMethods inherited from class GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Buildable
getBuildableId
-
Constructor Details
-
FileFilter
Create a FileFilter instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
FileFilter
public FileFilter()Create a new FileFilter.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
fromGvariant
Deserialize a file filter from a
GVariant.The variant must be in the format produced by
toGvariant().- Parameters:
variant- ana{sv}GVariant- Returns:
- a new
GtkFileFilterobject
-
addMimeType
Adds a rule allowing a given mime type.- Parameters:
mimeType- name of a MIME type
-
addMimeTypes
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
addMimeType(String)for all the supported mime types.- Parameters:
mimeTypes- anull-terminated array of mime types- Since:
- 4.22
-
addPattern
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.
- Parameters:
pattern- a shell style glob pattern
-
addPixbufFormats
Deprecated.Use the api of your image loading framework (e.g. glycin) to enumerate supported formatsAdds a rule allowing image files in the formats supported by
GdkPixbuf.This is equivalent to calling
addMimeType(String)for all the supported mime types. -
addSuffix
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":
gtk_file_filter_add_suffix (filter, "sub");Filters with multiple dots are allowed.
In contrast to pattern matches, suffix matches are always case-insensitive.
- Parameters:
suffix- filename suffix to match- Since:
- 4.4
-
getAttributes
Gets the attributes that need to be filled in for the
GFileInfopassed to this filter.This function will not typically be used by applications; it is intended for use in file chooser implementation.
- Returns:
- the attributes
-
getName
Gets the human-readable name for the filter.
See
setName(String).- Returns:
- the human-readable name of the filter
-
setName
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.
- Parameters:
name- the human-readable name for the filter
-
toGvariant
Serialize a file filter to ana{sv}variant.- Returns:
- a new, floating,
GVariant
-
builder
AFileFilter.Builderobject constructs aFileFilterwith the specified properties. Use the variousset...()methods to set properties, and finish construction withFileFilter.Builder.build().- Returns:
- the builder object
-