Class View
- All Implemented Interfaces:
Accessible,AccessibleText,Buildable,ConstraintTarget,Scrollable,Proxy
- Direct Known Subclasses:
Map
TextView.
GtkSourceView is the main class of the GtkSourceView library.
Use a 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 Buildable interface exposes the
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 GtkSourceView in a
manner that allows for components like Map to scale the desired
font.
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);
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 TextTag with the Gtk.TextTag:family or
Gtk.TextTag:scale set so that the font size may be scaled relative to
the default font set in CSS.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classView.Builder<B extends View.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theChangeCaseCallbackcallback.static interfaceFunctional interface declaration of theChangeNumberCallbackcallback.static interfaceFunctional interface declaration of theJoinLinesCallbackcallback.static interfaceFunctional interface declaration of theLineMarkActivatedCallbackcallback.static interfaceFunctional interface declaration of theMoveLinesCallbackcallback.static interfaceFunctional interface declaration of theMoveToMatchingBracketCallbackcallback.static interfaceFunctional interface declaration of theMoveWordsCallbackcallback.static interfaceFunctional interface declaration of thePushSnippetCallbackcallback.static interfaceFunctional interface declaration of theShowCompletionCallbackcallback.static interfaceFunctional interface declaration of theSmartHomeEndCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gtk.TextView
TextView.BackspaceCallback, TextView.CopyClipboardCallback, TextView.CutClipboardCallback, TextView.DeleteFromCursorCallback, TextView.ExtendSelectionCallback, TextView.InsertAtCursorCallback, TextView.InsertEmojiCallback, TextView.MoveCursorCallback, TextView.MoveViewportCallback, TextView.PasteClipboardCallback, TextView.PreeditChangedCallback, TextView.SelectAllCallback, TextView.SetAnchorCallback, TextView.TextViewClass, TextView.ToggleCursorVisibleCallback, TextView.ToggleOverwriteCallbackNested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.Widget$Impl, Widget.WidgetClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.AccessibleText
AccessibleText.AccessibleText$Impl, AccessibleText.AccessibleTextInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Scrollable
Scrollable.Scrollable$Impl, Scrollable.ScrollableInterface -
Constructor Summary
ConstructorsConstructorDescriptionView()Creates a new View.View(MemorySegment address) Create a View proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ViewasParent()Returns this instance as if it were its parent type.static View.Builder<? extends View.Builder> builder()AView.Builderobject constructs aViewwith the specified properties.voidemitChangeCase(ChangeCaseType caseType) Emits the "change-case" signal.voidemitChangeNumber(int count) Emits the "change-number" signal.voidEmits the "join-lines" signal.voidemitLineMarkActivated(@Nullable TextIter iter, int button, Set<ModifierType> state, int nPresses) Emits the "line-mark-activated" signal.voidemitMoveLines(boolean down) Emits the "move-lines" signal.voidemitMoveToMatchingBracket(boolean extendSelection) Emits the "move-to-matching-bracket" signal.voidemitMoveWords(int count) Emits the "move-words" signal.voidemitPushSnippet(@Nullable Snippet snippet, @Nullable TextIter location) Emits the "push-snippet" signal.voidEmits the "show-completion" signal.voidemitSmartHomeEnd(@Nullable TextIter iter, int count) Emits the "smart-home-end" signal.Gets theAnnotationsassociated withview.booleanReturns whether auto-indentation of text is enabled.Returns theGtkSourceBackgroundPatternTypespecifying if and how the background pattern should be displayed for thisview.Gets theCompletionassociated withview.booleanGets theView:enable-snippetsproperty.getGutter(TextWindowType windowType) booleanReturns whether the current line is highlighted.getHover()Gets theHoverassociated withview.@Nullable IndenterGets theView:indenterproperty.booleanReturns whether when the tab key is pressed the current selection should get indented instead of replaced with the\\tcharacter.intReturns the number of spaces to use for each step of indent.booleanReturns whether when inserting a tabulator character it should be replaced by a group of space characters.getMarkAttributes(String category, MemorySegment priority) Gets attributes and priority for thecategory.static MemoryLayoutThe memory layout of the native struct.intGets the position of the right margin in the givenview.booleanReturns whether line marks are displayed beside the text.booleanReturns whether line numbers are displayed beside the text.booleanReturns whether a right margin is displayed.booleanReturnstrueif pressing the Backspace key will try to delete spaces up to the previous tab stop.Returns aSmartHomeEndTypeend value specifying how the cursor will move when HOME and END keys are pressed.Gets theSpaceDrawerassociated withview.intReturns the width of tabulation in characters.static @Nullable TypegetType()Get the GType of the View classintgetVisualColumn(TextIter iter) Determines the visual column atitertaking into consideration theView:tab-widthofview.voidindentLines(TextIter start, TextIter end) Inserts one indentation level at the beginning of the specified lines.protected voidlineMarkActivated(TextIter iter, int button, Set<ModifierType> state, int nPresses) protected voidmoveLines(boolean down) protected voidmoveWords(int step) onChangeCase(View.ChangeCaseCallback handler) Keybinding signal to change case of the text at the current cursor position.onChangeNumber(View.ChangeNumberCallback handler) Keybinding signal to edit a number at the current cursor position.onJoinLines(View.JoinLinesCallback handler) Keybinding signal to join the lines currently selected.Emitted when a line mark has been activated (for instance when there was a button press in the line marks gutter).onMoveLines(View.MoveLinesCallback handler) The signal is a keybinding which gets emitted when the user initiates moving a line.Keybinding signal to move the cursor to the matching bracket.onMoveWords(View.MoveWordsCallback handler) The signal is a keybinding which gets emitted when the user initiates moving a word.onPushSnippet(View.PushSnippetCallback handler) The signal is emitted to insert a new snippet into the view.The signal is a key binding signal which gets emitted when the user requests a completion, by pressing <keycombo><keycap>Control</keycap><keycap>space</keycap></keycombo>.onSmartHomeEnd(View.SmartHomeEndCallback handler) Emitted when a the cursor was moved according to the smart home end setting.voidpushSnippet(Snippet snippet, @Nullable TextIter location) Inserts a new snippet atlocationvoidsetAutoIndent(boolean enable) Iftrueauto-indentation of text is enabled.voidsetBackgroundPattern(BackgroundPatternType backgroundPattern) Set if and how the background pattern should be displayed.voidsetEnableSnippets(boolean enableSnippets) Sets theView:enable-snippetsproperty.voidsetHighlightCurrentLine(boolean highlight) Ifhighlightistruethe current line will be highlighted.voidsetIndenter(@Nullable Indenter indenter) Sets the indenter for this View toindenter.voidsetIndentOnTab(boolean enable) Iftrue, 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\\tcharacter.voidsetIndentWidth(int width) Sets the number of spaces to use for each step of indent when the tab key is pressed.voidsetInsertSpacesInsteadOfTabs(boolean enable) Iftruea tab key pressed is replaced by a group of space characters.voidsetMarkAttributes(String category, MarkAttributes attributes, int priority) Sets attributes and priority for thecategory.voidsetRightMarginPosition(int pos) Sets the position of the right margin in the givenview.voidsetShowLineMarks(boolean show) Iftrueline marks will be displayed beside the text.voidsetShowLineNumbers(boolean show) Iftrueline numbers will be displayed beside the text.voidsetShowRightMargin(boolean show) Iftruea right margin is displayed.voidsetSmartBackspace(boolean smartBackspace) When set totrue, pressing the Backspace key will try to delete spaces up to the previous tab stop.voidsetSmartHomeEnd(SmartHomeEndType smartHomeEnd) Set the desired movement of the cursor when HOME and END keys are pressed.voidsetTabWidth(int width) Sets the width of tabulation in characters.protected voidvoidunindentLines(TextIter start, TextIter end) Removes one indentation level at the beginning of the specified lines.static ViewwithBuffer(Buffer buffer) Creates a newGtkSourceViewwidget displaying the bufferbuffer.Methods inherited from class org.gnome.gtk.TextView
addChildAtAnchor, addOverlay, backspace, backwardDisplayLine, backwardDisplayLineStart, bufferToWindowCoords, copyClipboard, createBuffer, cutClipboard, deleteFromCursor, emitBackspace, emitCopyClipboard, emitCutClipboard, emitDeleteFromCursor, emitExtendSelection, emitInsertAtCursor, emitInsertEmoji, emitMoveCursor, emitMoveViewport, emitPasteClipboard, emitPreeditChanged, emitSelectAll, emitSetAnchor, emitToggleCursorVisible, emitToggleOverwrite, extendSelection, forwardDisplayLine, forwardDisplayLineEnd, getAcceptsTab, getBottomMargin, getBuffer, getCursorLocations, getCursorVisible, getEditable, getExtraMenu, getIndent, getInputHints, getInputPurpose, getIterAtLocation, getIterAtPosition, getIterLocation, getJustification, getLeftMargin, getLineAtY, getLineYrange, getLtrContext, getMonospace, getOverwrite, getPixelsAboveLines, getPixelsBelowLines, getPixelsInsideWrap, getRightMargin, getRtlContext, getTabs, getTopMargin, getVisibleOffset, getVisibleRect, getWrapMode, imContextFilterKeypress, insertAtCursor, insertEmoji, moveCursor, moveMarkOnscreen, moveOverlay, moveVisually, onBackspace, onCopyClipboard, onCutClipboard, onDeleteFromCursor, onExtendSelection, onInsertAtCursor, onInsertEmoji, onMoveCursor, onMoveViewport, onPasteClipboard, onPreeditChanged, onSelectAll, onSetAnchor, onToggleCursorVisible, onToggleOverwrite, pasteClipboard, placeCursorOnscreen, remove, resetCursorBlink, resetImContext, scrollMarkOnscreen, scrollToIter, scrollToMark, setAcceptsTab, setAnchor, setBottomMargin, setBuffer, setCursorVisible, setEditable, setExtraMenu, setGutter, setIndent, setInputHints, setInputHints, setInputPurpose, setJustification, setLeftMargin, setMonospace, setOverwrite, setPixelsAboveLines, setPixelsBelowLines, setPixelsInsideWrap, setRightMargin, setTabs, setTopMargin, setWrapMode, snapshotLayer, startsDisplayLine, toggleOverwrite, windowToBufferCoords, withBufferMethods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlagsMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface org.gnome.gtk.AccessibleText
updateCaretPosition, updateContents, updateSelectionBoundMethods inherited from interface org.gnome.gtk.Buildable
getBuildableIdMethods inherited from interface org.gnome.gtk.Scrollable
getBorder, getHadjustment, getHscrollPolicy, getVadjustment, getVscrollPolicy, setHadjustment, setHscrollPolicy, setVadjustment, setVscrollPolicy
-
Constructor Details
-
View
Create a View proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
View
public View()Creates a new View.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
withBuffer
-
getAnnotations
Gets theAnnotationsassociated withview.The returned object is guaranteed to be the same for the lifetime of
view.EachViewobject has a differentAnnotations.- Returns:
- the
GtkSourceAnnotationsassociated withview. - Since:
- 5.18
-
getAutoIndent
public boolean getAutoIndent()Returns whether auto-indentation of text is enabled.- Returns:
trueif auto indentation is enabled.
-
getBackgroundPattern
Returns theGtkSourceBackgroundPatternTypespecifying if and how the background pattern should be displayed for thisview.- Returns:
- the
GtkSourceBackgroundPatternType.
-
getCompletion
Gets theCompletionassociated withview.The returned object is guaranteed to be the same for the lifetime of
view.EachGtkSourceViewobject has a differentCompletion.- Returns:
- the
GtkSourceCompletionassociated withview.
-
getEnableSnippets
public boolean getEnableSnippets()Gets theView:enable-snippetsproperty.If
true, matching snippets found in theSnippetManagermay be expanded when the user presses Tab after a word in theView.- Returns:
trueif enabled
-
getGutter
Returns theGutterobject associated withwindowTypeforview.Only
TextWindowType.LEFTandTextWindowType.RIGHTare supported, respectively corresponding to the left and right gutter. The line numbers and mark category icons are rendered in the left gutter. -
getHighlightCurrentLine
public boolean getHighlightCurrentLine()Returns whether the current line is highlighted.- Returns:
trueif the current line is highlighted.
-
getHover
-
getIndentOnTab
public boolean getIndentOnTab()Returns whether when the tab key is pressed the current selection should get indented instead of replaced with the\\tcharacter.- Returns:
trueif the selection is indented when tab is pressed.
-
getIndentWidth
public int getIndentWidth()Returns the number of spaces to use for each step of indent.See
setIndentWidth(int)for details.- Returns:
- indent width.
-
getIndenter
Gets theView:indenterproperty.- Returns:
- a
GtkSourceIndenterornull
-
getInsertSpacesInsteadOfTabs
public boolean getInsertSpacesInsteadOfTabs()Returns whether when inserting a tabulator character it should be replaced by a group of space characters.- Returns:
trueif spaces are inserted instead of tabs.
-
getMarkAttributes
Gets attributes and priority for thecategory.- Parameters:
category- the category.priority- place where priority of the category will be stored.- Returns:
GtkSourceMarkAttributesfor thecategory.The object belongs toview,so it must not be unreffed.
-
getRightMarginPosition
public int getRightMarginPosition()Gets the position of the right margin in the givenview.- Returns:
- the position of the right margin.
-
getShowLineMarks
public boolean getShowLineMarks()Returns whether line marks are displayed beside the text.- Returns:
trueif the line marks are displayed.
-
getShowLineNumbers
public boolean getShowLineNumbers()Returns whether line numbers are displayed beside the text.- Returns:
trueif the line numbers are displayed.
-
getShowRightMargin
public boolean getShowRightMargin()Returns whether a right margin is displayed.- Returns:
trueif the right margin is shown.
-
getSmartBackspace
public boolean getSmartBackspace()Returnstrueif pressing the Backspace key will try to delete spaces up to the previous tab stop.- Returns:
trueif smart Backspace handling is enabled.
-
getSmartHomeEnd
Returns aSmartHomeEndTypeend value specifying how the cursor will move when HOME and END keys are pressed.- Returns:
- a
GtkSourceSmartHomeEndTypevalue.
-
getSpaceDrawer
Gets theSpaceDrawerassociated withview.The returned object is guaranteed to be the same for the lifetime of
view.EachViewobject has a differentSpaceDrawer.- Returns:
- the
GtkSourceSpaceDrawerassociated withview.
-
getTabWidth
public int getTabWidth()Returns the width of tabulation in characters.- Returns:
- width of tab.
-
getVisualColumn
Determines the visual column atitertaking into consideration theView:tab-widthofview.- Parameters:
iter- a position inview.- Returns:
- the visual column at
iter.
-
indentLines
-
pushSnippet
Inserts a new snippet atlocationIf another snippet was already active, it will be paused and the new snippet will become active. Once the focus positions of
snippethave been exhausted, editing will return to the previous snippet.- Parameters:
snippet- aGtkSourceSnippetlocation- aGtkTextIterornullfor the cursor position
-
setAutoIndent
public void setAutoIndent(boolean enable) Iftrueauto-indentation of text is enabled.When Enter is pressed to create a new line, the auto-indentation inserts the same indentation as the previous line. This is not a "smart indentation" where an indentation level is added or removed depending on the context.
- Parameters:
enable- whether to enable auto indentation.
-
setBackgroundPattern
Set if and how the background pattern should be displayed.- Parameters:
backgroundPattern- theGtkSourceBackgroundPatternType.
-
setEnableSnippets
public void setEnableSnippets(boolean enableSnippets) Sets theView:enable-snippetsproperty.If
enableSnippetsistrue, matching snippets found in theSnippetManagermay be expanded when the user presses Tab after a word in theView.- Parameters:
enableSnippets- if snippets should be enabled
-
setHighlightCurrentLine
public void setHighlightCurrentLine(boolean highlight) Ifhighlightistruethe current line will be highlighted.- Parameters:
highlight- whether to highlight the current line.
-
setIndentOnTab
public void setIndentOnTab(boolean enable) Iftrue, 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\\tcharacter. Shift+Tab unindents the selection.If the first or last line is not selected completely, it is also indented or unindented.
When the selection doesn't span several lines, the tab key always replaces the selection with a normal
\\tcharacter.- Parameters:
enable- whether to indent a block when tab is pressed.
-
setIndentWidth
public void setIndentWidth(int width) Sets the number of spaces to use for each step of indent when the tab key is pressed.If
widthis -1, the value of theView:tab-widthproperty will be used.The
View:indent-widthinteracts with theView:insert-spaces-instead-of-tabsproperty andView:tab-width. An example will be clearer:If the
View:indent-widthis 4 andView:tab-widthis 8 andView:insert-spaces-instead-of-tabsisfalse, then pressing the tab key at the beginning of a line will insert 4 spaces. So far so good. Pressing the tab key a second time will remove the 4 spaces and insert a\\tcharacter instead (sinceView:tab-widthis 8). On the other hand, ifView:insert-spaces-instead-of-tabsistrue, the second tab key pressed will insert 4 more spaces for a total of 8 spaces in theTextBuffer.The test-widget program (available in the GtkSourceView repository) may be useful to better understand the indentation settings (enable the space drawing!).
- Parameters:
width- indent width in characters.
-
setIndenter
Sets the indenter for this View toindenter.Note that the indenter will not be used unless
GtkSourceView:auto-indent has been set totrue.- Parameters:
indenter- aGtkSourceIndenterornull
-
setInsertSpacesInsteadOfTabs
public void setInsertSpacesInsteadOfTabs(boolean enable) Iftruea tab key pressed is replaced by a group of space characters.Of course it is still possible to insert a real
\\tprogrammatically with theTextBufferAPI.- Parameters:
enable- whether to insert spaces instead of tabs.
-
setMarkAttributes
Sets attributes and priority for thecategory.- Parameters:
category- the category.attributes- mark attributes.priority- priority of the category.
-
setRightMarginPosition
public void setRightMarginPosition(int pos) Sets the position of the right margin in the givenview.- Parameters:
pos- the width in characters where to position the right margin.
-
setShowLineMarks
public void setShowLineMarks(boolean show) Iftrueline marks will be displayed beside the text.- Parameters:
show- whether line marks should be displayed.
-
setShowLineNumbers
public void setShowLineNumbers(boolean show) Iftrueline numbers will be displayed beside the text.- Parameters:
show- whether line numbers should be displayed.
-
setShowRightMargin
public void setShowRightMargin(boolean show) Iftruea right margin is displayed.- Parameters:
show- whether to show a right margin.
-
setSmartBackspace
public void setSmartBackspace(boolean smartBackspace) When set totrue, pressing the Backspace key will try to delete spaces up to the previous tab stop.- Parameters:
smartBackspace- whether to enable smart Backspace handling.
-
setSmartHomeEnd
Set the desired movement of the cursor when HOME and END keys are pressed.- Parameters:
smartHomeEnd- the desired behavior amongGtkSourceSmartHomeEndType.
-
setTabWidth
public void setTabWidth(int width) Sets the width of tabulation in characters.The
GtkTextBufferstill contains\\tcharacters, but they can take a different visual width in aViewwidget.- Parameters:
width- width of tab in characters.
-
unindentLines
-
lineMarkActivated
-
moveLines
protected void moveLines(boolean down) -
moveWords
protected void moveWords(int step) -
showCompletion
protected void showCompletion() -
onChangeCase
Keybinding signal to change case of the text at the current cursor position.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChangeCase
Emits the "change-case" signal. SeeonChangeCase(org.gnome.gtksourceview.View.ChangeCaseCallback). -
onChangeNumber
public SignalConnection<View.ChangeNumberCallback> onChangeNumber(View.ChangeNumberCallback handler) Keybinding signal to edit a number at the current cursor position.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChangeNumber
public void emitChangeNumber(int count) Emits the "change-number" signal. SeeonChangeNumber(org.gnome.gtksourceview.View.ChangeNumberCallback). -
onJoinLines
Keybinding signal to join the lines currently selected.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitJoinLines
public void emitJoinLines()Emits the "join-lines" signal. SeeonJoinLines(org.gnome.gtksourceview.View.JoinLinesCallback). -
onLineMarkActivated
public SignalConnection<View.LineMarkActivatedCallback> onLineMarkActivated(View.LineMarkActivatedCallback handler) Emitted when a line mark has been activated (for instance when there was a button press in the line marks gutter).You can use
iterto determine on which line the activation took place.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitLineMarkActivated
public void emitLineMarkActivated(@Nullable TextIter iter, int button, Set<ModifierType> state, int nPresses) Emits the "line-mark-activated" signal. SeeonLineMarkActivated(org.gnome.gtksourceview.View.LineMarkActivatedCallback). -
onMoveLines
The signal is a keybinding which gets emitted when the user initiates moving a line.The default binding key is Alt+Up/Down arrow. And moves the currently selected lines, or the current line up or down by one line.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMoveLines
public void emitMoveLines(boolean down) Emits the "move-lines" signal. SeeonMoveLines(org.gnome.gtksourceview.View.MoveLinesCallback). -
onMoveToMatchingBracket
public SignalConnection<View.MoveToMatchingBracketCallback> onMoveToMatchingBracket(View.MoveToMatchingBracketCallback handler) Keybinding signal to move the cursor to the matching bracket.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMoveToMatchingBracket
public void emitMoveToMatchingBracket(boolean extendSelection) Emits the "move-to-matching-bracket" signal. SeeonMoveToMatchingBracket(org.gnome.gtksourceview.View.MoveToMatchingBracketCallback). -
onMoveWords
The signal is a keybinding which gets emitted when the user initiates moving a word.The default binding key is Alt+Left/Right Arrow and moves the current selection, or the current word by one word.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMoveWords
public void emitMoveWords(int count) Emits the "move-words" signal. SeeonMoveWords(org.gnome.gtksourceview.View.MoveWordsCallback). -
onPushSnippet
The signal is emitted to insert a new snippet into the view.If another snippet was active, it will be paused until all focus positions of
snippethave been exhausted.locationwill be updated to point at the end of the snippet.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPushSnippet
Emits the "push-snippet" signal. SeeonPushSnippet(org.gnome.gtksourceview.View.PushSnippetCallback). -
onShowCompletion
public SignalConnection<View.ShowCompletionCallback> onShowCompletion(View.ShowCompletionCallback handler) The signal is a key binding signal which gets emitted when the user requests a completion, by pressing <keycombo><keycap>Control</keycap><keycap>space</keycap></keycombo>.This will create a
CompletionContextwith the activation type asCompletionActivation.USER_REQUESTED.Applications should not connect to it, but may emit it with
GObjects.signalEmitByName(org.gnome.gobject.GObject, java.lang.String, java.lang.Object...)if they need to activate the completion by another means, for example with another key binding or a menu entry.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitShowCompletion
public void emitShowCompletion()Emits the "show-completion" signal. SeeonShowCompletion(org.gnome.gtksourceview.View.ShowCompletionCallback). -
onSmartHomeEnd
public SignalConnection<View.SmartHomeEndCallback> onSmartHomeEnd(View.SmartHomeEndCallback handler) Emitted when a the cursor was moved according to the smart home end setting.The signal is emitted after the cursor is moved, but during the
Gtk.TextView::move-cursoraction. This can be used to find out whether the cursor was moved by a normal home/end or by a smart home/end.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitSmartHomeEnd
Emits the "smart-home-end" signal. SeeonSmartHomeEnd(org.gnome.gtksourceview.View.SmartHomeEndCallback). -
builder
AView.Builderobject constructs aViewwith the specified properties. Use the variousset...()methods to set properties, and finish construction withView.Builder.build().- Returns:
- the builder object
-