Interface Indenter
- All Superinterfaces:
Proxy
- All Known Implementing Classes:
Indenter.Indenter$Impl
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(org.gnome.gtksourceview.View, org.gnome.gtk.TextIter, java.util.Set<org.gnome.gdk.ModifierType>, int) and indent(org.gnome.gtksourceview.View, org.gnome.gtk.TextIter).
isTrigger(org.gnome.gtksourceview.View, org.gnome.gtk.TextIter, java.util.Set<org.gnome.gdk.ModifierType>, 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(org.gnome.gtksourceview.View, org.gnome.gtk.TextIter) is called after text has been
inserted into Buffer when
isTrigger(org.gnome.gtksourceview.View, org.gnome.gtk.TextIter, java.util.Set<org.gnome.gdk.ModifierType>, 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(org.gnome.gtk.TextIter, org.gnome.gtk.TextIter) 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 ClassesModifier and TypeInterfaceDescriptionstatic classThe Indenter$Impl type represents a native instance of the Indenter interface.static classThe virtual function table forGtkSourceIndenter. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable TypegetType()Get the GType of the Indenter classdefault voidThis function should be implemented to alter the indentation of text within the view.default booleanisTrigger(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 booleanisTrigger(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.
-
Method Details
-
getType
-
indent
This function should be implemented to alter the indentation of text within the view.viewis provided so that the indenter may retrieve settings such as indentation and tab widths.iteris 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(org.gnome.gtksourceview.View, org.gnome.gtk.TextIter, java.util.Set<org.gnome.gdk.ModifierType>, int)for how to trigger indentation on various characters inserted into the buffer.The implementor of this function is expected to keep
itervalid 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- aGtkSourceViewiter- the location of the indentation request
-
isTrigger
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
keyvalisGdk.KEY_ReturnorGdk.KEY_KP_Enterandstatedoes not haveModifierType.SHIFT_MASKset. 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- aGtkSourceViewlocation- the location wherechis to be insertedstate- modifier state for the insertionkeyval- the keyval pressed such asGdk.KEY_Return- Returns:
trueif indentation should be automatically triggered; otherwisefalseand no indentation will be performed.
-
isTrigger
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
keyvalisGdk.KEY_ReturnorGdk.KEY_KP_Enterandstatedoes not haveModifierType.SHIFT_MASKset. 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- aGtkSourceViewlocation- the location wherechis to be insertedstate- modifier state for the insertionkeyval- the keyval pressed such asGdk.KEY_Return- Returns:
trueif indentation should be automatically triggered; otherwisefalseand no indentation will be performed.
-