Class TextBuffer

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
Buffer

@Generated("org.javagi.JavaGI") public class TextBuffer extends GObject

Stores text and attributes for display in a GtkTextView.

You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.

GtkTextBuffer can support undoing changes to the buffer content, see setEnableUndo(boolean).

  • Constructor Details

    • TextBuffer

      public TextBuffer(MemorySegment address)
      Create a TextBuffer instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • TextBuffer

      public TextBuffer(@Nullable TextTagTable table)
      Creates a new text buffer.
      Parameters:
      table - a tag table, or null to create a new one
    • TextBuffer

      public TextBuffer()
      Create a new TextBuffer.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the TextBuffer class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected TextBuffer asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • addCommitNotify

      public int addCommitNotify(Set<TextBufferNotifyFlags> flags, @Nullable TextBufferCommitNotify commitNotify)

      Adds a Gtk.TextBufferCommitNotify to be called when a change is to be made to the Gtk.TextBuffer.

      Functions are explicitly forbidden from making changes to the Gtk.TextBuffer from this callback. It is intended for tracking changes to the buffer only.

      It may be advantageous to use Gtk.TextBufferCommitNotify over connecting to the Gtk.TextBuffer::insert-text or Gtk.TextBuffer::delete-range signals to avoid ordering issues with other signal handlers which may further modify the Gtk.TextBuffer.

      Parameters:
      flags - which notifications should be dispatched to callback
      commitNotify - a Gtk.TextBufferCommitNotify to call for commit notifications
      Returns:
      a handler id which may be used to remove the commit notify callback using removeCommitNotify(int).
      Since:
      4.16
    • addCommitNotify

      public int addCommitNotify(TextBufferNotifyFlags flags, @Nullable TextBufferCommitNotify commitNotify)

      Adds a Gtk.TextBufferCommitNotify to be called when a change is to be made to the Gtk.TextBuffer.

      Functions are explicitly forbidden from making changes to the Gtk.TextBuffer from this callback. It is intended for tracking changes to the buffer only.

      It may be advantageous to use Gtk.TextBufferCommitNotify over connecting to the Gtk.TextBuffer::insert-text or Gtk.TextBuffer::delete-range signals to avoid ordering issues with other signal handlers which may further modify the Gtk.TextBuffer.

      Parameters:
      flags - which notifications should be dispatched to callback
      commitNotify - a Gtk.TextBufferCommitNotify to call for commit notifications
      Returns:
      a handler id which may be used to remove the commit notify callback using removeCommitNotify(int).
      Since:
      4.16
    • addMark

      public void addMark(TextMark mark, TextIter where)

      Adds the mark at position where.

      The mark must not be added to another buffer, and if its name is not null then there must not be another mark in the buffer with the same name.

      Emits the Gtk.TextBuffer::mark-set signal as notification of the mark's initial placement.

      Parameters:
      mark - the mark to add
      where - location to place mark
    • addSelectionClipboard

      public void addSelectionClipboard(Clipboard clipboard)

      Adds clipboard to the list of clipboards in which the selection contents of this TextBuffer are available.

      In most cases, clipboard will be the GdkClipboard returned by Widget.getPrimaryClipboard() for a view of buffer.

      Parameters:
      clipboard - a GdkClipboard
    • applyTag

      public void applyTag(TextTag tag, TextIter start, TextIter end)

      Emits the “apply-tag” signal on buffer.

      The default handler for the signal applies tag to the given range. start and end do not have to be in order.

      Parameters:
      tag - a GtkTextTag
      start - one bound of range to be tagged
      end - other bound of range to be tagged
    • applyTagByName

      public void applyTagByName(String name, TextIter start, TextIter end)

      Emits the “apply-tag” signal on buffer.

      Calls TextTagTable.lookup(String) on the buffer’s tag table to get a GtkTextTag, then calls applyTag(TextTag, TextIter, TextIter).

      Parameters:
      name - name of a named GtkTextTag
      start - one bound of range to be tagged
      end - other bound of range to be tagged
    • backspace

      public boolean backspace(TextIter iter, boolean interactive, boolean defaultEditable)

      Performs the appropriate action as if the user hit the delete key with the cursor at the position specified by iter.

      In the normal case a single character will be deleted, but when combining accents are involved, more than one character can be deleted, and when precomposed character and accent combinations are involved, less than one character will be deleted.

      Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the iter will be re-initialized to point to the location where text was deleted.

      Parameters:
      iter - a position in this TextBuffer
      interactive - whether the deletion is caused by user interaction
      defaultEditable - whether the buffer is editable by default
      Returns:
      true if the buffer was modified
    • beginIrreversibleAction

      public void beginIrreversibleAction()

      Denotes the beginning of an action that may not be undone.

      This will cause any previous operations in the undo/redo queue to be cleared.

      This should be paired with a call to endIrreversibleAction() after the irreversible action has completed.

      You may nest calls to gtk_text_buffer_begin_irreversible_action() and gtk_text_buffer_end_irreversible_action() pairs.

    • beginUserAction

      public void beginUserAction()

      Called to indicate that the buffer operations between here and a call to gtk_text_buffer_end_user_action() are part of a single user-visible operation.

      The operations between gtk_text_buffer_begin_user_action() and gtk_text_buffer_end_user_action() can then be grouped when creating an undo stack. GtkTextBuffer maintains a count of calls to gtk_text_buffer_begin_user_action() that have not been closed with a call to gtk_text_buffer_end_user_action(), and emits the “begin-user-action” and “end-user-action” signals only for the outermost pair of calls. This allows you to build user actions from other user actions.

      The “interactive” buffer mutation functions, such as insertInteractive(TextIter, String, int, boolean), automatically call begin/end user action around the buffer operations they perform, so there's no need to add extra calls if you user action consists solely of a single call to one of those functions.

    • copyClipboard

      public void copyClipboard(Clipboard clipboard)
      Copies the currently-selected text to a clipboard.
      Parameters:
      clipboard - the GdkClipboard object to copy to
    • createChildAnchor

      public TextChildAnchor createChildAnchor(TextIter iter)

      Creates and inserts a child anchor.

      This is a convenience function which simply creates a child anchor with TextChildAnchor() and inserts it into the buffer with insertChildAnchor(TextIter, TextChildAnchor).

      The new anchor is owned by the buffer; no reference count is returned to the caller of this function.

      Parameters:
      iter - location in the buffer
      Returns:
      the created child anchor
    • createMark

      public TextMark createMark(@Nullable String markName, TextIter where, boolean leftGravity)

      Creates a mark at position where.

      If markName is null, the mark is anonymous; otherwise, the mark can be retrieved by name using getMark(String). If a mark has left gravity, and text is inserted at the mark’s current location, the mark will be moved to the left of the newly-inserted text. If the mark has right gravity (leftGravity = false), the mark will end up on the right of newly-inserted text. The standard left-to-right cursor is a mark with right gravity (when you type, the cursor stays on the right side of the text you’re typing).

      The caller of this function does not own a reference to the returned GtkTextMark, so you can ignore the return value if you like. Marks are owned by the buffer and go away when the buffer does.

      Emits the Gtk.TextBuffer::mark-set signal as notification of the mark's initial placement.

      Parameters:
      markName - name for mark
      where - location to place mark
      leftGravity - whether the mark has left gravity
      Returns:
      the new GtkTextMark object
    • createTag

      public TextTag createTag(@Nullable String tagName, @Nullable String firstPropertyName, Object... varargs)

      Creates a tag and adds it to the tag table for buffer.

      Equivalent to calling TextTag() and then adding the tag to the buffer’s tag table. The returned tag is owned by the buffer’s tag table, so the ref count will be equal to one.

      If tagName is null, the tag is anonymous.

      If tagName is non-null, a tag called tagName must not already exist in the tag table for this buffer.

      The firstPropertyName argument and subsequent arguments are a list of properties to set on the tag, as with g_object_set().

      Parameters:
      tagName - name of the new tag
      firstPropertyName - name of first property to set
      varargs - null-terminated list of property names and values
      Returns:
      a new tag
    • cutClipboard

      public void cutClipboard(Clipboard clipboard, boolean defaultEditable)
      Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.
      Parameters:
      clipboard - the GdkClipboard object to cut to
      defaultEditable - default editability of the buffer
    • delete

      public void delete(TextIter start, TextIter end)

      Deletes text between start and end.

      The order of start and end is not actually relevant; gtk_text_buffer_delete() will reorder them.

      This function actually emits the “delete-range” signal, and the default handler of that signal deletes the text. Because the buffer is modified, all outstanding iterators become invalid after calling this function; however, the start and end will be re-initialized to point to the location where text was deleted.

      Parameters:
      start - a position in this TextBuffer
      end - another position in this TextBuffer
    • deleteInteractive

      public boolean deleteInteractive(TextIter startIter, TextIter endIter, boolean defaultEditable)

      Deletes all editable text in the given range.

      Calls delete(TextIter, TextIter) for each editable sub-range of [end). start and end are revalidated to point to the location of the last deleted range, or left untouched if no text was deleted.

      Parameters:
      startIter - start of range to delete
      endIter - end of range
      defaultEditable - whether the buffer is editable by default
      Returns:
      whether some text was actually deleted
    • deleteMark

      public void deleteMark(TextMark mark)

      Deletes mark, so that it’s no longer located anywhere in the buffer.

      Removes the reference the buffer holds to the mark, so if you haven’t called g_object_ref() on the mark, it will be freed. Even if the mark isn’t freed, most operations on mark become invalid, until it gets added to a buffer again with addMark(TextMark, TextIter). Use TextMark.getDeleted() to find out if a mark has been removed from its buffer.

      The Gtk.TextBuffer::mark-deleted signal will be emitted as notification after the mark is deleted.

      Parameters:
      mark - a GtkTextMark in this TextBuffer
    • deleteMarkByName

      public void deleteMarkByName(String name)

      Deletes the mark named name; the mark must exist.

      See deleteMark(TextMark) for details.

      Parameters:
      name - name of a mark in this TextBuffer
    • deleteSelection

      public boolean deleteSelection(boolean interactive, boolean defaultEditable)

      Deletes the range between the “insert” and “selection_bound” marks, that is, the currently-selected text.

      If interactive is true, the editability of the selection will be considered (users can’t delete uneditable text).

      Parameters:
      interactive - whether the deletion is caused by user interaction
      defaultEditable - whether the buffer is editable by default
      Returns:
      whether there was a non-empty selection to delete
    • endIrreversibleAction

      public void endIrreversibleAction()

      Denotes the end of an action that may not be undone.

      This will cause any previous operations in the undo/redo queue to be cleared.

      This should be called after completing modifications to the text buffer after beginIrreversibleAction() was called.

      You may nest calls to gtk_text_buffer_begin_irreversible_action() and gtk_text_buffer_end_irreversible_action() pairs.

    • endUserAction

      public void endUserAction()

      Ends a user-visible operation.

      Should be paired with a call to beginUserAction(). See that function for a full explanation.

    • getBounds

      public void getBounds(TextIter start, TextIter end)
      Retrieves the first and last iterators in the buffer, i.e. the entire buffer lies within the range [end).
      Parameters:
      start - iterator to initialize with first position in the buffer
      end - iterator to initialize with the end iterator
    • getCanRedo

      public boolean getCanRedo()
      Gets whether there is a redoable action in the history.
      Returns:
      true if there is a redoable action
    • getCanUndo

      public boolean getCanUndo()
      Gets whether there is an undoable action in the history.
      Returns:
      true if there is an undoable action
    • getCharCount

      public int getCharCount()

      Gets the number of characters in the buffer.

      Note that characters and bytes are not the same, you can’t e.g. expect the contents of the buffer in string form to be this many bytes long.

      The character count is cached, so this function is very fast.

      Returns:
      number of characters in the buffer
    • getEnableUndo

      public boolean getEnableUndo()

      Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions.

      See beginIrreversibleAction() and endIrreversibleAction() to create changes to the buffer that cannot be undone.

      Returns:
      true if undoing and redoing changes to the buffer is allowed.
    • getEndIter

      public void getEndIter(TextIter iter)

      Initializes iter with the “end iterator,” one past the last valid character in the text buffer.

      If dereferenced with TextIter.getChar(), the end iterator has a character value of 0. The entire buffer lies in the range from the first position in the buffer (call getStartIter(TextIter) to get character position 0) to the end iterator.

      Parameters:
      iter - iterator to initialize
    • getHasSelection

      public boolean getHasSelection()
      Indicates whether the buffer has some text currently selected.
      Returns:
      true if the there is text selected
    • getInsert

      public TextMark getInsert()

      Returns the mark that represents the cursor (insertion point).

      Equivalent to calling getMark(String) to get the mark named “insert”, but very slightly more efficient, and involves less typing.

      Returns:
      insertion point mark
    • getIterAtChildAnchor

      public void getIterAtChildAnchor(TextIter iter, TextChildAnchor anchor)
      Obtains the location of anchor within buffer.
      Parameters:
      iter - an iterator to be initialized
      anchor - a child anchor that appears in this TextBuffer
    • getIterAtLine

      public boolean getIterAtLine(TextIter iter, int lineNumber)

      Initializes iter to the start of the given line.

      If lineNumber is greater than or equal to the number of lines in the buffer, the end iterator is returned.

      Parameters:
      iter - iterator to initialize
      lineNumber - line number counting from 0
      Returns:
      whether the exact position has been found
    • getIterAtLineIndex

      public boolean getIterAtLineIndex(TextIter iter, int lineNumber, int byteIndex)

      Obtains an iterator pointing to byteIndex within the given line.

      byteIndex must be the start of a UTF-8 character. Note bytes, not characters; UTF-8 may encode one character as multiple bytes.

      If lineNumber is greater than or equal to the number of lines in the buffer, the end iterator is returned. And if byteIndex is off the end of the line, the iterator at the end of the line is returned.

      Parameters:
      iter - iterator to initialize
      lineNumber - line number counting from 0
      byteIndex - byte index from start of line
      Returns:
      whether the exact position has been found
    • getIterAtLineOffset

      public boolean getIterAtLineOffset(TextIter iter, int lineNumber, int charOffset)

      Obtains an iterator pointing to charOffset within the given line.

      Note characters, not bytes; UTF-8 may encode one character as multiple bytes.

      If lineNumber is greater than or equal to the number of lines in the buffer, the end iterator is returned. And if charOffset is off the end of the line, the iterator at the end of the line is returned.

      Parameters:
      iter - iterator to initialize
      lineNumber - line number counting from 0
      charOffset - char offset from start of line
      Returns:
      whether the exact position has been found
    • getIterAtMark

      public void getIterAtMark(TextIter iter, TextMark mark)
      Initializes iter with the current position of mark.
      Parameters:
      iter - iterator to initialize
      mark - a GtkTextMark in this TextBuffer
    • getIterAtOffset

      public void getIterAtOffset(TextIter iter, int charOffset)

      Initializes iter to a position charOffset chars from the start of the entire buffer.

      If charOffset is -1 or greater than the number of characters in the buffer, iter is initialized to the end iterator, the iterator one past the last valid character in the buffer.

      Parameters:
      iter - iterator to initialize
      charOffset - char offset from start of buffer, counting from 0, or -1
    • getLineCount

      public int getLineCount()

      Obtains the number of lines in the buffer.

      This value is cached, so the function is very fast.

      Returns:
      number of lines in the buffer
    • getMark

      public @Nullable TextMark getMark(String name)
      Returns the mark named name in buffer buffer, or null if no such mark exists in the buffer.
      Parameters:
      name - a mark name
      Returns:
      a GtkTextMark
    • getMaxUndoLevels

      public int getMaxUndoLevels()

      Gets the maximum number of undo levels to perform.

      If 0, unlimited undo actions may be performed. Note that this may have a memory usage impact as it requires storing an additional copy of the inserted or removed text within the text buffer.

      Returns:
      The max number of undo levels allowed (0 indicates unlimited).
    • getModified

      public boolean getModified()

      Indicates whether the buffer has been modified since the last call to setModified(boolean) set the modification flag to false.

      Used for example to enable a “save” function in a text editor.

      Returns:
      true if the buffer has been modified
    • getSelectionBound

      public TextMark getSelectionBound()

      Returns the mark that represents the selection bound.

      Equivalent to calling getMark(String) to get the mark named “selection_bound”, but very slightly more efficient, and involves less typing.

      The currently-selected text in this TextBuffer is the region between the “selection_bound” and “insert” marks. If “selection_bound” and “insert” are in the same place, then there is no current selection. getSelectionBounds(TextIter, TextIter) is another convenient function for handling the selection, if you just want to know whether there’s a selection and what its bounds are.

      Returns:
      selection bound mark
    • getSelectionBounds

      public boolean getSelectionBounds(TextIter start, TextIter end)

      Returns true if some text is selected; places the bounds of the selection in start and end.

      If the selection has length 0, then start and end are filled in with the same value. start and end will be in ascending order. If start and end are null, then they are not filled in, but the return value still indicates whether text is selected.

      Parameters:
      start - iterator to initialize with selection start
      end - iterator to initialize with selection end
      Returns:
      whether the selection has nonzero length
    • getSelectionContent

      public ContentProvider getSelectionContent()

      Get a content provider for this buffer.

      It can be used to make the content of this TextBuffer available in a GdkClipboard, see Clipboard#setContent.

      Returns:
      a new GdkContentProvider.
    • getSlice

      public String getSlice(TextIter start, TextIter end, boolean includeHiddenChars)

      Returns the text in the range `end).

      Excludes undisplayed text (text marked with tags that set the invisibility attribute) if @include_hidden_chars is %FALSE. The returned string includes a 0xFFFC character whenever the buffer contains embedded images, so byte and character indexes into the returned string do correspond to byte and character indexes into the buffer. Contrast with [method@Gtk.TextBuffer.get_text`. Note that 0xFFFC can occur in normal text as well, so it is not a reliable indicator that a paintable or widget is in the buffer.

      Parameters:
      start - start of a range
      end - end of a range
      includeHiddenChars - whether to include invisible text
      Returns:
      an allocated UTF-8 string
    • getStartIter

      public void getStartIter(TextIter iter)

      Initialized iter with the first position in the text buffer.

      This is the same as using getIterAtOffset(TextIter, int) to get the iter at character offset 0.

      Parameters:
      iter - iterator to initialize
    • getTagTable

      public TextTagTable getTagTable()
      Get the GtkTextTagTable associated with this buffer.
      Returns:
      the buffer’s tag table
    • getText

      public String getText(TextIter start, TextIter end, boolean includeHiddenChars)

      Returns the text in the range `end).

      Excludes undisplayed text (text marked with tags that set the invisibility attribute) if @include_hidden_chars is %FALSE. Does not include characters representing embedded images, so byte and character indexes into the returned string do not correspond to byte and character indexes into the buffer. Contrast with [method@Gtk.TextBuffer.get_slice`.

      Parameters:
      start - start of a range
      end - end of a range
      includeHiddenChars - whether to include invisible text
      Returns:
      an allocated UTF-8 string
    • insert

      public void insert(TextIter iter, String text, int len)

      Inserts len bytes of text at position iter.

      If len is -1, text must be nul-terminated and will be inserted in its entirety. Emits the “insert-text” signal; insertion actually occurs in the default handler for the signal. iter is invalidated when insertion occurs (because the buffer contents change), but the default signal handler revalidates it to point to the end of the inserted text.

      Parameters:
      iter - a position in the buffer
      text - text in UTF-8 format
      len - length of text in bytes, or -1
    • insertAtCursor

      public void insertAtCursor(String text, int len)

      Inserts text in buffer.

      Simply calls insert(TextIter, String, int), using the current cursor position as the insertion point.

      Parameters:
      text - text in UTF-8 format
      len - length of text, in bytes
    • insertChildAnchor

      public void insertChildAnchor(TextIter iter, TextChildAnchor anchor)

      Inserts a child widget anchor into the text buffer at iter.

      The anchor will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for child anchors, but the “text” variants do not. E.g. see getSlice(TextIter, TextIter, boolean) and getText(TextIter, TextIter, boolean).

      Consider createChildAnchor(TextIter) as a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion.

      Parameters:
      iter - location to insert the anchor
      anchor - a GtkTextChildAnchor
    • insertInteractive

      public boolean insertInteractive(TextIter iter, String text, int len, boolean defaultEditable)

      Inserts text in buffer.

      Like insert(TextIter, String, int), but the insertion will not occur if iter is at a non-editable location in the buffer. Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive).

      defaultEditable indicates the editability of text that doesn't have a tag affecting editability applied to it. Typically the result of TextView.getEditable() is appropriate here.

      Parameters:
      iter - a position in this TextBuffer
      text - some UTF-8 text
      len - length of text in bytes, or -1
      defaultEditable - default editability of buffer
      Returns:
      whether text was actually inserted
    • insertInteractiveAtCursor

      public boolean insertInteractiveAtCursor(String text, int len, boolean defaultEditable)

      Inserts text in buffer.

      Calls insertInteractive(TextIter, String, int, boolean) at the cursor position.

      defaultEditable indicates the editability of text that doesn't have a tag affecting editability applied to it. Typically the result of TextView.getEditable() is appropriate here.

      Parameters:
      text - text in UTF-8 format
      len - length of text in bytes, or -1
      defaultEditable - default editability of buffer
      Returns:
      whether text was actually inserted
    • insertMarkup

      public void insertMarkup(TextIter iter, String markup, int len)

      Inserts the text in markup at position iter.

      markup will be inserted in its entirety and must be nul-terminated and valid UTF-8. Emits the Gtk.TextBuffer::insert-text signal, possibly multiple times; insertion actually occurs in the default handler for the signal. iter will point to the end of the inserted text on return.

      Parameters:
      iter - location to insert the markup
      markup - a nul-terminated UTF-8 string containing Pango markup
      len - length of markup in bytes, or -1
    • insertPaintable

      public void insertPaintable(TextIter iter, Paintable paintable)

      Inserts an image into the text buffer at iter.

      The image will be counted as one character in character counts, and when obtaining the buffer contents as a string, will be represented by the Unicode “object replacement character” 0xFFFC. Note that the “slice” variants for obtaining portions of the buffer as a string include this character for paintable, but the “text” variants do not. e.g. see getSlice(TextIter, TextIter, boolean) and getText(TextIter, TextIter, boolean).

      Parameters:
      iter - location to insert the paintable
      paintable - a GdkPaintable
    • insertRange

      public void insertRange(TextIter iter, TextIter start, TextIter end)

      Copies text, tags, and paintables between start and end and inserts the copy at iter.

      The order of start and end doesn’t matter.

      Used instead of simply getting/inserting text because it preserves images and tags. If start and end are in a different buffer from buffer, the two buffers must share the same tag table.

      Implemented via emissions of the ::insert-text and ::apply-tag signals, so expect those.

      Parameters:
      iter - a position in this TextBuffer
      start - a position in a GtkTextBuffer
      end - another position in the same buffer as start
    • insertRangeInteractive

      public boolean insertRangeInteractive(TextIter iter, TextIter start, TextIter end, boolean defaultEditable)

      Copies text, tags, and paintables between start and end and inserts the copy at iter.

      Same as insertRange(TextIter, TextIter, TextIter), but does nothing if the insertion point isn’t editable. The defaultEditable parameter indicates whether the text is editable at iter if no tags enclosing iter affect editability. Typically the result of TextView.getEditable() is appropriate here.

      Parameters:
      iter - a position in this TextBuffer
      start - a position in a GtkTextBuffer
      end - another position in the same buffer as start
      defaultEditable - default editability of the buffer
      Returns:
      whether an insertion was possible at iter
    • insertWithTags

      public void insertWithTags(TextIter iter, String text, int len, TextTag firstTag, Object... varargs)

      Inserts text into this TextBuffer at iter, applying the list of tags to the newly-inserted text.

      The last tag specified must be null to terminate the list. Equivalent to calling insert(TextIter, String, int), then applyTag(TextTag, TextIter, TextIter) on the inserted text; this is just a convenience function.

      Parameters:
      iter - an iterator in this TextBuffer
      text - UTF-8 text
      len - length of text, or -1
      firstTag - first tag to apply to text
      varargs - null-terminated list of tags to apply
    • insertWithTagsByName

      public void insertWithTagsByName(TextIter iter, String text, int len, String firstTagName, Object... varargs)

      Inserts text into this TextBuffer at iter, applying the list of tags to the newly-inserted text.

      Same as insertWithTags(TextIter, String, int, TextTag, Object...), but allows you to pass in tag names instead of tag objects.

      Parameters:
      iter - position in this TextBuffer
      text - UTF-8 text
      len - length of text, or -1
      firstTagName - name of a tag to apply to text
      varargs - more tag names
    • moveMark

      public void moveMark(TextMark mark, TextIter where)

      Moves mark to the new location where.

      Emits the Gtk.TextBuffer::mark-set signal as notification of the move.

      Parameters:
      mark - a GtkTextMark
      where - new location for mark in this TextBuffer
    • moveMarkByName

      public void moveMarkByName(String name, TextIter where)

      Moves the mark named name (which must exist) to location where.

      See moveMark(TextMark, TextIter) for details.

      Parameters:
      name - name of a mark
      where - new location for mark
    • pasteClipboard

      public void pasteClipboard(Clipboard clipboard, @Nullable TextIter overrideLocation, boolean defaultEditable)

      Pastes the contents of a clipboard.

      If overrideLocation is null, the pasted text will be inserted at the cursor position, or the buffer selection will be replaced if the selection is non-empty.

      Note: pasting is asynchronous, that is, we’ll ask for the paste data and return, and at some point later after the main loop runs, the paste data will be inserted.

      Parameters:
      clipboard - the GdkClipboard to paste from
      overrideLocation - location to insert pasted text
      defaultEditable - whether the buffer is editable by default
    • placeCursor

      public void placeCursor(TextIter where)

      This function moves the “insert” and “selection_bound” marks simultaneously.

      If you move them to the same place in two steps with moveMark(TextMark, TextIter), you will temporarily select a region in between their old and new locations, which can be pretty inefficient since the temporarily-selected region will force stuff to be recalculated. This function moves them as a unit, which can be optimized.

      Parameters:
      where - where to put the cursor
    • redo

      public void redo()
      Redoes the next redoable action on the buffer, if there is one.
    • removeAllTags

      public void removeAllTags(TextIter start, TextIter end)

      Removes all tags in the range between start and end.

      Be careful with this function; it could remove tags added in code unrelated to the code you’re currently writing. That is, using this function is probably a bad idea if you have two or more unrelated code sections that add tags.

      Parameters:
      start - one bound of range to be untagged
      end - other bound of range to be untagged
    • removeCommitNotify

      public void removeCommitNotify(int commitNotifyHandler)

      Removes the GtkTextBufferCommitNotify handler previously registered with addCommitNotify(Set, TextBufferCommitNotify).

      This may result in the user_data_destroy being called that was passed when registering the commit notify functions.

      Parameters:
      commitNotifyHandler - the notify handler identifier returned from addCommitNotify(Set, TextBufferCommitNotify).
      Since:
      4.16
    • removeSelectionClipboard

      public void removeSelectionClipboard(Clipboard clipboard)
      Removes a GdkClipboard added with addSelectionClipboard(Clipboard)
      Parameters:
      clipboard - a GdkClipboard added to this TextBuffer by addSelectionClipboard(Clipboard)
    • removeTag

      public void removeTag(TextTag tag, TextIter start, TextIter end)

      Emits the “remove-tag” signal.

      The default handler for the signal removes all occurrences of tag from the given range. start and end don’t have to be in order.

      Parameters:
      tag - a GtkTextTag
      start - one bound of range to be untagged
      end - other bound of range to be untagged
    • removeTagByName

      public void removeTagByName(String name, TextIter start, TextIter end)

      Emits the “remove-tag” signal.

      Calls TextTagTable.lookup(String) on the buffer’s tag table to get a GtkTextTag, then calls removeTag(TextTag, TextIter, TextIter).

      Parameters:
      name - name of a GtkTextTag
      start - one bound of range to be untagged
      end - other bound of range to be untagged
    • selectRange

      public void selectRange(TextIter ins, TextIter bound)

      This function moves the “insert” and “selection_bound” marks simultaneously.

      If you move them in two steps with moveMark(TextMark, TextIter), you will temporarily select a region in between their old and new locations, which can be pretty inefficient since the temporarily-selected region will force stuff to be recalculated. This function moves them as a unit, which can be optimized.

      Parameters:
      ins - where to put the “insert” mark
      bound - where to put the “selection_bound” mark
    • setEnableUndo

      public void setEnableUndo(boolean enableUndo)

      Sets whether or not to enable undoable actions in the text buffer.

      Undoable actions in this context are changes to the text content of the buffer. Changes to tags and marks are not tracked.

      If enabled, the user will be able to undo the last number of actions up to getMaxUndoLevels().

      See beginIrreversibleAction() and endIrreversibleAction() to create changes to the buffer that cannot be undone.

      Parameters:
      enableUndo - true to enable undo
    • setMaxUndoLevels

      public void setMaxUndoLevels(int maxUndoLevels)

      Sets the maximum number of undo levels to perform.

      If 0, unlimited undo actions may be performed. Note that this may have a memory usage impact as it requires storing an additional copy of the inserted or removed text within the text buffer.

      Parameters:
      maxUndoLevels - the maximum number of undo actions to perform
    • setModified

      public void setModified(boolean setting)

      Used to keep track of whether the buffer has been modified since the last time it was saved.

      Whenever the buffer is saved to disk, call gtk_text_buffer_set_modified (@buffer, FALSE). When the buffer is modified, it will automatically toggle on the modified bit again. When the modified bit flips, the buffer emits the Gtk.TextBuffer::modified-changed signal.

      Parameters:
      setting - modification flag setting
    • setText

      public void setText(String text, int len)

      Deletes current contents of buffer, and inserts text instead. This is automatically marked as an irreversible action in the undo stack. If you wish to mark this action as part of a larger undo operation, call delete(TextIter, TextIter) and insert(TextIter, String, int) directly instead.

      If len is -1, text must be nul-terminated. text must be valid UTF-8.

      Parameters:
      text - UTF-8 text to insert
      len - length of text in bytes
    • undo

      public void undo()
      Undoes the last undoable action on the buffer, if there is one.
    • changed

      protected void changed()
      The class handler for the GtkTextBuffer::changed signal.
    • deleteRange

      protected void deleteRange(TextIter start, TextIter end)
      The class handler for the GtkTextBuffer::delete-range signal.
    • insertText

      protected void insertText(TextIter pos, String newText, int newTextLength)
      The class handler for the GtkTextBuffer::insert-text signal.
    • markDeleted

      protected void markDeleted(TextMark mark)
      The class handler for the GtkTextBuffer::mark-deleted signal.
    • markSet

      protected void markSet(TextIter location, TextMark mark)
      The class handler for the GtkTextBuffer::mark-set signal.
    • modifiedChanged

      protected void modifiedChanged()
      The class handler for the GtkTextBuffer::modified-changed signal.
    • pasteDone

      protected void pasteDone(Clipboard clipboard)
      The class handler for the GtkTextBuffer::paste-done signal.
    • onApplyTag

      Emitted to apply a tag to a range of text in a GtkTextBuffer.

      Applying actually occurs in the default handler.

      Note that if your handler runs before the default handler it must not invalidate the start and end iters (or has to revalidate them).

      See also: applyTag(TextTag, TextIter, TextIter), insertWithTags(TextIter, String, int, TextTag, Object...), insertRange(TextIter, TextIter, TextIter).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitApplyTag

      public void emitApplyTag(@Nullable TextTag tag, @Nullable TextIter start, @Nullable TextIter end)
      Emits the "apply-tag" signal. See onApplyTag(TextBuffer.ApplyTagCallback).
    • onBeginUserAction

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitBeginUserAction

      public void emitBeginUserAction()
      Emits the "begin-user-action" signal. See onBeginUserAction(TextBuffer.BeginUserActionCallback).
    • onChanged

      Emitted when the content of a GtkTextBuffer has changed.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged()
      Emits the "changed" signal. See onChanged(TextBuffer.ChangedCallback).
    • onDeleteRange

      Emitted to delete a range from a GtkTextBuffer.

      Note that if your handler runs before the default handler it must not invalidate the start and end iters (or has to revalidate them). The default signal handler revalidates the start and end iters to both point to the location where text was deleted. Handlers which run after the default handler (see g_signal_connect_after()) do not have access to the deleted text.

      See also: delete(TextIter, TextIter).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitDeleteRange

      public void emitDeleteRange(@Nullable TextIter start, @Nullable TextIter end)
      Emits the "delete-range" signal. See onDeleteRange(TextBuffer.DeleteRangeCallback).
    • onEndUserAction

    • emitEndUserAction

      public void emitEndUserAction()
      Emits the "end-user-action" signal. See onEndUserAction(TextBuffer.EndUserActionCallback).
    • onInsertChildAnchor

      Emitted to insert a GtkTextChildAnchor in a GtkTextBuffer.

      Insertion actually occurs in the default handler.

      Note that if your handler runs before the default handler it must not invalidate the location iter (or has to revalidate it). The default signal handler revalidates it to be placed after the inserted anchor.

      See also: insertChildAnchor(TextIter, TextChildAnchor).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitInsertChildAnchor

      public void emitInsertChildAnchor(@Nullable TextIter location, @Nullable TextChildAnchor anchor)
      Emits the "insert-child-anchor" signal. See onInsertChildAnchor(TextBuffer.InsertChildAnchorCallback).
    • onInsertPaintable

      Emitted to insert a GdkPaintable in a GtkTextBuffer.

      Insertion actually occurs in the default handler.

      Note that if your handler runs before the default handler it must not invalidate the location iter (or has to revalidate it). The default signal handler revalidates it to be placed after the inserted paintable.

      See also: insertPaintable(TextIter, Paintable).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitInsertPaintable

      public void emitInsertPaintable(@Nullable TextIter location, @Nullable Paintable paintable)
      Emits the "insert-paintable" signal. See onInsertPaintable(TextBuffer.InsertPaintableCallback).
    • onInsertText

      Emitted to insert text in a GtkTextBuffer.

      Insertion actually occurs in the default handler.

      Note that if your handler runs before the default handler it must not invalidate the location iter (or has to revalidate it). The default signal handler revalidates it to point to the end of the inserted text.

      See also: insert(TextIter, String, int), insertRange(TextIter, TextIter, TextIter).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitInsertText

      public void emitInsertText(@Nullable TextIter location, String text, int len)
      Emits the "insert-text" signal. See onInsertText(TextBuffer.InsertTextCallback).
    • onMarkDeleted

      Emitted as notification after a GtkTextMark is deleted.

      See also: deleteMark(TextMark).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitMarkDeleted

      public void emitMarkDeleted(@Nullable TextMark mark)
      Emits the "mark-deleted" signal. See onMarkDeleted(TextBuffer.MarkDeletedCallback).
    • onMarkSet

      Emitted as notification after a GtkTextMark is set.

      See also: createMark(String, TextIter, boolean), moveMark(TextMark, TextIter).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitMarkSet

      public void emitMarkSet(@Nullable TextIter location, @Nullable TextMark mark)
      Emits the "mark-set" signal. See onMarkSet(TextBuffer.MarkSetCallback).
    • onModifiedChanged

      Emitted when the modified bit of a GtkTextBuffer flips.

      See also: setModified(boolean).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitModifiedChanged

      public void emitModifiedChanged()
      Emits the "modified-changed" signal. See onModifiedChanged(TextBuffer.ModifiedChangedCallback).
    • onPasteDone

      Emitted after paste operation has been completed.

      This is useful to properly scroll the view to the end of the pasted text. See pasteClipboard(Clipboard, TextIter, boolean) for more details.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitPasteDone

      public void emitPasteDone(@Nullable Clipboard clipboard)
      Emits the "paste-done" signal. See onPasteDone(TextBuffer.PasteDoneCallback).
    • onRedo

      Emitted when a request has been made to redo the previously undone operation.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitRedo

      public void emitRedo()
      Emits the "redo" signal. See onRedo(TextBuffer.RedoCallback).
    • onRemoveTag

      Emitted to remove all occurrences of tag from a range of text in a GtkTextBuffer.

      Removal actually occurs in the default handler.

      Note that if your handler runs before the default handler it must not invalidate the start and end iters (or has to revalidate them).

      See also: removeTag(TextTag, TextIter, TextIter).

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitRemoveTag

      public void emitRemoveTag(@Nullable TextTag tag, @Nullable TextIter start, @Nullable TextIter end)
      Emits the "remove-tag" signal. See onRemoveTag(TextBuffer.RemoveTagCallback).
    • onUndo

      Emitted when a request has been made to undo the previous operation or set of operations that have been grouped together.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitUndo

      public void emitUndo()
      Emits the "undo" signal. See onUndo(TextBuffer.UndoCallback).
    • builder

      public static TextBuffer.Builder<? extends TextBuffer.Builder> builder()
      A TextBuffer.Builder object constructs a TextBuffer with the specified properties. Use the various set...() methods to set properties, and finish construction with TextBuffer.Builder.build().
      Returns:
      the builder object