Class LanguageManager
- All Implemented Interfaces:
Proxy
Language
s.
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(java.lang.String, java.lang.String)
to get a Language
for
given file name and content type.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
LanguageManager.Builder<B extends LanguageManager.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCreates a new language manager.LanguageManager
(MemorySegment address) Create a LanguageManager proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendSearchPath
(String path) Appendspath
to the list of directories where themanager
looks for language files.protected LanguageManager
asParent()
Returns this instance as if it were its parent type.static LanguageManager.Builder
<? extends LanguageManager.Builder> builder()
ALanguageManager.Builder
object constructs aLanguageManager
with the specified properties.static LanguageManager
Returns the defaultGtkSourceLanguageManager
instance.getLanguage
(String id) Gets theLanguage
identified by the givenid
in the language manager.String[]
Returns the ids of the available languages.String[]
Gets the list directories where this LanguageManager looks for language files.static Type
getType()
Get the GType of the LanguageManager classguessLanguage
(@Nullable String filename, @Nullable String contentType) Picks aLanguage
for given file name and content type, according to the information in lang files.void
prependSearchPath
(String path) Prependspath
to the list of directories where themanager
looks for language files.void
setSearchPath
(@Nullable String[] dirs) Sets the list of directories where the this LanguageManager looks for language files.Methods inherited from class org.gnome.gobject.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, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
LanguageManager
Create a LanguageManager proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
LanguageManager
public LanguageManager()Creates a new language manager.If you do not need more than one language manager or a private language manager instance then use
getDefault()
instead.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getDefault
Returns the defaultGtkSourceLanguageManager
instance.- Returns:
- a
GtkSourceLanguageManager
. Return value is owned by GtkSourceView library and must not be unref'ed.
-
appendSearchPath
Appendspath
to the list of directories where themanager
looks for language files.See
setSearchPath(java.lang.String[])
for details.- Parameters:
path
- a directory or a filename.
-
getLanguage
Gets theLanguage
identified by the givenid
in the language manager.- Parameters:
id
- a language id.- Returns:
- a
GtkSourceLanguage
, ornull
if 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 ornull
if 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
public Language guessLanguage(@Nullable @Nullable String filename, @Nullable @Nullable String contentType) Picks aLanguage
for given file name and content type, according to the information in lang files.Either
filename
orcontentType
may 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);
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);
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
, ornull
if there is no suitable language for givenfilename
and/orcontentType
. Return value is owned by this LanguageManager and should not be freed.
-
prependSearchPath
Prependspath
to the list of directories where themanager
looks for language files.See
setSearchPath(java.lang.String[])
for details.- Parameters:
path
- a directory or a filename.
-
setSearchPath
Sets the list of directories where the this LanguageManager looks for language files.If
dirs
isnull
, 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
GResource
s. They must contain the path of a directory within theGResource
.- Parameters:
dirs
- anull
-terminated array of strings ornull
.
-
builder
ALanguageManager.Builder
object constructs aLanguageManager
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withLanguageManager.Builder.build()
.
-