Class LanguageManager

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class LanguageManager extends GObject

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.

  • Constructor Details

    • LanguageManager

      public LanguageManager(MemorySegment address)
      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

      public static @Nullable Type getType()
      Get the GType of the LanguageManager class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected LanguageManager asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getDefault

      public static LanguageManager getDefault()
      Returns the default GtkSourceLanguageManager instance.
      Returns:
      a GtkSourceLanguageManager. Return value is owned by GtkSourceView library and must not be unref'ed.
    • appendSearchPath

      public void appendSearchPath(String path)

      Appends path to the list of directories where the manager looks for language files.

      See setSearchPath(String[]) for details.

      Parameters:
      path - a directory or a filename.
      Since:
      5.4
    • getLanguage

      public @Nullable Language getLanguage(String id)
      Gets the Language identified by the given id in the language manager.
      Parameters:
      id - a language id.
      Returns:
      a GtkSourceLanguage, or null if there is no language identified by the given id. Return value is owned by this LanguageManager and should not be freed.
    • getLanguageIds

      public @Nullable String @Nullable [] getLanguageIds()
      Returns the ids of the available languages.
      Returns:
      a null-terminated array of strings containing the ids of the available languages or null 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

      public String[] 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 @Nullable Language guessLanguage(@Nullable String filename, @Nullable String contentType)

      Picks a Language for given file name and content type, according to the information in lang files.

      Either filename or contentType may be null. 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() and Language.getGlobs() if you need full control over file -> language mapping.

      Parameters:
      filename - a filename in Glib filename encoding, or null.
      contentType - a content type (as in GIO API), or null.
      Returns:
      a GtkSourceLanguage, or null if there is no suitable language for given filename and/or contentType. Return value is owned by this LanguageManager and should not be freed.
    • prependSearchPath

      public void prependSearchPath(String path)

      Prepends path to the list of directories where the manager looks for language files.

      See setSearchPath(String[]) for details.

      Parameters:
      path - a directory or a filename.
      Since:
      5.4
    • setSearchPath

      public void setSearchPath(@Nullable String @Nullable [] dirs)

      Sets the list of directories where the this LanguageManager looks for language files.

      If dirs is null, 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 the GResource.

      Parameters:
      dirs - a null-terminated array of strings or null.
    • builder

      public static LanguageManager.Builder<? extends LanguageManager.Builder> builder()
      A LanguageManager.Builder object constructs a LanguageManager with the specified properties. Use the various set...() methods to set properties, and finish construction with LanguageManager.Builder.build().
      Returns:
      the builder object