Class: Gtk::TextBuffer
- Inherits:
-
Object
- Object
- Gtk::TextBuffer
- Extended by:
- GLib::Deprecatable
- Defined in:
- lib/gtk3/deprecated.rb,
lib/gtk3/text-buffer.rb
Overview
The class structure for GtkTextBuffer.
Instance Method Summary collapse
-
#add_mark(mark, where) ⇒ nil
Adds the mark at position where.
-
#add_mark_raw ⇒ nil
Adds the mark at position where.
-
#add_selection_clipboard(clipboard) ⇒ nil
Adds clipboard to the list of clipboards in which the selection contents of buffer are available.
-
#apply_tag(tag, start, last) ⇒ nil
Emits the “apply-tag” signal on buffer.
-
#apply_tag_by_name(name, start, end) ⇒ nil
Emits the “apply-tag” signal on buffer.
-
#apply_tag_raw ⇒ nil
Emits the “apply-tag” signal on buffer.
-
#backspace(iter, interactive, default_editable) ⇒ Boolean
Performs the appropriate action as if the user hit the delete key with the cursor at the position specified by iter.
-
#begin_irreversible_action ⇒ nil
Denotes the beginning of an action that may not be undone.
-
#begin_user_action ⇒ nil
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.
-
#can_redo ⇒ Boolean
Gets whether there is a redoable action in the history.
-
#can_redo=(can_redo) ⇒ Boolean
Denotes that the buffer can reapply the last undone action.
-
#can_redo? ⇒ Boolean
Denotes that the buffer can reapply the last undone action.
-
#can_undo ⇒ Boolean
Gets whether there is an undoable action in the history.
-
#can_undo=(can_undo) ⇒ Boolean
Denotes that the buffer can undo the last applied action.
-
#can_undo? ⇒ Boolean
Denotes that the buffer can undo the last applied action.
-
#char_count ⇒ Integer
Gets the number of characters in the buffer.
-
#copy_clipboard(clipboard) ⇒ nil
Copies the currently-selected text to a clipboard.
-
#create_child_anchor(iter) ⇒ Gtk::TextChildAnchor
Creates and inserts a child anchor.
-
#create_mark(name, where, options = {}) ⇒ Gtk::TextMark
Creates a mark at position where.
-
#create_mark_raw ⇒ Gtk::TextMark
Creates a mark at position where.
-
#create_tag(tag_name = nil, properties = {}) ⇒ Gtk::TextTag
Creates a tag and adds it to the tag table for buffer.
-
#cursor_position ⇒ Integer
The position of the insert mark.
-
#cursor_position=(cursor_position) ⇒ Integer
The position of the insert mark.
-
#cut_clipboard(clipboard, default_editable) ⇒ nil
Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.
-
#delete(start, end) ⇒ nil
Deletes text between start and end.
-
#delete_interactive(start_iter, end_iter, default_editable) ⇒ Boolean
Deletes all editable text in the given range.
-
#delete_mark(mark) ⇒ nil
Deletes mark, so that it’s no longer located anywhere in the buffer.
-
#delete_mark_by_name(name) ⇒ nil
Deletes the mark named name; the mark must exist.
-
#delete_mark_raw ⇒ nil
Deletes mark, so that it’s no longer located anywhere in the buffer.
-
#delete_selection(interactive, default_editable) ⇒ Boolean
Deletes the range between the “insert” and “selection_bound” marks, that is, the currently-selected text.
-
#enable_undo ⇒ Boolean
Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions.
-
#enable_undo=(enable_undo) ⇒ Boolean
Denotes if support for undoing and redoing changes to the buffer is allowed.
-
#enable_undo? ⇒ Boolean
Denotes if support for undoing and redoing changes to the buffer is allowed.
-
#end_irreversible_action ⇒ nil
Denotes the end of an action that may not be undone.
-
#end_user_action ⇒ nil
Ends a user-visible operation.
-
#get_bounds(start, end) ⇒ nil
Retrieves the first and last iterators in the buffer, i.e.
-
#get_end_iter(iter) ⇒ nil
Initializes iter with the “end iterator,” one past the last valid character in the text buffer.
- #get_iter_at(arguments) ⇒ Object
-
#get_iter_at_child_anchor(iter, anchor) ⇒ nil
(also: #get_iter_at_child_anchor_raw)
Obtains the location of anchor within buffer.
-
#get_iter_at_line(iter, line_number) ⇒ Boolean
(also: #get_iter_at_line_raw)
Initializes iter to the start of the given line.
-
#get_iter_at_line_index(iter, line_number, byte_index) ⇒ Boolean
(also: #get_iter_at_line_index_raw)
Obtains an iterator pointing to byte_index within the given line.
-
#get_iter_at_line_offset(iter, line_number, char_offset) ⇒ Boolean
(also: #get_iter_at_line_offset_raw)
Obtains an iterator pointing to char_offset within the given line.
-
#get_iter_at_mark(iter, mark) ⇒ nil
(also: #get_iter_at_mark_raw)
Initializes iter with the current position of mark.
-
#get_iter_at_offset(iter, char_offset) ⇒ nil
(also: #get_iter_at_offset_raw)
Initializes iter to a position char_offset chars from the start of the entire buffer.
-
#get_mark(name) ⇒ Gtk::TextMark
Returns the mark named name in buffer buffer, or nil if no such mark exists in the buffer.
-
#get_selection_bounds(start, end) ⇒ Boolean
Returns true if some text is selected; places the bounds of the selection in start and end.
-
#get_slice(start, end, include_hidden_chars) ⇒ String
Returns the text in the range [start,end).
-
#get_start_iter(iter) ⇒ nil
Initialized iter with the first position in the text buffer.
-
#get_text(start, end, include_hidden_chars) ⇒ String
Returns the text in the range [start,end).
-
#has_selection ⇒ Boolean
Indicates whether the buffer has some text currently selected.
-
#has_selection=(has_selection) ⇒ Boolean
Whether the buffer has some text currently selected.
-
#has_selection? ⇒ Boolean
Whether the buffer has some text currently selected.
-
#initialize(table) ⇒ Gtk::TextBuffer
constructor
Creates a new text buffer.
-
#insert(iter, target, *args) ⇒ nil
Inserts len bytes of text at position iter.
-
#insert_at_cursor(text, options = {}) ⇒ nil
Inserts text in buffer.
-
#insert_at_cursor_raw ⇒ nil
Inserts text in buffer.
-
#insert_child_anchor(iter, anchor) ⇒ nil
(also: #insert_child_anchor_raw)
Inserts a child widget anchor into the text buffer at iter.
-
#insert_markup(iter, markup, n_bytes = nil) ⇒ nil
Inserts the text in markup at position iter.
-
#insert_markup_raw ⇒ nil
Inserts the text in markup at position iter.
-
#insert_paintable(iter, paintable) ⇒ nil
Inserts an image into the text buffer at iter.
-
#insert_range(iter, start, end) ⇒ nil
Copies text, tags, and paintables between start and end and inserts the copy at iter.
-
#insert_range_interactive(iter, start, end, default_editable) ⇒ Boolean
Copies text, tags, and paintables between start and end and inserts the copy at iter.
-
#insert_raw ⇒ nil
Inserts len bytes of text at position iter.
-
#insert_with_tags(iter, text, len, first_tag, array) ⇒ nil
Inserts text into buffer at iter, applying the list of tags to the newly-inserted text.
-
#insert_with_tags_by_name(iter, text, len, first_tag_name, array) ⇒ nil
Inserts text into buffer at iter, applying the list of tags to the newly-inserted text.
-
#line_count ⇒ Integer
Obtains the number of lines in the buffer.
-
#max_undo_levels ⇒ Integer
Gets the maximum number of undo levels to perform.
-
#max_undo_levels=(max_undo_levels) ⇒ nil
Sets the maximum number of undo levels to perform.
-
#modified ⇒ Boolean
Indicates whether the buffer has been modified since the last call to [methodGtk.TextBuffer.set_modified] set the modification flag to false.
-
#modified=(setting) ⇒ nil
Used to keep track of whether the buffer has been modified since the last time it was saved.
-
#move_mark(mark, where) ⇒ nil
Moves mark to the new location where.
-
#move_mark_by_name(name, where) ⇒ nil
Moves the mark named name (which must exist) to location where.
-
#paste_clipboard(clipboard, override_location, default_editable) ⇒ nil
Pastes the contents of a clipboard.
-
#place_cursor(where) ⇒ nil
This function moves the “insert” and “selection_bound” marks simultaneously.
-
#redo ⇒ nil
Redoes the next redoable action on the buffer, if there is one.
-
#remove_all_tags(start, end) ⇒ nil
Removes all tags in the range between start and end.
-
#remove_selection_clipboard(clipboard) ⇒ nil
Removes a
GdkClipboardadded with [methodGtk.TextBuffer.add_selection_clipboard]. -
#remove_tag(tag, start, end) ⇒ nil
Emits the “remove-tag” signal.
-
#remove_tag_by_name(name, start, end) ⇒ nil
Emits the “remove-tag” signal.
-
#select_range(ins, bound) ⇒ nil
This function moves the “insert” and “selection_bound” marks simultaneously.
-
#selection_bound ⇒ Gtk::TextMark
Returns the mark that represents the selection bound.
- #selection_bounds ⇒ Object
- #selection_bounds_raw ⇒ Object
-
#selection_content ⇒ Gdk::ContentProvider
Get a content provider for this buffer.
- #serialize(*arguments) ⇒ Object
- #serialize_raw ⇒ Object
-
#set_text(text) ⇒ nil
(also: #text=)
Deletes current contents of buffer, and inserts text instead.
-
#set_text_raw ⇒ nil
Deletes current contents of buffer, and inserts text instead.
-
#tag_table ⇒ Gtk::TextTagTable
The GtkTextTagTable for the buffer.
-
#tag_table=(tag_table) ⇒ Gtk::TextTagTable
The GtkTextTagTable for the buffer.
-
#text ⇒ String
The text content of the buffer.
-
#undo ⇒ nil
Undoes the last undoable action on the buffer, if there is one.
Constructor Details
#initialize(table) ⇒ Gtk::TextBuffer
Creates a new text buffer.
Instance Method Details
#add_mark(mark, where) ⇒ nil
Adds the mark at position where.
The mark must not be added to another buffer, and if its name is not nil then there must not be another mark in the buffer with the same name.
Emits the [signalGtk.TextBuffer::mark-set] signal as notification of the mark's initial placement.
33 34 35 36 37 38 |
# File 'lib/gtk3/text-buffer.rb', line 33 def add_mark(mark, where) @marks ||= {} add_mark_raw(mark, where) mark_name = mark.name @marks[mark_name] = mark if mark_name end |
#add_mark_raw ⇒ nil
Adds the mark at position where.
The mark must not be added to another buffer, and if its name is not nil then there must not be another mark in the buffer with the same name.
Emits the [signalGtk.TextBuffer::mark-set] signal as notification of the mark's initial placement.
|
|
# File 'lib/gtk3/text-buffer.rb', line 32
|
#add_selection_clipboard(clipboard) ⇒ nil
Adds clipboard to the list of clipboards in which the selection contents of buffer are available.
In most cases, clipboard will be the GdkClipboard returned by
[methodGtk.Widget.get_primary_clipboard] for a view of buffer.
#apply_tag(tag, start, last) ⇒ nil
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.
200 201 202 203 204 205 206 |
# File 'lib/gtk3/text-buffer.rb', line 200 def apply_tag(tag, start, last) if tag.is_a?(String) apply_tag_by_name(tag, start, last) else apply_tag_raw(tag, start, last) end end |
#apply_tag_by_name(name, start, end) ⇒ nil
Emits the “apply-tag” signal on buffer.
Calls [methodGtk.TextTagTable.lookup] on the buffer’s
tag table to get a GtkTextTag, then calls
[methodGtk.TextBuffer.apply_tag].
#apply_tag_raw ⇒ nil
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.
|
|
# File 'lib/gtk3/text-buffer.rb', line 199
|
#backspace(iter, interactive, default_editable) ⇒ Boolean
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.
#begin_irreversible_action ⇒ nil
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 [methodGtk.TextBuffer.end_irreversible_action] 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.
#begin_user_action ⇒ nil
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 [methodGtk.TextBuffer.insert_interactive], 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.
#can_redo ⇒ Boolean
Gets whether there is a redoable action in the history.
#can_redo=(can_redo) ⇒ Boolean
Denotes that the buffer can reapply the last undone action.
#can_redo? ⇒ Boolean
Denotes that the buffer can reapply the last undone action.
#can_undo ⇒ Boolean
Gets whether there is an undoable action in the history.
#can_undo=(can_undo) ⇒ Boolean
Denotes that the buffer can undo the last applied action.
#can_undo? ⇒ Boolean
Denotes that the buffer can undo the last applied action.
#char_count ⇒ Integer
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.
#copy_clipboard(clipboard) ⇒ nil
Copies the currently-selected text to a clipboard.
#create_child_anchor(iter) ⇒ Gtk::TextChildAnchor
Creates and inserts a child anchor.
This is a convenience function which simply creates a child anchor with [ctorGtk.TextChildAnchor.new] and inserts it into the buffer with [methodGtk.TextBuffer.insert_child_anchor].
The new anchor is owned by the buffer; no reference count is returned to the caller of this function.
#create_mark(name, where, options = {}) ⇒ Gtk::TextMark
Creates a mark at position where.
If mark_name is nil, the mark is anonymous; otherwise, the mark can be retrieved by name using [methodGtk.TextBuffer.get_mark]. 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 (left_gravity = 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 [signalGtk.TextBuffer::mark-set] signal as notification of the mark's initial placement.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gtk3/text-buffer.rb', line 41 def create_mark(name, where, ={}) if == true or == false = {:left_gravity => } end left_gravity = [:left_gravity] left_gravity = true if left_gravity.nil? @marks ||= {} if name.nil? create_mark_raw(name, where, left_gravity) else @marks[name] = create_mark_raw(name, where, left_gravity) end end |
#create_mark_raw ⇒ Gtk::TextMark
Creates a mark at position where.
If mark_name is nil, the mark is anonymous; otherwise, the mark can be retrieved by name using [methodGtk.TextBuffer.get_mark]. 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 (left_gravity = 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 [signalGtk.TextBuffer::mark-set] signal as notification of the mark's initial placement.
|
|
# File 'lib/gtk3/text-buffer.rb', line 40
|
#create_tag(tag_name = nil, properties = {}) ⇒ Gtk::TextTag
Creates a tag and adds it to the tag table for buffer.
Equivalent to calling [ctorGtk.TextTag.new] 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 tag_name is nil, the tag is anonymous.
If tag_name is non-nil, a tag called tag_name must not already exist in the tag table for this buffer.
The first_property_name argument and subsequent arguments are a list of properties to set on the tag, as with g_object_set().
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gtk3/text-buffer.rb', line 19 def create_tag(tag_name=nil, properties={}) tag = TextTag.new(tag_name) succeeded = tag_table.add(tag) return nil unless succeeded properties.each do |name, value| property_name = name.to_s.gsub(/-/, "_") tag.__send__("#{property_name}=", value) end tag end |
#cursor_position ⇒ Integer
The position of the insert mark.
This is an offset from the beginning of the buffer. It is useful for getting notified when the cursor moves.
#cursor_position=(cursor_position) ⇒ Integer
The position of the insert mark.
This is an offset from the beginning of the buffer. It is useful for getting notified when the cursor moves.
#cut_clipboard(clipboard, default_editable) ⇒ nil
Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.
#delete(start, end) ⇒ nil
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.
#delete_interactive(start_iter, end_iter, default_editable) ⇒ Boolean
Deletes all editable text in the given range.
Calls [methodGtk.TextBuffer.delete] for each editable sub-range of [start,end). start and end are revalidated to point to the location of the last deleted range, or left untouched if no text was deleted.
#delete_mark(mark) ⇒ nil
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 [methodGtk.TextBuffer.add_mark]. Use [methodGtk.TextMark.get_deleted] to find out if a mark has been removed from its buffer.
The [signalGtk.TextBuffer::mark-deleted] signal will be emitted as notification after the mark is deleted.
56 57 58 59 60 61 |
# File 'lib/gtk3/text-buffer.rb', line 56 def delete_mark(mark) @marks ||= {} mark_name = mark.name delete_mark_raw(mark) @marks.delete(mark_name) if mark_name end |
#delete_mark_by_name(name) ⇒ nil
Deletes the mark named name; the mark must exist.
See [methodGtk.TextBuffer.delete_mark] for details.
#delete_mark_raw ⇒ nil
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 [methodGtk.TextBuffer.add_mark]. Use [methodGtk.TextMark.get_deleted] to find out if a mark has been removed from its buffer.
The [signalGtk.TextBuffer::mark-deleted] signal will be emitted as notification after the mark is deleted.
|
|
# File 'lib/gtk3/text-buffer.rb', line 55
|
#delete_selection(interactive, default_editable) ⇒ Boolean
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).
#enable_undo ⇒ Boolean
Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions.
See [methodGtk.TextBuffer.begin_irreversible_action] and [methodGtk.TextBuffer.end_irreversible_action] to create changes to the buffer that cannot be undone.
#enable_undo=(enable_undo) ⇒ Boolean
Denotes if support for undoing and redoing changes to the buffer is allowed.
#enable_undo? ⇒ Boolean
Denotes if support for undoing and redoing changes to the buffer is allowed.
#end_irreversible_action ⇒ nil
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 [methodGtk.TextBuffer.begin_irreversible_action] was called.
You may nest calls to gtk_text_buffer_begin_irreversible_action() and gtk_text_buffer_end_irreversible_action() pairs.
#end_user_action ⇒ nil
Ends a user-visible operation.
Should be paired with a call to [methodGtk.TextBuffer.begin_user_action]. See that function for a full explanation.
#get_bounds(start, end) ⇒ nil
Retrieves the first and last iterators in the buffer, i.e. the entire buffer lies within the range [start,end).
#get_end_iter(iter) ⇒ nil
Initializes iter with the “end iterator,” one past the last valid character in the text buffer.
If dereferenced with [methodGtk.TextIter.get_char], the end iterator has a character value of 0. The entire buffer lies in the range from the first position in the buffer (call [methodGtk.TextBuffer.get_start_iter] to get character position 0) to the end iterator.
#get_iter_at(arguments) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gtk3/text-buffer.rb', line 70 def get_iter_at(arguments) line = arguments[:line] offset = arguments[:offset] index = arguments[:index] mark = arguments[:mark] anchor = arguments[:anchor] if line if offset get_iter_at_line_offset_raw(line, offset) elsif index get_iter_at_line_index_raw(line, index) else get_iter_at_line_raw(line) end elsif offset get_iter_at_offset_raw(offset) elsif mark get_iter_at_mark_raw(mark) elsif anchor get_iter_at_child_anchor_raw(anchor) else = "Must specify one of :line, :offset, :mark or :anchor: #{arguments.inspect}" raise ArgumentError, end end |
#get_iter_at_child_anchor(iter, anchor) ⇒ nil Also known as: get_iter_at_child_anchor_raw
Obtains the location of anchor within buffer.
#get_iter_at_line(iter, line_number) ⇒ Boolean Also known as: get_iter_at_line_raw
Initializes iter to the start of the given line.
If line_number is greater than or equal to the number of lines in the buffer, the end iterator is returned.
#get_iter_at_line_index(iter, line_number, byte_index) ⇒ Boolean Also known as: get_iter_at_line_index_raw
Obtains an iterator pointing to byte_index within the given line.
byte_index must be the start of a UTF-8 character. Note bytes, not characters; UTF-8 may encode one character as multiple bytes.
If line_number is greater than or equal to the number of lines in the buffer, the end iterator is returned. And if byte_index is off the end of the line, the iterator at the end of the line is returned.
#get_iter_at_line_offset(iter, line_number, char_offset) ⇒ Boolean Also known as: get_iter_at_line_offset_raw
Obtains an iterator pointing to char_offset within the given line.
Note characters, not bytes; UTF-8 may encode one character as multiple bytes.
If line_number is greater than or equal to the number of lines in the buffer, the end iterator is returned. And if char_offset is off the end of the line, the iterator at the end of the line is returned.
#get_iter_at_mark(iter, mark) ⇒ nil Also known as: get_iter_at_mark_raw
Initializes iter with the current position of mark.
#get_iter_at_offset(iter, char_offset) ⇒ nil Also known as: get_iter_at_offset_raw
Initializes iter to a position char_offset chars from the start of the entire buffer.
If char_offset 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.
#get_mark(name) ⇒ Gtk::TextMark
Returns the mark named name in buffer buffer, or nil if no such mark exists in the buffer.
#get_selection_bounds(start, end) ⇒ Boolean
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 nil, then they are not filled in, but the return value still indicates whether text is selected.
#get_slice(start, end, include_hidden_chars) ⇒ String
Returns the text in the range [start,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 [methodGtk.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.
#get_start_iter(iter) ⇒ nil
Initialized iter with the first position in the text buffer.
This is the same as using [methodGtk.TextBuffer.get_iter_at_offset] to get the iter at character offset 0.
#get_text(start, end, include_hidden_chars) ⇒ String
Returns the text in the range [start,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 [methodGtk.TextBuffer.get_slice].
#has_selection ⇒ Boolean
Indicates whether the buffer has some text currently selected.
#has_selection=(has_selection) ⇒ Boolean
Whether the buffer has some text currently selected.
#has_selection? ⇒ Boolean
Whether the buffer has some text currently selected.
#insert(iter, target, *args) ⇒ nil
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.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/gtk3/text-buffer.rb', line 100 def insert(iter, target, *args) = nil = nil case args.size when 0 = {} when 1 case args.first when Hash = args.first else = args end else = args end if .nil? signature_prefix = "#{self.class}\##{__method__}(iter, target" warn("#{signature_prefix}, *tags) style has been deprecated. " + "Use #{signature_prefix}, options={:tags => tags}) style instead.") = {:tags => } end interactive = [:interactive] default_editable = [:default_editable] = [:tags] start_offset = iter.offset if interactive default_editable = true if default_editable.nil? insert_interactive(iter, target, default_editable) else case target when GdkPixbuf::Pixbuf insert_pixbuf_raw(iter, target) when TextChildAnchor insert_text_child_anchor_raw(iter, target) when GLib::Bytes insert_raw(iter, target, target.size) else insert_raw(iter, target, target.bytesize) end end if start_iter = get_iter_at(:offset => start_offset) .each do |tag| if tag.is_a?(String) resolved_tag = tag_table.lookup(tag) if resolved_tag.nil? raise ArgumentError "unknown tag: #{tag.inspect}" end tag = resolved_tag end apply_tag(tag, start_iter, iter) end end self end |
#insert_at_cursor(text, options = {}) ⇒ nil
Inserts text in buffer.
Simply calls [methodGtk.TextBuffer.insert], using the current cursor position as the insertion point.
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/gtk3/text-buffer.rb', line 175 def insert_at_cursor(text, ={}) interactive = [:interactive] default_editable = [:default_editable] if interactive default_editable = true if default_editable.nil? insert_interactive_at_cursor(text, default_editable) else insert_at_cursor_raw(text, text.bytesize) end end |
#insert_at_cursor_raw ⇒ nil
Inserts text in buffer.
Simply calls [methodGtk.TextBuffer.insert], using the current cursor position as the insertion point.
|
|
# File 'lib/gtk3/text-buffer.rb', line 174
|
#insert_child_anchor(iter, anchor) ⇒ nil Also known as: insert_child_anchor_raw
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 [methodGtk.TextBuffer.get_slice] and [methodGtk.TextBuffer.get_text].
Consider [methodGtk.TextBuffer.create_child_anchor] as a more convenient alternative to this function. The buffer will add a reference to the anchor, so you can unref it after insertion.
#insert_markup(iter, markup, n_bytes = nil) ⇒ nil
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 [signalGtk.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.
163 164 165 166 167 168 169 170 171 |
# File 'lib/gtk3/text-buffer.rb', line 163 def insert_markup(iter, markup, n_bytes=nil) case markup when GLib::Bytes n_bytes ||= markup.size else n_bytes ||= markup.bytesize end insert_markup_raw(iter, markup, n_bytes) end |
#insert_markup_raw ⇒ nil
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 [signalGtk.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.
|
|
# File 'lib/gtk3/text-buffer.rb', line 162
|
#insert_paintable(iter, paintable) ⇒ nil
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 [methodGtk.TextBuffer.get_slice] and [methodGtk.TextBuffer.get_text].
#insert_range(iter, start, end) ⇒ nil
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.
#insert_range_interactive(iter, start, end, default_editable) ⇒ Boolean
Copies text, tags, and paintables between start and end and inserts the copy at iter.
Same as [methodGtk.TextBuffer.insert_range], but does nothing if the insertion point isn’t editable. The default_editable parameter indicates whether the text is editable at iter if no tags enclosing iter affect editability. Typically the result of [methodGtk.TextView.get_editable] is appropriate here.
#insert_raw ⇒ nil
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.
|
|
# File 'lib/gtk3/text-buffer.rb', line 97
|
#insert_with_tags(iter, text, len, first_tag, array) ⇒ nil
Inserts text into buffer at iter, applying the list of tags to the newly-inserted text.
The last tag specified must be nil to terminate the list. Equivalent to calling [methodGtk.TextBuffer.insert], then [methodGtk.TextBuffer.apply_tag] on the inserted text; this is just a convenience function.
#insert_with_tags_by_name(iter, text, len, first_tag_name, array) ⇒ nil
Inserts text into buffer at iter, applying the list of tags to the newly-inserted text.
Same as [methodGtk.TextBuffer.insert_with_tags], but allows you to pass in tag names instead of tag objects.
#line_count ⇒ Integer
Obtains the number of lines in the buffer.
This value is cached, so the function is very fast.
#max_undo_levels ⇒ Integer
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.
#max_undo_levels=(max_undo_levels) ⇒ nil
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.
#modified ⇒ Boolean
Indicates whether the buffer has been modified since the last call to [methodGtk.TextBuffer.set_modified] set the modification flag to false.
Used for example to enable a “save” function in a text editor.
#modified=(setting) ⇒ nil
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 (<b>buffer</b>, FALSE).
When the buffer is modified, it will automatically
toggle on the modified bit again. When the modified
bit flips, the buffer emits the
[signalGtk.TextBuffer::modified-changed] signal.
#move_mark(mark, where) ⇒ nil
Moves mark to the new location where.
Emits the [signalGtk.TextBuffer::mark-set] signal as notification of the move.
#move_mark_by_name(name, where) ⇒ nil
Moves the mark named name (which must exist) to location where.
See [methodGtk.TextBuffer.move_mark] for details.
#paste_clipboard(clipboard, override_location, default_editable) ⇒ nil
Pastes the contents of a clipboard.
If override_location is nil, 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.
#place_cursor(where) ⇒ nil
This function moves the “insert” and “selection_bound” marks simultaneously.
If you move them to the same place in two steps with [methodGtk.TextBuffer.move_mark], 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.
#redo ⇒ nil
Redoes the next redoable action on the buffer, if there is one.
#remove_all_tags(start, end) ⇒ nil
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.
#remove_selection_clipboard(clipboard) ⇒ nil
Removes a GdkClipboard added with
[methodGtk.TextBuffer.add_selection_clipboard]
#remove_tag(tag, start, end) ⇒ nil
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.
#remove_tag_by_name(name, start, end) ⇒ nil
Emits the “remove-tag” signal.
Calls [methodGtk.TextTagTable.lookup] on the buffer’s
tag table to get a GtkTextTag, then calls
[methodGtk.TextBuffer.remove_tag].
#select_range(ins, bound) ⇒ nil
This function moves the “insert” and “selection_bound” marks simultaneously.
If you move them in two steps with [methodGtk.TextBuffer.move_mark], 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.
#selection_bound ⇒ Gtk::TextMark
Returns the mark that represents the selection bound.
Equivalent to calling [methodGtk.TextBuffer.get_mark] to get the mark named “selection_bound”, but very slightly more efficient, and involves less typing.
The currently-selected text in buffer 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. [methodGtk.TextBuffer.get_selection_bounds] is another convenient function for handling the selection, if you just want to know whether there’s a selection and what its bounds are.
#selection_bounds ⇒ Object
214 215 216 217 218 219 220 221 |
# File 'lib/gtk3/text-buffer.rb', line 214 def selection_bounds selected, start_iter, end_iter = selection_bounds_raw if selected [start_iter, end_iter] else nil end end |
#selection_bounds_raw ⇒ Object
213 |
# File 'lib/gtk3/text-buffer.rb', line 213 alias_method :selection_bounds_raw, :selection_bounds |
#selection_content ⇒ Gdk::ContentProvider
Get a content provider for this buffer.
It can be used to make the content of buffer available
in a GdkClipboard, see [methodGdk.Clipboard.set_content].
#serialize(*arguments) ⇒ Object
209 210 211 |
# File 'lib/gtk3/text-buffer.rb', line 209 def serialize(*arguments) serialize_raw(*arguments).pack("C*") end |
#serialize_raw ⇒ Object
208 |
# File 'lib/gtk3/text-buffer.rb', line 208 alias_method :serialize_raw, :serialize |
#set_text(text) ⇒ nil Also known as: text=
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 [methodTextBuffer.delete] and [methodTextBuffer.insert] directly instead.
If len is -1, text must be nul-terminated. text must be valid UTF-8.
188 189 190 191 192 193 194 195 |
# File 'lib/gtk3/text-buffer.rb', line 188 def set_text(text) if text.is_a?(GLib::Bytes) text, text_size = text.to_s, text.size else text_size = text.bytesize end set_text_raw(text, text_size) end |
#set_text_raw ⇒ nil
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 [methodTextBuffer.delete] and [methodTextBuffer.insert] directly instead.
If len is -1, text must be nul-terminated. text must be valid UTF-8.
|
|
# File 'lib/gtk3/text-buffer.rb', line 187
|
#tag_table ⇒ Gtk::TextTagTable
The GtkTextTagTable for the buffer.
#tag_table=(tag_table) ⇒ Gtk::TextTagTable
The GtkTextTagTable for the buffer.
#text ⇒ String
The text content of the buffer.
Without child widgets and images, see [methodGtk.TextBuffer.get_text] for more information.
#undo ⇒ nil
Undoes the last undoable action on the buffer, if there is one.