View

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.utf8 or gtk.text_tag.TextTag.gdouble set so that the font size may be scaled relative to the default font set in CSS.

class View : TextView {}

Constructors

this
this()

Creates a new gtksource.view.View.

Members

Functions

connectChangeCase
ulong connectChangeCase(T callback, Flag!"After" after)

Connect to ChangeCase signal.

connectChangeNumber
ulong connectChangeNumber(T callback, Flag!"After" after)

Connect to ChangeNumber signal.

connectJoinLines
ulong connectJoinLines(T callback, Flag!"After" after)

Connect to JoinLines signal.

connectLineMarkActivated
ulong connectLineMarkActivated(T callback, Flag!"After" after)

Connect to LineMarkActivated signal.

connectMoveLines
ulong connectMoveLines(T callback, Flag!"After" after)

Connect to MoveLines signal.

connectMoveToMatchingBracket
ulong connectMoveToMatchingBracket(T callback, Flag!"After" after)

Connect to MoveToMatchingBracket signal.

connectMoveWords
ulong connectMoveWords(T callback, Flag!"After" after)

Connect to MoveWords signal.

connectShowCompletion
ulong connectShowCompletion(T callback, Flag!"After" after)

Connect to ShowCompletion signal.

connectSmartHomeEnd
ulong connectSmartHomeEnd(T callback, Flag!"After" after)

Connect to SmartHomeEnd signal.

getAutoIndent
bool getAutoIndent()

Returns whether auto-indentation of text is enabled.

getBackgroundPattern
gtksource.types.BackgroundPatternType getBackgroundPattern()

Returns the #GtkSourceBackgroundPatternType specifying if and how the background pattern should be displayed for this view.

getCompletion
gtksource.completion.Completion getCompletion()

Gets the classCompletion associated with view.

getEnableSnippets
bool getEnableSnippets()

Gets the propertyView:enable-snippets property.

getGutter
gtksource.gutter.Gutter getGutter(gtk.types.TextWindowType windowType)

Returns the classGutter object associated with window_type for view.

getHighlightCurrentLine
bool getHighlightCurrentLine()

Returns whether the current line is highlighted.

getHover
gtksource.hover.Hover getHover()

Gets the classHover associated with view.

getIndentOnTab
bool getIndentOnTab()

Returns whether when the tab key is pressed the current selection should get indented instead of replaced with the \t character.

getIndentWidth
int getIndentWidth()

Returns the number of spaces to use for each step of indent.

getIndenter
gtksource.indenter.Indenter getIndenter()

Gets the propertyView:indenter property.

getInsertSpacesInsteadOfTabs
bool getInsertSpacesInsteadOfTabs()

Returns whether when inserting a tabulator character it should be replaced by a group of space characters.

getMarkAttributes
gtksource.mark_attributes.MarkAttributes getMarkAttributes(string category, int priority)

Gets attributes and priority for the category.

getRightMarginPosition
uint getRightMarginPosition()

Gets the position of the right margin in the given view.

getShowLineMarks
bool getShowLineMarks()

Returns whether line marks are displayed beside the text.

getShowLineNumbers
bool getShowLineNumbers()

Returns whether line numbers are displayed beside the text.

getShowRightMargin
bool getShowRightMargin()

Returns whether a right margin is displayed.

getSmartBackspace
bool getSmartBackspace()

Returns true if pressing the Backspace key will try to delete spaces up to the previous tab stop.

getSmartHomeEnd
gtksource.types.SmartHomeEndType getSmartHomeEnd()

Returns a enumSmartHomeEndType end value specifying how the cursor will move when HOME and END keys are pressed.

getSpaceDrawer
gtksource.space_drawer.SpaceDrawer getSpaceDrawer()

Gets the classSpaceDrawer associated with view.

getTabWidth
uint getTabWidth()

Returns the width of tabulation in characters.

getVisualColumn
uint getVisualColumn(gtk.text_iter.TextIter iter)

Determines the visual column at iter taking into consideration the propertyView:tab-width of view.

indentLines
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.

pushSnippet
void pushSnippet(gtksource.snippet.Snippet snippet, gtk.text_iter.TextIter location)

Inserts a new snippet at location

setAutoIndent
void setAutoIndent(bool enable)

If true auto-indentation of text is enabled.

setBackgroundPattern
void setBackgroundPattern(gtksource.types.BackgroundPatternType backgroundPattern)

Set if and how the background pattern should be displayed.

setEnableSnippets
void setEnableSnippets(bool enableSnippets)

Sets the propertyView:enable-snippets property.

