Class Snippet

All Implemented Interfaces:
Proxy

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

Quick insertion code snippets.

The GtkSourceSnippet represents a series of chunks that can quickly be inserted into the View.

Snippets are defined in XML files which are loaded by the SnippetManager. Alternatively, applications can create snippets on demand and insert them into the View using View.pushSnippet(Snippet, TextIter).

Snippet chunks can reference other snippet chunks as well as post-process the values from other chunks such as capitalization.

  • Constructor Details

    • Snippet

      public Snippet(MemorySegment address)
      Create a Snippet instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Snippet

      public Snippet(@Nullable String trigger, @Nullable String languageId)
      Creates a new GtkSourceSnippet
      Parameters:
      trigger - the trigger word
      languageId - the source language
    • Snippet

      public Snippet()
      Create a new Snippet.
  • Method Details

    • getType

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

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

      protected Snippet 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
    • parsed

      public static Snippet parsed(String text) throws GErrorException
      Parses the snippet formatted text into a series of chunks and adds them to a new GtkSourceSnippet.
      Parameters:
      text - the formatted snippet text to parse
      Returns:
      the newly parsed GtkSourceSnippet, or null upon failure and error is set.
      Throws:
      GErrorException - see GError
      Since:
      5.6
    • addChunk

      public void addChunk(SnippetChunk chunk)

      Appends chunk to the snippet.

      This may only be called before the snippet has been expanded.

      Parameters:
      chunk - a GtkSourceSnippetChunk
    • copy

      public Snippet copy()
      Does a deep copy of the snippet.
      Returns:
      A new GtkSourceSnippet
    • getContext

      public @Nullable SnippetContext getContext()
      Gets the context used for expanding the snippet.
      Returns:
      an GtkSourceSnippetContext
    • getDescription

      public String getDescription()
      Gets the description for the snippet.
    • getFocusPosition

      public int getFocusPosition()

      Gets the current focus for the snippet.

      This is changed as the user tabs through focus locations.

      Returns:
      The focus position, or -1 if unset.
    • getLanguageId

      public String getLanguageId()

      Gets the language-id used for the source snippet.

      The language identifier should be one that matches a source language Language:id property.

      Returns:
      the language identifier
    • getNChunks

      public int getNChunks()

      Gets the number of chunks in the snippet.

      Note that not all chunks are editable.

      Returns:
      The number of chunks.
    • getName

      public String getName()
      Gets the name for the snippet.
    • getNthChunk

      public SnippetChunk getNthChunk(int nth)
      Gets the chunk at nth.
      Parameters:
      nth - the nth chunk to get
      Returns:
      an GtkSourceSnippetChunk
    • getTrigger

      public @Nullable String getTrigger()

      Gets the trigger for the source snippet.

      A trigger is a word that can be expanded into the full snippet when the user presses Tab.

      Returns:
      A string or null
    • setDescription

      public void setDescription(String description)
      Sets the description for the snippet.
      Parameters:
      description - the snippet description
    • setLanguageId

      public void setLanguageId(String languageId)

      Sets the language identifier for the snippet.

      This should match the Language:id identifier.

      Parameters:
      languageId - the language identifier for the snippet
    • setName

      public void setName(String name)
      Sets the name for the snippet.
      Parameters:
      name - the snippet name
    • setTrigger

      public void setTrigger(String trigger)
      Sets the trigger for the snippet.
      Parameters:
      trigger - the trigger word
    • builder

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