gtksource.view
Module for [View] class
Types 3
Subclass of gtk.text_view.TextView.
gtksource.view.View is the main class of the GtkSourceView library. Use a gtksource.buffer.Buffer to display text with a gtksource.view.View.
This class provides:
- Show the line numbers;
- Show a right margin;
- Highlight the current line;
- Indentation settings;
- Configuration for the Home and End keyboard keys;
- Configure and show line marks;
- And a few other things.
An easy way to test all these features is to use the test-widget mini-program provided in the GtkSourceView repository, in the tests/ directory.
GtkSourceView as GtkBuildable
The GtkSourceView implementation of the gtk.buildable.Buildable interface exposes the gtksource.view.View.completion object with the internal-child "completion".
An example of a UI definition fragment with GtkSourceView:
<object class="GtkSourceView" id="source_view">
<property name="tab-width">4</property>
<property name="auto-indent">True</property>
<child internal-child="completion">
<object class="GtkSourceCompletion">
<property name="select-on-show">False</property>
</object>
</child>
</object>Changing the Font
Gtk CSS provides the best way to change the font for a gtksource.view.View in a manner that allows for components like gtksource.map.Map to scale the desired font.
GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
"textview { font-family: Monospace; font-size: 8pt; }",
-1,
NULL);
gtk_style_context_add_provider (gtk_widget_get_style_context (view),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);If you need to adjust the font or size of font within a portion of the document only, you should use a gtk.text_tag.TextTag with the gtk.text_tag.TextTag.family or gtk.text_tag.TextTag.scale set so that the font size may be scaled relative to the default font set in CSS.
ViewGidBuilder builder() static nothrowGet builder for [gtksource.view.View] Returns: New builder objectgtksource.types.BackgroundPatternType backgroundPattern() @property nothrowGet `backgroundPattern` property. Returns: Draw a specific background pattern on the view.void backgroundPattern(gtksource.types.BackgroundPatternType propval) @property nothrowSet `backgroundPattern` property. Params: propval = Draw a specific background pattern on the view.gtksource.completion.Completion completion() @property nothrowGet `completion` property. Returns: The completion object associated with the viewbool enableSnippets() @property nothrowGet `enableSnippets` property. Returns: The property denotes if snippets should be expanded when the user presses Tab after having typed a word matching the snippets found in [gtksource.snippet_man...void enableSnippets(bool propval) @property nothrowSet `enableSnippets` property. Params: propval = The property denotes if snippets should be expanded when the user presses Tab after having typed a word matching the snippets found in [gtksource.sn...int indentWidth() @property nothrowGet `indentWidth` property. Returns: Width of an indentation step expressed in number of spaces.void indentWidth(int propval) @property nothrowSet `indentWidth` property. Params: propval = Width of an indentation step expressed in number of spaces.gtksource.indenter.Indenter indenter() @property nothrowGet `indenter` property. Returns: The property is a [gtksource.indenter.Indenter] to use to indent as the user types into the [gtksource.view.View].void indenter(gtksource.indenter.Indenter propval) @property nothrowSet `indenter` property. Params: propval = The property is a [gtksource.indenter.Indenter] to use to indent as the user types into the [gtksource.view.View].uint rightMarginPosition() @property nothrowGet `rightMarginPosition` property. Returns: Position of the right margin.void rightMarginPosition(uint propval) @property nothrowSet `rightMarginPosition` property. Params: propval = Position of the right margin.bool showLineMarks() @property nothrowGet `showLineMarks` property. Returns: Whether to display line mark pixbufsvoid showLineMarks(bool propval) @property nothrowSet `showLineMarks` property. Params: propval = Whether to display line mark pixbufsbool showLineNumbers() @property nothrowGet `showLineNumbers` property. Returns: Whether to display line numbersvoid showLineNumbers(bool propval) @property nothrowSet `showLineNumbers` property. Params: propval = Whether to display line numbersbool showRightMargin() @property nothrowGet `showRightMargin` property. Returns: Whether to display the right margin.void showRightMargin(bool propval) @property nothrowSet `showRightMargin` property. Params: propval = Whether to display the right margin.bool smartBackspace() @property nothrowGet `smartBackspace` property. Returns: Whether smart Backspace should be used.void smartBackspace(bool propval) @property nothrowSet `smartBackspace` property. Params: propval = Whether smart Backspace should be used.gtksource.types.SmartHomeEndType smartHomeEnd() @property nothrowGet `smartHomeEnd` property. Returns: Set the behavior of the HOME and END keys.void smartHomeEnd(gtksource.types.SmartHomeEndType propval) @property nothrowSet `smartHomeEnd` property. Params: propval = Set the behavior of the HOME and END keys.gtksource.space_drawer.SpaceDrawer spaceDrawer() @property nothrowGet `spaceDrawer` property. Returns: The [gtksource.space_drawer.SpaceDrawer] object associated with the view.4uint tabWidth() @property nothrowGet `tabWidth` property. Returns: Width of a tab character expressed in number of spaces.void tabWidth(uint propval) @property nothrowSet `tabWidth` property. Params: propval = Width of a tab character expressed in number of spaces.gtksource.view.View newWithBuffer(gtksource.buffer.Buffer buffer) static nothrowCreates a new #GtkSourceView widget displaying the buffer buffer.bool getAutoIndent() nothrowReturns whether auto-indentation of text is enabled. Returns: true if auto indentation is enabled.gtksource.types.BackgroundPatternType getBackgroundPattern() nothrowReturns the #GtkSourceBackgroundPatternType specifying if and how the background pattern should be displayed for this view. Returns: the #GtkSourceBackgroundPatternType.gtksource.completion.Completion getCompletion() nothrowGets the [gtksource.completion.Completion] associated with view.gtksource.gutter.Gutter getGutter(gtk.types.TextWindowType windowType) nothrowReturns the [gtksource.gutter.Gutter] object associated with window_type for view.bool getHighlightCurrentLine() nothrowReturns whether the current line is highlighted. Returns: true if the current line is highlighted.bool getIndentOnTab() nothrowReturns whether when the tab key is pressed the current selection should get indented instead of replaced with the `\t` character. Returns: true if the selection is indented when tab is pressed.gtksource.indenter.Indenter getIndenter() nothrowGets the [gtksource.view.View.indenter] property. Returns: a #GtkSourceIndenter or nullbool getInsertSpacesInsteadOfTabs() nothrowReturns whether when inserting a tabulator character it should be replaced by a group of space characters. Returns: true if spaces are inserted instead of tabs.gtksource.mark_attributes.MarkAttributes getMarkAttributes(string category, out int priority) nothrowGets attributes and priority for the category.uint getRightMarginPosition() nothrowGets the position of the right margin in the given view. Returns: the position of the right margin.bool getShowLineMarks() nothrowReturns whether line marks are displayed beside the text. Returns: true if the line marks are displayed.bool getShowLineNumbers() nothrowReturns whether line numbers are displayed beside the text. Returns: true if the line numbers are displayed.bool getShowRightMargin() nothrowReturns whether a right margin is displayed. Returns: true if the right margin is shown.bool getSmartBackspace() nothrowReturns true if pressing the Backspace key will try to delete spaces up to the previous tab stop. Returns: true if smart Backspace handling is enabled.gtksource.types.SmartHomeEndType getSmartHomeEnd() nothrowReturns a [gtksource.types.SmartHomeEndType] end value specifying how the cursor will move when HOME and END keys are pressed. Returns: a #GtkSourceSmartHomeEndType value.gtksource.space_drawer.SpaceDrawer getSpaceDrawer() nothrowGets the [gtksource.space_drawer.SpaceDrawer] associated with view.uint getVisualColumn(gtk.text_iter.TextIter iter) nothrowDetermines the visual column at iter taking into consideration the [gtksource.view.View.tabWidth] of view.void indentLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end) nothrowInserts one indentation level at the beginning of the specified lines. The empty lines are not indented.void pushSnippet(gtksource.snippet.Snippet snippet, gtk.text_iter.TextIter location = null) nothrowInserts a new snippet at locationvoid setBackgroundPattern(gtksource.types.BackgroundPatternType backgroundPattern) nothrowSet if and how the background pattern should be displayed.void setEnableSnippets(bool enableSnippets) nothrowSets the [gtksource.view.View.enableSnippets] property.void setHighlightCurrentLine(bool highlight) nothrowIf highlight is true the current line will be highlighted.void setIndentOnTab(bool enable) nothrowIf true, when the tab key is pressed when several lines are selected, the selected lines are indented of one level instead of being replaced with a `\t` character. Shift+Tab unindents the selection.void setIndentWidth(int width) nothrowSets the number of spaces to use for each step of indent when the tab key is pressed.void setIndenter(gtksource.indenter.Indenter indenter = null) nothrowSets the indenter for view to indenter.void setInsertSpacesInsteadOfTabs(bool enable) nothrowIf true a tab key pressed is replaced by a group of space characters.void setMarkAttributes(string category, gtksource.mark_attributes.MarkAttributes attributes, int priority) nothrowSets attributes and priority for the category.void setRightMarginPosition(uint pos) nothrowSets the position of the right margin in the given view.void setSmartBackspace(bool smartBackspace) nothrowWhen set to true, pressing the Backspace key will try to delete spaces up to the previous tab stop.void setSmartHomeEnd(gtksource.types.SmartHomeEndType smartHomeEnd) nothrowSet the desired movement of the cursor when HOME and END keys are pressed.void unindentLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end) nothrowRemoves one indentation level at the beginning of the specified lines.gulong connectChangeCase(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtksource.types.ChangeCaseType)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtksource.view.View)))
&& Parameters!T.length < 3) nothrowConnect to `ChangeCase` signal.gulong connectChangeNumber(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == int)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtksource.view.View)))
&& Parameters!T.length < 3) nothrowConnect to `ChangeNumber` signal.gulong connectJoinLines(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtksource.view.View)))
&& Parameters!T.length < 2) nothrowConnect to `JoinLines` signal.gulong connectLineMarkActivated(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.text_iter.TextIter)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == uint)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] == gdk.types.ModifierType)))
&& (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] == int)))
&& (Parameters!T.length < 5 || (ParameterStorageClassTuple!T[4] == ParameterStorageClass.none && is(Parameters!T[4] : gtksource.view.View)))
&& Parameters!T.length < 6) nothrowConnect to `LineMarkActivated` signal.gulong connectMoveLines(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == bool)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtksource.view.View)))
&& Parameters!T.length < 3) nothrowConnect to `MoveLines` signal.gulong connectMoveToMatchingBracket(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == bool)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtksource.view.View)))
&& Parameters!T.length < 3) nothrowConnect to `MoveToMatchingBracket` signal.gulong connectMoveWords(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == int)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtksource.view.View)))
&& Parameters!T.length < 3) nothrowConnect to `MoveWords` signal.gulong connectPushSnippet(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtksource.snippet.Snippet)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.ref_ && is(Parameters!T[1] == gtk.text_iter.TextIter)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtksource.view.View)))
&& Parameters!T.length < 4) nothrowConnect to `PushSnippet` signal.gulong connectShowCompletion(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtksource.view.View)))
&& Parameters!T.length < 2) nothrowConnect to `ShowCompletion` signal.gulong connectSmartHomeEnd(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.text_iter.TextIter)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == int)))
&& (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] : gtksource.view.View)))
&& Parameters!T.length < 4) nothrowConnect to `SmartHomeEnd` signal.Fluent builder implementation template for gtksource.view.View
T autoIndent(bool propval) nothrowT backgroundPattern(gtksource.types.BackgroundPatternType propval) nothrowSet `backgroundPattern` property. Params: propval = Draw a specific background pattern on the view. Returns: Builder instance for fluent chainingT enableSnippets(bool propval) nothrowSet `enableSnippets` property. Params: propval = The property denotes if snippets should be expanded when the user presses Tab after having typed a word matching the snippets found in [gtksource.sn...T highlightCurrentLine(bool propval) nothrowT indentOnTab(bool propval) nothrowT indentWidth(int propval) nothrowSet `indentWidth` property. Params: propval = Width of an indentation step expressed in number of spaces. Returns: Builder instance for fluent chainingT indenter(gtksource.indenter.Indenter propval) nothrowSet `indenter` property. Params: propval = The property is a [gtksource.indenter.Indenter] to use to indent as the user types into the [gtksource.view.View]. Returns: Builder instance for fluent ch...T insertSpacesInsteadOfTabs(bool propval) nothrowT rightMarginPosition(uint propval) nothrowSet `rightMarginPosition` property. Params: propval = Position of the right margin. Returns: Builder instance for fluent chainingT showLineMarks(bool propval) nothrowSet `showLineMarks` property. Params: propval = Whether to display line mark pixbufs Returns: Builder instance for fluent chainingT showLineNumbers(bool propval) nothrowSet `showLineNumbers` property. Params: propval = Whether to display line numbers Returns: Builder instance for fluent chainingT showRightMargin(bool propval) nothrowSet `showRightMargin` property. Params: propval = Whether to display the right margin. Returns: Builder instance for fluent chainingT smartBackspace(bool propval) nothrowSet `smartBackspace` property. Params: propval = Whether smart Backspace should be used. Returns: Builder instance for fluent chainingT smartHomeEnd(gtksource.types.SmartHomeEndType propval) nothrowSet `smartHomeEnd` property. Params: propval = Set the behavior of the HOME and END keys. Returns: Builder instance for fluent chainingT tabWidth(uint propval) nothrowSet `tabWidth` property. Params: propval = Width of a tab character expressed in number of spaces. Returns: Builder instance for fluent chainingFluent builder for gtksource.view.View