setHighlightCurrentLine
void setHighlightCurrentLine(bool highlight)

If highlight is true the current line will be highlighted.

setIndentOnTab
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.

setIndentWidth
void setIndentWidth(int width)

Sets the number of spaces to use for each step of indent when the tab key is pressed.

setIndenter
void setIndenter(gtksource.indenter.Indenter indenter)

Sets the indenter for view to indenter.

setInsertSpacesInsteadOfTabs
void setInsertSpacesInsteadOfTabs(bool enable)

If true a tab key pressed is replaced by a group of space characters.

setMarkAttributes
void setMarkAttributes(string category, gtksource.mark_attributes.MarkAttributes attributes, int priority)

Sets attributes and priority for the category.

setRightMarginPosition
void setRightMarginPosition(uint pos)

Sets the position of the right margin in the given view.

setShowLineMarks
void setShowLineMarks(bool show)

If true line marks will be displayed beside the text.

setShowLineNumbers
void setShowLineNumbers(bool show)

If true line numbers will be displayed beside the text.

setShowRightMargin
void setShowRightMargin(bool show)

If true a right margin is displayed.

setSmartBackspace
void setSmartBackspace(bool smartBackspace)

When set to true, pressing the Backspace key will try to delete spaces up to the previous tab stop.

setSmartHomeEnd
void setSmartHomeEnd(gtksource.types.SmartHomeEndType smartHomeEnd)

Set the desired movement of the cursor when HOME and END keys are pressed.

setTabWidth
void setTabWidth(uint width)

Sets the width of tabulation in characters.

unindentLines
void unindentLines(gtk.text_iter.TextIter start, gtk.text_iter.TextIter end)

Removes one indentation level at the beginning of the specified lines.

Static functions

newWithBuffer
gtksource.view.View newWithBuffer(gtksource.buffer.Buffer buffer)

Creates a new #GtkSourceView widget displaying the buffer buffer.

Inherited Members

From TextView

newWithBuffer
gtk.text_view.TextView newWithBuffer(gtk.text_buffer.TextBuffer buffer)

Creates a new gtk.text_view.TextView widget displaying the buffer buffer.

addChildAtAnchor
void addChildAtAnchor(gtk.widget.Widget child, gtk.text_child_anchor.TextChildAnchor anchor)

Adds a child widget in the text buffer, at the given anchor.

addOverlay
void addOverlay(gtk.widget.Widget child, int xpos, int ypos)

Adds child at a fixed coordinate in the gtk.text_view.TextView's text window.

backwardDisplayLine
bool backwardDisplayLine(gtk.text_iter.TextIter iter)

Moves the given iter backward by one display (wrapped) line.

backwardDisplayLineStart
bool backwardDisplayLineStart(gtk.text_iter.TextIter iter)

Moves the given iter backward to the next display line start.

bufferToWindowCoords
void bufferToWindowCoords(gtk.types.TextWindowType win, int bufferX, int bufferY, int windowX, int windowY)

Converts buffer coordinates to window coordinates.

forwardDisplayLine
bool forwardDisplayLine(gtk.text_iter.TextIter iter)

Moves the given iter forward by one display (wrapped) line.

forwardDisplayLineEnd
bool forwardDisplayLineEnd(gtk.text_iter.TextIter iter)

Moves the given iter forward to the next display line end.

getAcceptsTab
bool getAcceptsTab()

Returns whether pressing the <kbd>Tab</kbd> key inserts a tab characters.

getBottomMargin
int getBottomMargin()

Gets the bottom margin for text in the text_view.

getBuffer
gtk.text_buffer.TextBuffer getBuffer()

Returns the gtk.text_buffer.TextBuffer being displayed by this text view.

getCursorLocations
void getCursorLocations(gtk.text_iter.TextIter iter, gdk.rectangle.Rectangle strong, gdk.rectangle.Rectangle weak)

Determine the positions of the strong and weak cursors if the insertion point is at iter.

getCursorVisible
bool getCursorVisible()

Find out whether the cursor should be displayed.

getEditable
bool getEditable()

Returns the default editability of the gtk.text_view.TextView.

getExtraMenu
gio.menu_model.MenuModel getExtraMenu()

Gets the menu model that gets added to the context menu or null if none has been set.

getGutter
gtk.widget.Widget getGutter(gtk.types.TextWindowType win)

Gets a gtk.widget.Widget that has previously been set as gutter.

getIndent
int getIndent()

Gets the default indentation of paragraphs in text_view.

getInputHints
gtk.types.InputHints getInputHints()

