GtkSource.Indenter¶
- Implementations:
None
Methods¶
|
|
|
Virtual Methods¶
|
|
|
Properties¶
None
Signals¶
None
Fields¶
None
Class Details¶
- class GtkSource.Indenter¶
- Bases:
- Structure:
Auto-indentation interface.
By default, [class`View`] can auto-indent as you type when [property`View`:py:data::auto-indent<GtkSource.Indenter.props.auto_indent>] is enabled. The indentation simply copies the previous lines indentation.
This can be changed by implementing
GtkSourceIndenter
and setting the [property`View`:py:data::indenter<GtkSource.Indenter.props.indenter>] property.Implementors of this interface should implement both [vfunc`Indenter`.is_trigger] and [vfunc`Indenter`.indent].
[vfunc`Indenter`.is_trigger] 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 [const`Gdk`.KEY_Return] or [const`Gdk`.KEY_KP_Enter] without
Gdk.ModifierType.SHIFT_MASK
set.[vfunc`Indenter`.indent] is called after text has been inserted into [class`Buffer`] when [vfunc`Indenter`.is_trigger] returned
True
. The [struct`Gtk`.TextIter] is placed directly after the inserted character or characters.It may be beneficial to move the insertion mark using [method`Gtk`.TextBuffer.select_range] 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.
- indent(view, iter)¶
- Parameters:
view (
GtkSource.View
) – aGtkSource.View
iter (
Gtk.TextIter
) – the location of the indentation request
- Returns:
the location of the indentation request
- Return type:
iter:
Gtk.TextIter
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 [iface`Indenter`.is_trigger] 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.
- is_trigger(view, location, state, keyval)¶
- Parameters:
view (
GtkSource.View
) – aGtkSource.View
location (
Gtk.TextIter
) – the location where ch is to be insertedstate (
Gdk.ModifierType
) – modifier state for the insertionkeyval (
int
) – the keyval pressed such as [const`Gdk`.KEY_Return]
- Returns:
True
if indentation should be automatically triggered; otherwiseFalse
and no indentation will be performed.- Return type:
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 [const`Gdk`.KEY_Return] or [const`Gdk`.KEY_KP_Enter] and state does not have
Gdk.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.
- do_indent(view, iter) virtual¶
- Parameters:
view (
GtkSource.View
) – aGtkSource.View
iter (
Gtk.TextIter
) – the location of the indentation request
- Returns:
the location of the indentation request
- Return type:
iter:
Gtk.TextIter
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 [iface`Indenter`.is_trigger] 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.
- do_is_trigger(view, location, state, keyval) virtual¶
- Parameters:
view (
GtkSource.View
) – aGtkSource.View
location (
Gtk.TextIter
) – the location where ch is to be insertedstate (
Gdk.ModifierType
) – modifier state for the insertionkeyval (
int
) – the keyval pressed such as [const`Gdk`.KEY_Return]
- Returns:
True
if indentation should be automatically triggered; otherwiseFalse
and no indentation will be performed.- Return type:
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 [const`Gdk`.KEY_Return] or [const`Gdk`.KEY_KP_Enter] and state does not have
Gdk.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.