Subclass of [class@Gtk.
TextView].
`GtkSourceView` is the main class of the GtkSourceView library. Use a [class@Buffer] to display text with a `GtkSourceView`.
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 [iface@Gtk.Buildable] interface exposes the [property@View:completion] object with the
internal-child "completion".
An example of a UI definition fragment with GtkSourceView: ```xml <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 `GtkSourceView` in a manner that allows for components like [class@Map] to scale
the desired font.
```c GtkCssProvider *provider = gtk_css_provider_new (); gtk_css_provider_load_from_string (provider, "textview { font-family:
Monospace; font-size: 8pt; }"); gtk_style_context_add_provider (gtk_widget_get_style_context (view), GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref (provider); ``` ```python provider = Gtk.CssProvider() provider.load_from_string(
"textview { font-family: Monospace; font-size: 8pt; }") style_context = view.get_style_context() style_context.add_provider(provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) ```
If you need to adjust the font or size of font within a portion of the document only, you should use a [class@Gtk.TextTag] with the [
property@Gtk.TextTag:family] or [property@Gtk.TextTag:scale] set so that the font size may be scaled relative to the default font set in
CSS.
- public bool get_auto_indent ()
Returns whether auto-indentation of text is enabled.
- public unowned SourceCompletion get_completion ()
Gets the [class@Completion] associated with
this.
- public SourceDrawSpacesFlags get_draw_spaces ()
- public unowned SourceGutter get_gutter (TextWindowType window_type)
Returns the [class@Gutter] object associated with window_type
for this.
- public bool get_highlight_current_line ()
Returns whether the current line is highlighted.
- public bool get_indent_on_tab ()
Returns whether when the tab key is pressed the current selection
should get indented instead of replaced with the `\t` character.
- public int get_indent_width ()
Returns the number of spaces to use for each step of indent.
- public bool get_insert_spaces_instead_of_tabs ()
Returns whether when inserting a tabulator character it should be
replaced by a group of space characters.
- public bool get_mark_category_background (string category, Color dest)
- public unowned Pixbuf get_mark_category_pixbuf (string category)
- public int get_mark_category_priority (string category)
- public uint get_right_margin_position ()
Gets the position of the right margin in the given
this.
- public bool get_show_line_marks ()
Returns whether line marks are displayed beside the text.
- public bool get_show_line_numbers ()
Returns whether line numbers are displayed beside the text.
- public bool get_show_right_margin ()
Returns whether a right margin is displayed.
- public SourceSmartHomeEndType get_smart_home_end ()
Returns a [enum@SmartHomeEndType] end value specifying how the cursor
will move when HOME and END keys are pressed.
- public uint get_tab_width ()
Returns the width of tabulation in characters.
- public void set_auto_indent (bool enable)
If true auto-indentation of text is
enabled.
- public void set_draw_spaces (SourceDrawSpacesFlags flags)
Set if and how the spaces should be visualized.
- public void set_highlight_current_line (bool show)
If highlight is true
the current line will be highlighted.
- public void set_indent_on_tab (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.
- public void set_indent_width (int width)
Sets the number of spaces to use for each step of indent when the tab
key is pressed.
- public void set_insert_spaces_instead_of_tabs (bool enable)
If true a tab key pressed is
replaced by a group of space characters.
- public void set_mark_category_background (string category, Color color)
- public void set_mark_category_icon_from_icon_name (string category, string name)
- public void set_mark_category_icon_from_pixbuf (string category, Pixbuf pixbuf)
- public void set_mark_category_icon_from_stock (string category, string stock_id)
- public void set_mark_category_pixbuf (string category, Pixbuf pixbuf)
- public void set_mark_category_priority (string category, int priority)
- public void set_mark_category_tooltip_func (string category, SourceViewMarkTooltipFunc func, DestroyNotify user_data_notify)
- public void set_mark_category_tooltip_markup_func (string category, SourceViewMarkTooltipFunc markup_func, DestroyNotify user_data_notify)
- public void set_right_margin_position (uint pos)
Sets the position of the right margin in the given
this.
- public void set_show_line_marks (bool show)
If true line marks will be displayed
beside the text.
- public void set_show_line_numbers (bool show)
If true line numbers will be
displayed beside the text.
- public void set_show_right_margin (bool show)
If true a right margin is displayed.
- public void set_smart_home_end (SourceSmartHomeEndType smart_he)
Set the desired movement of the cursor when HOME and END keys are
pressed.
- public void set_tab_width (uint width)
Sets the width of tabulation in characters.