Gets the input-hints of the gtk.text_view.TextView.

getInputPurpose
gtk.types.InputPurpose getInputPurpose()

Gets the input-purpose of the gtk.text_view.TextView.

getIterAtLocation
bool getIterAtLocation(gtk.text_iter.TextIter iter, int x, int y)

Retrieves the iterator at buffer coordinates x and y.

getIterAtPosition
bool getIterAtPosition(gtk.text_iter.TextIter iter, int trailing, int x, int y)

Retrieves the iterator pointing to the character at buffer coordinates x and y.

getIterLocation
void getIterLocation(gtk.text_iter.TextIter iter, gdk.rectangle.Rectangle location)

Gets a rectangle which roughly contains the character at iter.

getJustification
gtk.types.Justification getJustification()

Gets the default justification of paragraphs in text_view.

getLeftMargin
int getLeftMargin()

Gets the default left margin size of paragraphs in the text_view.

getLineAtY
void getLineAtY(gtk.text_iter.TextIter targetIter, int y, int lineTop)

Gets the gtk.text_iter.TextIter at the start of the line containing the coordinate y.

getLineYrange
void getLineYrange(gtk.text_iter.TextIter iter, int y, int height)

Gets the y coordinate of the top of the line containing iter, and the height of the line.

getLtrContext
pango.context.Context getLtrContext()

Gets the pango.context.Context that is used for rendering LTR directed text layouts.

getMonospace
bool getMonospace()

Gets whether the gtk.text_view.TextView uses monospace styling.

getOverwrite
bool getOverwrite()

Returns whether the gtk.text_view.TextView is in overwrite mode or not.

getPixelsAboveLines
int getPixelsAboveLines()

Gets the default number of pixels to put above paragraphs.

getPixelsBelowLines
int getPixelsBelowLines()

Gets the default number of pixels to put below paragraphs.

getPixelsInsideWrap
int getPixelsInsideWrap()

Gets the default number of pixels to put between wrapped lines inside a paragraph.

getRightMargin
int getRightMargin()

Gets the default right margin for text in text_view.

getRtlContext
pango.context.Context getRtlContext()

Gets the pango.context.Context that is used for rendering RTL directed text layouts.

getTabs
pango.tab_array.TabArray getTabs()

Gets the default tabs for text_view.

getTopMargin
int getTopMargin()

Gets the top margin for text in the text_view.

getVisibleRect
void getVisibleRect(gdk.rectangle.Rectangle visibleRect)

Fills visible_rect with the currently-visible region of the buffer, in buffer coordinates.

getWrapMode
gtk.types.WrapMode getWrapMode()

Gets the line wrapping for the view.

imContextFilterKeypress
bool imContextFilterKeypress(gdk.event.Event event)

Allow the gtk.text_view.TextView input method to internally handle key press and release events.

moveMarkOnscreen
bool moveMarkOnscreen(gtk.text_mark.TextMark mark)

Moves a mark within the buffer so that it's located within the currently-visible text area.

moveOverlay
void moveOverlay(gtk.widget.Widget child, int xpos, int ypos)

Updates the position of a child.

moveVisually
bool moveVisually(gtk.text_iter.TextIter iter, int count)

Move the iterator a given number of characters visually, treating it as the strong cursor position.

placeCursorOnscreen
bool placeCursorOnscreen()

Moves the cursor to the currently visible region of the buffer.

remove
void remove(gtk.widget.Widget child)

Removes a child widget from text_view.

resetCursorBlink
void resetCursorBlink()

Ensures that the cursor is shown.

resetImContext
void resetImContext()

Reset the input method context of the text view if needed.

scrollMarkOnscreen
void scrollMarkOnscreen(gtk.text_mark.TextMark mark)

Scrolls text_view the minimum distance such that mark is contained within the visible area of the widget.

scrollToIter
bool scrollToIter(gtk.text_iter.TextIter iter, double withinMargin, bool useAlign, double xalign, double yalign)

Scrolls text_view so that iter is on the screen in the position indicated by xalign and yalign.

scrollToMark
void scrollToMark(gtk.text_mark.TextMark mark, double withinMargin, bool useAlign, double xalign, double yalign)

Scrolls text_view so that mark is on the screen in the position indicated by xalign and yalign.

setAcceptsTab
void setAcceptsTab(bool acceptsTab)

Sets the behavior of the text widget when the <kbd>Tab</kbd> key is pressed.

setBottomMargin
void setBottomMargin(int bottomMargin)

Sets the bottom margin for text in text_view.

