gtk-sharpGtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.GLib.ObjectThis class stores formatted text for display in a .
The relationship between and objects is not necessarily one-to-one. All views must contain a buffer, but a buffer does not have to be assigned a view, and one buffer may be used by multiple views.In the following example, a single object is shared between two widgets.using Gtk;
public class TextBufferExample
{
public static void Main ()
{
// Initialize GTK.
Application.Init ();
// Create a containing window.
Window window = new Window ("TextBuffer Example");
window.DeleteEvent += OnDelete;
window.SetDefaultSize (400, 300);
// Create a buffer and vertical panes for the views.
TextBuffer buffer = new TextBuffer (new TextTagTable ());
VPaned paned = new VPaned ();
// Create a text view for the buffer, make it scrollable, and
// add it to the first pane.
TextView view1 = new TextView (buffer);
ScrolledWindow scrolled_window1 = new ScrolledWindow ();
scrolled_window1.Add (view1);
paned.Add1 (scrolled_window1);
// Create a second text view for the buffer, make it scrollable,
// and add it to the second pane.
TextView view2 = new TextView (buffer);
ScrolledWindow scrolled_window2 = new ScrolledWindow ();
scrolled_window2.Add (view2);
paned.Add2 (scrolled_window2);
// Add the panes to the window and show it.
window.Add (paned);
window.ShowAll ();
// Run the application.
Application.Run ();
}
// Quit when the window is closed.
static void OnDelete (object o, DeleteEventArgs e)
{
Application.Quit ();
}
}Constructor
a tag table, or to create a new one
Creates a new text buffer.Constructor
Pointer to the C object.
Internal constructorThis is an internal constructor, and should not be used by user code.MethodSystem.Void
To be added.
To be added.
To be added.To be added.MethodSystem.Void
an object of type Adds to the list of clipboards in which the selection contents of buffer are available.In most cases, clipboard will be the of type for a view of buffer.MethodSystem.Void
a
the beginning of the range to be tagged
the end of the range to be tagged
Fires the events on buffer.
The default handler for the signal applies tag to the
given range. and do not have to be in order.
MethodSystem.Void
the name of the tag
the location of the beginning of the range
the location of the end of the range
Fires the event on buffer. The default handler
for the signal applies tag to the given range.
The order for and is not important.
MethodSystem.Boolean
a
a
a To be addeda To be addedMethodSystem.VoidCalled to indicate that the buffer operations between here and a call to are part of a single user-visible operation.The operations between and can then be grouped when creating an undo stack. maintains a count of calls to that have not been closed with a call to , and emits and 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 , automatically call begin/end user action around the buffer operations they perform, so there is no need to add extra calls if you user action consists solely of a single call to one of those functions.
EventGLib.Signal("changed")System.EventHandlerEmitted when the text in the buffer has been changed.PropertySystem.Int32The number of characters in the bufferThe number of characters in the bufferThe result of this method is cached, so it is very fast.EventGLib.Signal("insert-child-anchor")Gtk.ChildAnchorInsertedHandlerEmitted when a ChildAnchor has been inserted in the buffer.MethodSystem.VoidClears the contents of the bufferMethodSystem.Void
The to copy the text to.
Copies the buffer's selected text to the given .Copying a 's selected text: void Copy (Gtk.TextView view) {
Gtk.TextBuffer buffer = view.Buffer;
Gtk.Clipboard board = Clipboard.Get (Gdk.Selection.Clipboard);
buffer.CopyClipboard (board);
} PropertyGLib.Property("copy-target-list")Gtk.TargetListObtains the copy TargetList.a .MethodGtk.TextChildAnchor
the location in the buffer
This is a convenience function which simply creates a child
anchor with and inserts it into
the buffer with .
the created child anchor
This is a convenience function which simply creates a child
anchor with and inserts it into
the buffer with . The new anchor is owned by the buffer; no reference
count is returned to the caller of .
MethodGtk.TextMark
name for mark, or .
To be added.
whether the mark has left gravity
Creates a mark at position .a new object
Creates a mark at position . If is ,
the mark is anonymous; otherwise, the mark can be
retrieved by name using . If a
mark has left gravity, and text is inserted at the
current location of the mark, the mark will be moved to the left of
the newly-inserted text. If the mark has right gravity
(ie. = ), 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 are typing).
Fires the event as
notification of the initial placement of the mark.
PropertyGLib.Property("cursor-position")System.Int32Position of the insert mark.a representing the offset to the cursor from the beginning of the buffer.MethodSystem.Void
an object of type
an object of type Copies the currently-selected text to a clipboard, then deletes said text if it is editable.MethodSystem.Obsolete("Replaced by 'ref TextIter, ref TextIter' overload")System.Void
To be added.
To be added.
Delete text between two iterators.This overload is obsolete, replaced by ref TextIter overloads since the iters passed in are updated by the caller.MethodSystem.Void
a position in the buffer
a position in the buffer
Deletes text between and .
Deletes text between and . The order of the two is not actually
relevant, as they will be reordered. This function
actually fires off the event, 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,
and will be re-initialized to point to the location
where text was deleted.
MethodSystem.Boolean
the beginning of range to delete
the end of the range to delete
whether the buffer is editable by default
Deletes all editable text in the given range.whether some text was actually deleted
Deletes all editable text in the given range. Calls for each editable sub-range of
and . and
are revalidated to point to the
location of the last deleted range, or left untouched if
no text was deleted.
MethodSystem.Void
a in the buffer to be deleted.
Deletes mark, so that it is no longer located anywhere in the buffer.
Deletes mark, so that it is no longer located anywhere in
the buffer. There is no way to undelete a
mark. will return
after
this function has been called on a mark;
indicates that a mark no
longer belongs to a buffer. The event will
be raised as notification after the mark is deleted.
MethodSystem.Void
the name of a mark in buffer
Deletes the mark named ; the mark must exist.
See for more details.
EventGLib.Signal("delete-range")Gtk.DeleteRangeHandlerEmitted when a range of text has been deleted from the buffer.MethodSystem.Boolean
whether the deletion is caused by user interaction
whether the buffer is editable by default
Deletes the currently-selected text
whether there was a non-empty selection to delete
Deletes the range between the "insert" and
"selection_bound" marks, that is, the currently-selected
text. If is , the editability of the selection will
be considered (users can't delete uneditable text).
MethodSystem.Boolean
buffer to deserialize content.
MIME type format.
insertion point.
serialized data.
length of serialized data.
Deserialize content.a .PropertyGdk.Atom[]The supported MIME type formats for deserialization.an array of MIME type Atoms.MethodSystem.Boolean
a MIME type Atom.
Determines if tag creation is supported for a MIME type deserializer.if , tag creation is supported.MethodSystem.Void
a MIME type Atom.
a .
Enables or disables arbitrary tag creation.In most cases, you don't want to do this, as it will put arbitrary tags in the buffer.PropertyGtk.TextIterThe end of the bufferThe location of the end of the bufferMethodSystem.VoidShould be paired with a call to .See for an explanation.MethodSystem.Void
A object to store the location
of the beginning of the buffer.
A object to store the location
of the end of the buffer.
Retrieves the first and last iterators in the buffer, i.e. the entire buffer.
MethodGtk.TextIter
A at the current buffer.
Gets the location of the specific anchor.The location at .MethodGtk.TextIter
The specified line number.
Gets the location of a particular line.The location at the beginning fo the line as specified by .MethodGtk.TextIter
A line number for the current buffer, counting from 0.
The byte index from start of line.
Obtains an iterator pointing to within the given line.The location as specified by and . must be the start of a
UTF-8 character, and must not be beyond the end of the
line. Note bytes, not characters; UTF-8 may encode one
character as multiple bytes.
MethodGtk.TextIter
a
a Gets the location of a specific point.The location at the location specified by and .MethodGtk.TextIter
The specified mark.
Gets the location of the specified mark.The location of .MethodGtk.TextIter
The requested character offset
Returns the location at a particular character offsetThe location at MethodGtk.TextMark
the name of a mark
Returns the mark named name in buffer buffer, or if no such mark exists in the buffer.
Returns the mark named name in buffer buffer, or if no such mark exists in the buffer.
MethodSystem.Boolean
the location of the beginning of the selection
the location of the end of the selection
Returns if some text is selectedReturns if the selection has nonzero length
Returns if some text is selected;
and sets the bounds of the selection in and (if
the selection has length 0, then start and end are filled
in with the same value). and will be in
ascending order. If and are , then they are
not filled in, but the return value still indicates
whether text is selected.
MethodSystem.String
the start of a range
the end of the range
whether to include invisible text
Returns the text from to .
a string containing the text from
to
Returns the text in the range from to . Excludes undisplayed text
(text marked with tags that set the invisibility
attribute) if is
. 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 . Note that 0xFFFC can occur in normal text as well, so
it is not a reliable indicator that a pixbuf or widget is
in the buffer.
MethodSystem.String
the beginning of the specified range
the end of the specified range
whether to include invisible text
Returns the text from a specified rangea string containing the text from the specified range
Returns the text in the range specified by and . Excludes
undisplayed text (text marked with tags that set the
invisibility attribute) if is . 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 this with .
PropertyGLib.GTypeGType Property.a Returns the native value for .PropertyGLib.Property("has-selection")System.BooleanIndicates presence of a selection.if , there is text selected currently.MethodSystem.Obsolete("Replaced by 'ref TextIter iter' overload")System.Void
To be added.
To be added.
Inserts text.The overload is obsolete, replace by the ref TextIter overload.MethodSystem.Void
The location for to be
inserted
The text to be inserted
Insert text at a specific pointMethodSystem.Void
The text to be inserted
Insert text into the current cursor position
The event is
raised when a call to this method is made.
MethodSystem.Void
location to insert the anchor
a .
Inserts a child widget anchor into the text buffer.
Inserts a child widget anchor into the text buffer at . 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 pixbufs, but the
"text" variants do not. e.g. see and ). Consider as a
more convenient alternative to this function. The buffer
will add a reference to the anchor, so you can unref it
after insertion.
MethodSystem.Boolean
a location in the buffer
the text to be inserted
the default editability of buffer
Insert text if the cursor is at an editable point in
the buffer
whether text was actually inserted
Similar to , but the insertion will not occur if 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).
indicates the editability of text that
does not have a tag affecting editability applied to
it. Typically the result of
is appropriate here.
MethodSystem.Boolean
The text to be inserted
The default editability of the buffer
Insert text at cursor position if the location is editableWhether or not was inserted
See for more details.
PropertyGtk.TextMarkReturns the mark that represents the cursor (insertion point).The mark of the insert point.
This is equivelant to calling for the
mark named "insert".
MethodSystem.Void
The location to insert the image
The image to be inserted
Inserts an image into the text buffer at .
Inserts an image into the text buffer at . 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 pixbufs, but the "text" variants do not. e.g. see
and .
MethodSystem.Obsolete("Replaced by 'ref TextIter iter' overload")System.Void
To be added.
To be added.
To be added.
Inserts a range of text.This overload is obsolete, replaced by ref TextIter overloads since the iters passed in are updated by the caller.MethodSystem.Void
a position in buffer
a position in the source
a position in the source
Copies text, tags, and pixbufs between
and and inserts the copy at .
Copies text, tags, and pixbufs between and (the
order does not matter) and inserts the
copy at . Used instead of simply getting/inserting
text because it preserves images and tags. If and
are in a different buffer from buffer, the two buffers
must share the same tag table.
This method is implemented with the and events.
MethodSystem.Boolean
a position in buffer
a position in the source
a position in the source
whether the text is editable at if no tags enclosing
iter affect editability
Same as , but does nothing if the insertion point is not editable.
if an insertion was possible at
Same as , but does nothing if the insertion point is not
editable.
The parameter
indicates whether the text is editable at if no tags
enclosing iter affect editability. Typically the result of
is appropriate here.
EventGLib.Signal("insert-text")Gtk.InsertTextHandlerEmitted when text is inserted into the buffer.MethodSystem.Obsolete("Replaced by 'ref TextIter iter' overload")System.VoidSystem.ParamArray
To be added.
To be added.
To be added.
Inserts text with tag information.The overload is obsolete, replace by the ref TextIter overload.MethodSystem.VoidSystem.ParamArray
location to insert the text
text to insert
tags to apply to Inserts into buffer at , applying the list of to the newly-inserted text.Equivalent to calling , then on the inserted text; It is just a convenience function.MethodSystem.VoidSystem.ParamArray
location to insert the text
text to insert
names of the tags to apply to Inserts into buffer at , applying the list of tags with names to the newly-inserted text.Equivalent to calling , then on the inserted text; It is just a convenience function.PropertySystem.Int32Obtains the number of lines in the buffer.The number of lines in the buffer
The results of this method is cached, so this is very fast.
EventGLib.Signal("mark-deleted")Gtk.MarkDeletedHandlerEmitted when a mark has been deleted from the buffer.EventGLib.Signal("mark-set")Gtk.MarkSetHandlerEmitted when a mark is set in the buffer.PropertySystem.BooleanWhether or not the buffer has been modified if the buffer has
been modified, otherwise.
Whenever the buffer is saved to disk, set this property to
. When the buffer is modified, it
will automatically toggled to .
Whenever this property is changed, the event is raised.
EventGLib.Signal("modified-changed")System.EventHandlerEmitted when the Modified status of the buffer is changed.MethodSystem.Void
a .
To be added.
Moves mark to the new location .
Moves mark to the new location where. Fires the event as notification of the move.
MethodSystem.Void
the name of the mark
To be added.
Moves the mark named (which must
exist) to location .
It is possible to use built-in marks to implement a "Select All" method on a buffer (e.g. ).
private void SelectAll (TextBuffer buffer)
{
buffer.MoveMark ("insert", buffer.StartIter);
buffer.MoveMark ("selection_bound", buffer.EndIter);
}
See for more details.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideChanged", Type=typeof(Gtk.TextBuffer))System.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideChildAnchorInserted", Type=typeof(Gtk.TextBuffer))System.Void
To be added.
a Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideDeleteRange", Type=typeof(Gtk.TextBuffer))System.Void
a
a Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideInsertText", Type=typeof(Gtk.TextBuffer))System.Void
a
To be added.
Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideMarkDeleted", Type=typeof(Gtk.TextBuffer))System.Void
a Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideMarkSet", Type=typeof(Gtk.TextBuffer))System.Void
a
a Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideModifiedChanged", Type=typeof(Gtk.TextBuffer))System.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverridePasteDone", Type=typeof(Gtk.TextBuffer))System.Void
To be added.
Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverridePixbufInserted", Type=typeof(Gtk.TextBuffer))System.Void
To be added.
a Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideTagApplied", Type=typeof(Gtk.TextBuffer))System.Void
a
To be added.
To be added.
Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideTagRemoved", Type=typeof(Gtk.TextBuffer))System.Void
a
To be added.
To be added.
Default handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideUserActionBegun", Type=typeof(Gtk.TextBuffer))System.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodGLib.DefaultSignalHandler(ConnectionMethod="OverrideUserActionEnded", Type=typeof(Gtk.TextBuffer))System.VoidDefault handler for the event.Override this method in a subclass to provide a default handler for the event.MethodSystem.Void
a Pastes the contents of a clipboard at the insertion point.MethodSystem.Void
the to paste from
the location to insert pasted text, or for at the cursor
whether the buffer is editable by default
Pastes the contents of a clipboard at the insertion point,
or at .
Pastes the contents of a clipboard at the insertion point,
or at . (Note: pasting
is asynchronous, that is, we will ask for the paste data and
return, and at some point later after the main loop runs,
the paste data will be inserted.)
EventGLib.Signal("paste-done")Gtk.PasteDoneHandlerTo be added.To be added.PropertyGLib.Property("paste-target-list")Gtk.TargetListObtains the paste TargetList.a .EventGLib.Signal("insert-pixbuf")Gtk.PixbufInsertedHandlerEmitted when a Pixbuf is inserted into the buffer.MethodSystem.Void
where to put the cursor
Moves the "insert" and "selection_bound" marks simultaneously.
This function moves the "insert" and "selection_bound"
marks simultaneously. If you move them to the same place
in two steps with ,
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.
MethodGdk.Atom
a MIME type target.
Serialization formatter for the specified .
Registers a deserialization handler for a given MIME type.an atom representing the MIME type.MethodGdk.Atom
name of tagset, or .
Registers TextBuffer's internal serialization format.The newly registered format's mime type.MethodGdk.Atom
A MIME type target.
Serialization formatter for the specified .
Registers a serialization formatter for a given MIME type.MethodGdk.Atom
name of tagset, or .
Registers TextBuffer's internal serialization format.The newly registered format's mime type.MethodSystem.Void
The beginning of the range
The end of the range
Removes all tags in the range between and .
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 are currently writing. That
is, calling this method is probably a bad idea if you have
two or more unrelated code sections that add tags.
MethodSystem.Void
an object of type Removes a added with .MethodSystem.Void
the to remove
the beginning of the range
the end of the range
Fires the events
and removes all occurrences of from
the given range
Fires the
event. The default handler for the signal removes all
occurrences of tag from the given range. and .
MethodSystem.Void
the name of the tag
the beginning of the buffer to be untagged
the end of the buffer to be untagged
Calls on the buffer's tag table to get a , then calls
PropertyGtk.TextMarkReturns the mark that represents the selection bound.a
Returns the mark that represents the selection
bound. Equivalent to calling 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. is another convenient function for handling the
selection, if you just want to know whether there is a
selection and what its bounds are.
MethodSystem.Void
a
a This function moves the and
marks simultaneously.
If you move them in two steps
with , 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.
MethodSystem.Byte[]
buffer containing text to serialize.
MIME type format.
beginning of desired text.
end of desired text.
Serializes a range of text.the serialized data stream.PropertyGdk.Atom[]The supported MIME type formats for Serialization.an array of MIME type Atoms.MethodSystem.Obsolete("Use the TextBuffer.Text property's setter")System.Void
The new contents of the buffer
Set the contents of the buffer
This is equivelant to using the setter of the
property.
PropertyGtk.TextIterThe location of the beginning of the bufferThe location of the beginning of the buffer
This is the equivelant to calling to get the iter at character offset 0.
EventGLib.Signal("apply-tag")Gtk.TagAppliedHandlerEmitted when a tag is applied to the buffer.EventGLib.Signal("remove-tag")Gtk.TagRemovedHandlerEmitted when a tag is removed from the buffer.PropertyGLib.Property("tag-table")Gtk.TextTagTableThe tag table of the current bufferThe current of the bufferPropertyGLib.Property("text")System.StringThe complete contents of the bufferThe contents of the current bufferMethodSystem.Void
format Atom for a MIME type.
Removes a registered MIME type handler from the buffer.MethodSystem.Void
format to unregister.
Removes a Serialization format from the registry.EventGLib.Signal("begin-user-action")System.EventHandlerEmitted when a UserAction is begun on the buffer.EventGLib.Signal("end-user-action")System.EventHandlerEmitted when a UserAction ends on the buffer.