Interface Indenter

All Superinterfaces:
Proxy
All Known Implementing Classes:
Indenter.Indenter$Impl

@Generated("org.javagi.JavaGI") public interface Indenter extends Proxy

Auto-indentation interface.

By default, View can auto-indent as you type when View:auto-indent is enabled. The indentation simply copies the previous lines indentation.

This can be changed by implementing GtkSourceIndenter and setting the View:indenter property.

Implementors of this interface should implement both isTrigger(View, TextIter, Set, int) and indent(View, TextIter).

isTrigger(View, TextIter, Set, int) is called upon key-press to determine of the key press should trigger an indentation. The default implementation of the interface checks to see if the key was Gdk.KEY_Return or Gdk.KEY_KP_Enter without ModifierType.SHIFT_MASK set.

indent(View, TextIter) is called after text has been inserted into Buffer when isTrigger(View, TextIter, Set, int) returned true. The Gtk.TextIter is placed directly after the inserted character or characters.

It may be beneficial to move the insertion mark using TextBuffer#selectRange depending on how the indenter changes the indentation.

All changes are encapsulated within a single user action so that the user may undo them using standard undo/redo accelerators.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    The Indenter$Impl type represents a native instance of the Indenter interface.
    static class 
    The virtual function table for GtkSourceIndenter.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable Type
    Get the GType of the Indenter class.
    default void
    indent(View view, TextIter iter)
    This function should be implemented to alter the indentation of text within the view.
    default boolean
    isTrigger(View view, TextIter location, Set<ModifierType> state, int keyval)
    This function is used to determine if a key pressed should cause the indenter to automatically indent.
    default boolean
    isTrigger(View view, TextIter location, ModifierType state, int keyval)
    This function is used to determine if a key pressed should cause the indenter to automatically indent.

    Methods inherited from interface Proxy

    handle
  • Method Details

    • getType

      static @Nullable Type getType()
      Get the GType of the Indenter class.
      Returns:
      the GType
    • indent

      default void indent(View view, TextIter iter)

      This function should be implemented to alter the indentation of text within the view.

      view is provided so that the indenter may retrieve settings such as indentation and tab widths.

      iter is the location where the indentation was requested. This typically is after having just inserted a newline (\n) character but can be other situations such as a manually requested indentation or reformatting.

      See isTrigger(View, TextIter, Set, int) for how to trigger indentation on various characters inserted into the buffer.

      The implementor of this function is expected to keep iter valid across calls to the function and should contain the location of the insert mark after calling this function.

      The default implementation for this virtual function will copy the indentation of the previous line.

      Parameters:
      view - a GtkSourceView
      iter - the location of the indentation request
    • isTrigger

      default boolean isTrigger(View view, TextIter location, Set<ModifierType> state, int keyval)

      This function is used to determine if a key pressed should cause the indenter to automatically indent.

      The default implementation of this virtual method will check to see if keyval is Gdk.KEY_Return or Gdk.KEY_KP_Enter and state does not have ModifierType.SHIFT_MASK set. This is to allow the user to avoid indentation when Shift+Return is pressed. Other indenters may want to copy this behavior to provide a consistent experience to users.

      Parameters:
      view - a GtkSourceView
      location - the location where ch is to be inserted
      state - modifier state for the insertion
      keyval - the keyval pressed such as Gdk.KEY_Return
      Returns:
      true if indentation should be automatically triggered; otherwise false and no indentation will be performed.
    • isTrigger

      default boolean isTrigger(View view, TextIter location, ModifierType state, int keyval)

      This function is used to determine if a key pressed should cause the indenter to automatically indent.

      The default implementation of this virtual method will check to see if keyval is Gdk.KEY_Return or Gdk.KEY_KP_Enter and state does not have ModifierType.SHIFT_MASK set. This is to allow the user to avoid indentation when Shift+Return is pressed. Other indenters may want to copy this behavior to provide a consistent experience to users.

      Parameters:
      view - a GtkSourceView
      location - the location where ch is to be inserted
      state - modifier state for the insertion
      keyval - the keyval pressed such as Gdk.KEY_Return
      Returns:
      true if indentation should be automatically triggered; otherwise false and no indentation will be performed.