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 class@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 property@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 class@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()Get builder for [gtksource.view.View] Returns: New builder objectbool autoIndent() @propertyvoid autoIndent(bool propval) @propertygtksource.types.BackgroundPatternType backgroundPattern() @propertyGet `backgroundPattern` property. Returns: Draw a specific background pattern on the view.void backgroundPattern(gtksource.types.BackgroundPatternType propval) @propertySet `backgroundPattern` property. Params: propval = Draw a specific background pattern on the view.gtksource.completion.Completion completion() @propertyGet `completion` property. Returns: The completion object associated with the viewbool enableSnippets() @propertyGet `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 `class@SnippetManager`.void enableSnippets(bool propval) @propertySet `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 `class@Snippe...bool highlightCurrentLine() @propertyvoid highlightCurrentLine(bool propval) @propertybool indentOnTab() @propertyvoid indentOnTab(bool propval) @propertyint indentWidth() @propertyGet `indentWidth` property. Returns: Width of an indentation step expressed in number of spaces.void indentWidth(int propval) @propertySet `indentWidth` property. Params: propval = Width of an indentation step expressed in number of spaces.gtksource.indenter.Indenter indenter() @propertyGet `indenter` property. Returns: The property is a `iface@Indenter` to use to indent as the user types into the `class@View`.void indenter(gtksource.indenter.Indenter propval) @propertySet `indenter` property. Params: propval = The property is a `iface@Indenter` to use to indent as the user types into the `class@View`.bool insertSpacesInsteadOfTabs() @propertyvoid insertSpacesInsteadOfTabs(bool propval) @propertyuint rightMarginPosition() @propertyGet `rightMarginPosition` property. Returns: Position of the right margin.void rightMarginPosition(uint propval) @propertySet `rightMarginPosition` property. Params: propval = Position of the right margin.bool showLineMarks() @propertyGet `showLineMarks` property. Returns: Whether to display line mark pixbufsvoid showLineMarks(bool propval) @propertySet `showLineMarks` property. Params: propval = Whether to display line mark pixbufsbool showLineNumbers() @propertyGet `showLineNumbers` property. Returns: Whether to display line numbersvoid showLineNumbers(bool propval) @propertySet `showLineNumbers` property. Params: propval = Whether to display line numbersbool showRightMargin() @propertyGet `showRightMargin` property. Returns: Whether to display the right margin.void showRightMargin(bool propval) @propertySet `showRightMargin` property. Params: propval = Whether to display the right margin.bool smartBackspace() @propertyGet `smartBackspace` property. Returns: Whether smart Backspace should be used.void smartBackspace(bool propval) @propertySet `smartBackspace` property. Params: propval = Whether smart Backspace should be used.gtksource.types.SmartHomeEndType smartHomeEnd() @propertyGet `smartHomeEnd` property. Returns: Set the behavior of the HOME and END keys.void smartHomeEnd(gtksource.types.SmartHomeEndType propval) @propertySet `smartHomeEnd` property. Params: propval = Set the behavior of the HOME and END keys.gtksource.space_drawer.SpaceDrawer spaceDrawer() @propertyGet `spaceDrawer` property. Returns: The `class@SpaceDrawer` object associated with the view.4uint tabWidth() @propertyGet `tabWidth` property. Returns: Width of a tab character expressed in number of spaces.void tabWidth(uint propval) @propertySet `tabWidth` property. Params: propval = Width of a tab character expressed in number of spaces.gtksource.view.View newWithBuffer(gtksource.buffer.Buffer buffer)Creates a new #GtkSourceView widget displaying the buffer buffer.bool getAutoIndent()Returns whether auto-indentation of text is enabled. Returns: true if auto indentation is enabled.gtksource.types.BackgroundPatternType getBackgroundPattern()Returns the #GtkSourceBackgroundPatternType specifying if and how the background pattern should be displayed for this view. Returns: the #GtkSourceBackgroundPatternType.gtksource.completion.Completion getCompletion()Gets the `classCompletion` associated with view.bool getEnableSnippets()Gets the `propertyView:enable-snippets` property.gtksource.gutter.Gutter getGutter(gtk.types.TextWindowType windowType)Returns the `classGutter` object associated with window_type for view.bool getHighlightCurrentLine()Returns whether the current line is highlighted. Returns: true if the current line is highlighted.gtksource.hover.Hover getHover()Gets the `classHover` associated with view.bool getIndentOnTab()Returns 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.int getIndentWidth()Returns the number of spaces to use for each step of indent.gtksource.indenter.Indenter getIndenter()Gets the `propertyView:indenter` property. Returns: a #GtkSourceIndenter or nullbool getInsertSpacesInsteadOfTabs()Returns 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)Gets attributes and priority for the category.uint getRightMarginPosition()Gets the position of the right margin in the given view. Returns: the position of the right margin.bool getShowLineMarks()Returns whether line marks are displayed beside the text. Returns: true if the line marks are displayed.bool getShowLineNumbers()Returns whether line numbers are displayed beside the text. Returns: true if the line numbers are displayed.bool getShowRightMargin()Returns whether a right margin is displayed. Returns: true if the right margin is shown.bool getSmartBackspace()Returns 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()Returns a `enumSmartHomeEndType` end value specifying how the cursor will move when HOME and END keys are pressed. Returns: a #GtkSourceSmartHomeEndType value.gtksource.space_drawer.SpaceDrawer getSpaceDrawer()Gets the `classSpaceDrawer` associated with view.uint getTabWidth()Returns the width of tabulation in characters. Returns: width of tab.uint getVisualColumn(gtk.text_iter.TextIter iter)Determines the visual column at iter taking into consideration the `propertyView:tab-width` of view.void indentLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)Inserts 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)Inserts a new snippet at locationvoid setAutoIndent(bool enable)If true auto-indentation of text is enabled.void setBackgroundPattern(gtksource.types.BackgroundPatternType backgroundPattern)Set if and how the background pattern should be displayed.void setEnableSnippets(bool enableSnippets)Sets the `propertyView:enable-snippets` property.void setHighlightCurrentLine(bool highlight)If highlight is true the current line will be highlighted.void setIndentOnTab(bool enable)If 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)Sets the number of spaces to use for each step of indent when the tab key is pressed.void setIndenter(gtksource.indenter.Indenter indenter = null)Sets the indenter for view to indenter.void setInsertSpacesInsteadOfTabs(bool enable)If true a tab key pressed is replaced by a group of space characters.void setMarkAttributes(string category, gtksource.mark_attributes.MarkAttributes attributes, int priority)Sets attributes and priority for the category.void setRightMarginPosition(uint pos)Sets the position of the right margin in the given view.void setShowLineMarks(bool show)If true line marks will be displayed beside the text.void setShowLineNumbers(bool show)If true line numbers will be displayed beside the text.void setShowRightMargin(bool show)If true a right margin is displayed.void setSmartBackspace(bool smartBackspace)When set to true, pressing the Backspace key will try to delete spaces up to the previous tab stop.void setSmartHomeEnd(gtksource.types.SmartHomeEndType smartHomeEnd)Set the desired movement of the cursor when HOME and END keys are pressed.void setTabWidth(uint width)Sets the width of tabulation in characters.void unindentLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)Removes 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)Connect 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)Connect 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)Connect 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)Connect 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)Connect 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)Connect 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)Connect 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)Connect 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)Connect 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)Connect to `SmartHomeEnd` signal.T autoIndent(bool propval)T backgroundPattern(gtksource.types.BackgroundPatternType propval)Set `backgroundPattern` property. Params: propval = Draw a specific background pattern on the view. Returns: Builder instance for fluent chainingT enableSnippets(bool propval)Set `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 `class@Snippe...T highlightCurrentLine(bool propval)T indentOnTab(bool propval)T indentWidth(int propval)Set `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)Set `indenter` property. Params: propval = The property is a `iface@Indenter` to use to indent as the user types into the `class@View`. Returns: Builder instance for fluent chainingT insertSpacesInsteadOfTabs(bool propval)T rightMarginPosition(uint propval)Set `rightMarginPosition` property. Params: propval = Position of the right margin. Returns: Builder instance for fluent chainingT showLineMarks(bool propval)Set `showLineMarks` property. Params: propval = Whether to display line mark pixbufs Returns: Builder instance for fluent chainingT showLineNumbers(bool propval)Set `showLineNumbers` property. Params: propval = Whether to display line numbers Returns: Builder instance for fluent chainingT showRightMargin(bool propval)Set `showRightMargin` property. Params: propval = Whether to display the right margin. Returns: Builder instance for fluent chainingT smartBackspace(bool propval)Set `smartBackspace` property. Params: propval = Whether smart Backspace should be used. Returns: Builder instance for fluent chainingT smartHomeEnd(gtksource.types.SmartHomeEndType propval)Set `smartHomeEnd` property. Params: propval = Set the behavior of the HOME and END keys. Returns: Builder instance for fluent chainingT tabWidth(uint propval)Set `tabWidth` property. Params: propval = Width of a tab character expressed in number of spaces. Returns: Builder instance for fluent chaining