Class LanguageManager
- All Implemented Interfaces:
Proxy
Provides access to Languages.
GtkSourceLanguageManager is an object which processes language description
files and creates and stores Language objects, and provides API to
access them.
Use getDefault() to retrieve the default
instance of GtkSourceLanguageManager, and
guessLanguage(String, String) to get a Language for
given file name and content type.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLanguageManager.Builder<B extends LanguageManager.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new LanguageManager.LanguageManager(MemorySegment address) Create a LanguageManager instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendSearchPath(String path) Appendspathto the list of directories where themanagerlooks for language files.protected LanguageManagerasParent()Return this instance as if it were its parent type.static LanguageManager.Builder<? extends LanguageManager.Builder> builder()ALanguageManager.Builderobject constructs aLanguageManagerwith the specified properties.static LanguageManagerReturns the defaultGtkSourceLanguageManagerinstance.@Nullable LanguagegetLanguage(String id) Gets theLanguageidentified by the givenidin the language manager.@Nullable String @Nullable []Returns the ids of the available languages.static MemoryLayoutThe memory layout of the native struct.String[]Gets the list directories where this LanguageManager looks for language files.static @Nullable TypegetType()Get the GType of the LanguageManager class.@Nullable LanguageguessLanguage(@Nullable String filename, @Nullable String contentType) Picks aLanguagefor given file name and content type, according to the information in lang files.voidprependSearchPath(String path) Prependspathto the list of directories where themanagerlooks for language files.voidsetSearchPath(@Nullable String @Nullable [] dirs) Sets the list of directories where the this LanguageManager looks for language files.Methods 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, hashCode
-
Constructor Details
-
LanguageManager
Create a LanguageManager instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
LanguageManager
public LanguageManager()Create a new LanguageManager.
-
-
Method Details
-
getType
Get the GType of the LanguageManager class.- Returns:
- the GType
-
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. -
getDefault
Returns the defaultGtkSourceLanguageManagerinstance.- Returns:
- a
GtkSourceLanguageManager. Return value is owned by GtkSourceView library and must not be unref'ed.
-
appendSearchPath
Appends
pathto the list of directories where themanagerlooks for language files.See
setSearchPath(String[])for details.- Parameters:
path- a directory or a filename.- Since:
- 5.4
-
getLanguage
Gets theLanguageidentified by the givenidin the language manager.- Parameters:
id- a language id.- Returns:
- a
GtkSourceLanguage, ornullif there is no language identified by the givenid.Return value is owned by this LanguageManager and should not be freed.
-
getLanguageIds
Returns the ids of the available languages.- Returns:
- a
null-terminated array of strings containing the ids of the available languages ornullif no language is available. The array is sorted alphabetically according to the language name. The array is owned by this LanguageManager and must not be modified.
-
getSearchPath
Gets the list directories where this LanguageManager looks for language files.- Returns:
null-terminated array containing a list of language files directories. The array is owned by this LanguageManager and must not be modified.
-
guessLanguage
Picks a
Languagefor given file name and content type, according to the information in lang files.Either
filenameorcontentTypemay benull. This function can be used as follows:GtkSourceLanguage *lang; GtkSourceLanguageManager *manager; lm = gtk_source_language_manager_get_default (); lang = gtk_source_language_manager_guess_language (manager, filename, NULL); gtk_source_buffer_set_language (buffer, lang);manager = GtkSource.LanguageManager.get_default() language = manager.guess_language(filename=filename, content_type=None) buffer.set_language(language=language)or
GtkSourceLanguage *lang = NULL; GtkSourceLanguageManager *manager; gboolean result_uncertain; gchar *content_type; content_type = g_content_type_guess (filename, NULL, 0, &result_uncertain); if (result_uncertain) { g_free (content_type); content_type = NULL; } manager = gtk_source_language_manager_get_default (); lang = gtk_source_language_manager_guess_language (manager, filename, content_type); gtk_source_buffer_set_language (buffer, lang); g_free (content_type);content_type, uncertain = Gio.content_type_guess(filename=filename, data=None) if uncertain: content_type = None manager = GtkSource.LanguageManager.get_default() language = manager.guess_language(filename=filename, content_type=content_type) buffer.set_language(language=language)etc. Use
Language.getMimeTypes()andLanguage.getGlobs()if you need full control over file -> language mapping.- Parameters:
filename- a filename in Glib filename encoding, ornull.contentType- a content type (as in GIO API), ornull.- Returns:
- a
GtkSourceLanguage, ornullif there is no suitable language for givenfilenameand/orcontentType.Return value is owned by this LanguageManager and should not be freed.
-
prependSearchPath
Prepends
pathto the list of directories where themanagerlooks for language files.See
setSearchPath(String[])for details.- Parameters:
path- a directory or a filename.- Since:
- 5.4
-
setSearchPath
Sets the list of directories where the this LanguageManager looks for language files.
If
dirsisnull, the search path is reset to default.At the moment this function can be called only before the language files are loaded for the first time. In practice to set a custom search path for a
GtkSourceLanguageManager, you have to call this function right after creating it.Since GtkSourceView 5.4 this function will allow you to provide paths in the form of "resource:///" URIs to embedded
GResources. They must contain the path of a directory within theGResource.- Parameters:
dirs- anull-terminated array of strings ornull.
-
builder
ALanguageManager.Builderobject constructs aLanguageManagerwith the specified properties. Use the variousset...()methods to set properties, and finish construction withLanguageManager.Builder.build().- Returns:
- the builder object
-