Interface Indenter
- All Superinterfaces:
Proxy
- All Known Implementing Classes:
Indenter.IndenterImpl
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
Modifier and TypeInterfaceDescriptionstatic class
The IndenterImpl type represents a native instance of the Indenter interface.static class
The virtual function table forGtkSourceIndenter
. -
Method Summary
Modifier and TypeMethodDescriptionstatic Type
getType()
Get the GType of the Indenter classdefault void
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.
-
Method Details
-
getType
-
indent
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
invalid reference
is_trigger
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
- aGtkSourceView
iter
- 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
keyval
isGdk.KEY_Return
orGdk.KEY_KP_Enter
andstate
does not haveModifierType.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
- aGtkSourceView
location
- the location wherech
is to be insertedstate
- modifier state for the insertionkeyval
- the keyval pressed such asGdk.KEY_Return
- Returns:
true
if indentation should be automatically triggered; otherwisefalse
and 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
keyval
isGdk.KEY_Return
orGdk.KEY_KP_Enter
andstate
does not haveModifierType.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
- aGtkSourceView
location
- the location wherech
is to be insertedstate
- modifier state for the insertionkeyval
- the keyval pressed such asGdk.KEY_Return
- Returns:
true
if indentation should be automatically triggered; otherwisefalse
and no indentation will be performed.
-