Class SnippetContext

All Implemented Interfaces:
Proxy

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

Context for expanding SnippetChunk.

This class is currently used primary as a hashtable. However, the longer term goal is to have it hold onto a GjsContext as well as other languages so that SnippetChunk can expand themselves by executing script within the context.

The Snippet will build the context and then expand each of the chunks during the insertion/edit phase.

  • Constructor Details

    • SnippetContext

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

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

    • getType

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

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

      protected SnippetContext 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
    • clearVariables

      public void clearVariables()
      Removes all variables from the context.
    • expand

      public String expand(String input)
    • getVariable

      public @Nullable String getVariable(String key)
      Gets the current value for a variable named key.
      Parameters:
      key - the name of the variable
      Returns:
      the value for the variable, or null
    • setConstant

      public void setConstant(String key, String value)

      Sets a constatnt within the context.

      This is similar to a variable set with setVariable(String, String) but is expected to not change during use of the snippet.

      Examples would be the date or users name.

      Parameters:
      key - the constant name
      value - the value of the constant
    • setLinePrefix

      public void setLinePrefix(String linePrefix)
    • setTabWidth

      public void setTabWidth(int tabWidth)
    • setUseSpaces

      public void setUseSpaces(boolean useSpaces)
    • setVariable

      public void setVariable(String key, String value)

      Sets a variable within the context.

      This variable may be overridden by future updates to the context.

      Parameters:
      key - the variable name
      value - the value for the variable
    • onChanged

      The signal is emitted when a change has been discovered in one of the chunks of the snippet which has caused a variable or other dynamic data within the context to have changed.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged()
      Emits the "changed" signal. See onChanged(SnippetContext.ChangedCallback).
    • builder

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