setBuffer
void setBuffer(gtk.text_buffer.TextBuffer buffer)

Sets buffer as the buffer being displayed by text_view.

setCursorVisible
void setCursorVisible(bool setting)

Toggles whether the insertion point should be displayed.

setEditable
void setEditable(bool setting)

Sets the default editability of the gtk.text_view.TextView.

setExtraMenu
void setExtraMenu(gio.menu_model.MenuModel model)

Sets a menu model to add when constructing the context menu for text_view.

setGutter
void setGutter(gtk.types.TextWindowType win, gtk.widget.Widget widget)

Places widget into the gutter specified by win.

setIndent
void setIndent(int indent)

Sets the default indentation for paragraphs in text_view.

setInputHints
void setInputHints(gtk.types.InputHints hints)

Sets the input-hints of the gtk.text_view.TextView.

setInputPurpose
void setInputPurpose(gtk.types.InputPurpose purpose)

Sets the input-purpose of the gtk.text_view.TextView.

setJustification
void setJustification(gtk.types.Justification justification)

Sets the default justification of text in text_view.

setLeftMargin
void setLeftMargin(int leftMargin)

Sets the default left margin for text in text_view.

setMonospace
void setMonospace(bool monospace)

Sets whether the gtk.text_view.TextView should display text in monospace styling.

setOverwrite
void setOverwrite(bool overwrite)

Changes the gtk.text_view.TextView overwrite mode.

setPixelsAboveLines
void setPixelsAboveLines(int pixelsAboveLines)

Sets the default number of blank pixels above paragraphs in text_view.

setPixelsBelowLines
void setPixelsBelowLines(int pixelsBelowLines)

Sets the default number of pixels of blank space to put below paragraphs in text_view.

setPixelsInsideWrap
void setPixelsInsideWrap(int pixelsInsideWrap)

Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph.

setRightMargin
void setRightMargin(int rightMargin)

Sets the default right margin for text in the text view.

setTabs
void setTabs(pango.tab_array.TabArray tabs)

Sets the default tab stops for paragraphs in text_view.

setTopMargin
void setTopMargin(int topMargin)

Sets the top margin for text in text_view.

setWrapMode
void setWrapMode(gtk.types.WrapMode wrapMode)

Sets the line wrapping for the view.

startsDisplayLine
bool startsDisplayLine(gtk.text_iter.TextIter iter)

Determines whether iter is at the start of a display line.

windowToBufferCoords
void windowToBufferCoords(gtk.types.TextWindowType win, int windowX, int windowY, int bufferX, int bufferY)

Converts coordinates on the window identified by win to buffer coordinates.

connectBackspace
ulong connectBackspace(T callback, Flag!"After" after)

Connect to Backspace signal.

connectCopyClipboard
ulong connectCopyClipboard(T callback, Flag!"After" after)

Connect to CopyClipboard signal.

connectCutClipboard
ulong connectCutClipboard(T callback, Flag!"After" after)

Connect to CutClipboard signal.

connectDeleteFromCursor
ulong connectDeleteFromCursor(T callback, Flag!"After" after)

Connect to DeleteFromCursor signal.

connectExtendSelection
ulong connectExtendSelection(T callback, Flag!"After" after)

Connect to ExtendSelection signal.

connectInsertAtCursor
ulong connectInsertAtCursor(T callback, Flag!"After" after)

Connect to InsertAtCursor signal.

connectInsertEmoji
ulong connectInsertEmoji(T callback, Flag!"After" after)

Connect to InsertEmoji signal.

connectMoveCursor
ulong connectMoveCursor(T callback, Flag!"After" after)

Connect to MoveCursor signal.

connectMoveViewport
ulong connectMoveViewport(T callback, Flag!"After" after)

Connect to MoveViewport signal.

connectPasteClipboard
ulong connectPasteClipboard(T callback, Flag!"After" after)

Connect to PasteClipboard signal.

connectPreeditChanged
ulong connectPreeditChanged(T callback, Flag!"After" after)

Connect to PreeditChanged signal.

connectSelectAll
ulong connectSelectAll(T callback, Flag!"After" after)

Connect to SelectAll signal.

connectSetAnchor
ulong connectSetAnchor(T callback, Flag!"After" after)

Connect to SetAnchor signal.

connectToggleCursorVisible
ulong connectToggleCursorVisible(T callback, Flag!"After" after)

Connect to ToggleCursorVisible signal.

connectToggleOverwrite
ulong connectToggleOverwrite(T callback, Flag!"After" after)

Connect to ToggleOverwrite signal.