![]() |
![]() |
![]() |
GtkSourceView 2 Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties | Signals |
GtkSourceBufferGtkSourceBuffer — Buffer object for GtkSourceView |
#include <gtksourceview/gtksourcebuffer.h> GtkSourceBuffer; GtkSourceBufferClass; GtkSourceBuffer * gtk_source_buffer_new (GtkTextTagTable *table
); GtkSourceBuffer * gtk_source_buffer_new_with_language (GtkSourceLanguage *language
); void gtk_source_buffer_set_highlight_syntax (GtkSourceBuffer *buffer
,gboolean highlight
); gboolean gtk_source_buffer_get_highlight_syntax (GtkSourceBuffer *buffer
); void gtk_source_buffer_set_language (GtkSourceBuffer *buffer
,GtkSourceLanguage *language
); GtkSourceLanguage * gtk_source_buffer_get_language (GtkSourceBuffer *buffer
); void gtk_source_buffer_set_highlight_matching_brackets (GtkSourceBuffer *buffer
,gboolean highlight
); gboolean gtk_source_buffer_get_highlight_matching_brackets (GtkSourceBuffer *buffer
); void gtk_source_buffer_set_style_scheme (GtkSourceBuffer *buffer
,GtkSourceStyleScheme *scheme
); GtkSourceStyleScheme * gtk_source_buffer_get_style_scheme (GtkSourceBuffer *buffer
); gint gtk_source_buffer_get_max_undo_levels (GtkSourceBuffer *buffer
); void gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer *buffer
,gint max_undo_levels
); void gtk_source_buffer_redo (GtkSourceBuffer *buffer
); void gtk_source_buffer_undo (GtkSourceBuffer *buffer
); gboolean gtk_source_buffer_can_redo (GtkSourceBuffer *buffer
); gboolean gtk_source_buffer_can_undo (GtkSourceBuffer *buffer
); void gtk_source_buffer_begin_not_undoable_action (GtkSourceBuffer *buffer
); void gtk_source_buffer_end_not_undoable_action (GtkSourceBuffer *buffer
); GtkSourceMark * gtk_source_buffer_create_source_mark (GtkSourceBuffer *buffer
,const gchar *name
,const gchar *category
,const GtkTextIter *where
); GSList * gtk_source_buffer_get_source_marks_at_line (GtkSourceBuffer *buffer
,gint line
,const gchar *category
); GSList * gtk_source_buffer_get_source_marks_at_iter (GtkSourceBuffer *buffer
,GtkTextIter *iter
,const gchar *category
); void gtk_source_buffer_remove_source_marks (GtkSourceBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
,const gchar *category
); gboolean gtk_source_buffer_forward_iter_to_source_mark (GtkSourceBuffer *buffer
,GtkTextIter *iter
,const gchar *category
); gboolean gtk_source_buffer_backward_iter_to_source_mark (GtkSourceBuffer *buffer
,GtkTextIter *iter
,const gchar *category
); void gtk_source_buffer_ensure_highlight (GtkSourceBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
);
"can-redo" gboolean : Read "can-undo" gboolean : Read "highlight-matching-brackets" gboolean : Read / Write "highlight-syntax" gboolean : Read / Write "language" GtkSourceLanguage* : Read / Write "max-undo-levels" gint : Read / Write "style-scheme" GtkSourceStyleScheme* : Read / Write "undo-manager" GtkSourceUndoManager* : Read / Write / Construct
"highlight-updated" : Run Last "redo" : Run Last "source-mark-updated" : Run Last "undo" : Run Last
The GtkSourceBuffer object is the model for GtkSourceView widgets. It extends the GtkTextBuffer object by adding features useful to display and edit source code as syntax highlighting and bracket matching. It also implements support for undo/redo operations.
To create a GtkSourceBuffer use gtk_source_buffer_new()
or
gtk_source_buffer_new_with_language()
. The second form is just a convenience
function which allows you to initially set a GtkSourceLanguage.
By default highlighting is enabled, but you can disable it with
gtk_source_buffer_set_highlight_syntax()
.
typedef struct { GtkTextBufferClass parent_class; /* Signals */ void (*undo) (GtkSourceBuffer *buffer); void (*redo) (GtkSourceBuffer *buffer); /* Padding for future expansion */ void (*_gtk_source_reserved1) (void); void (*_gtk_source_reserved2) (void); void (*_gtk_source_reserved3) (void); void (*_gtk_source_reserved4) (void); } GtkSourceBufferClass;
GtkSourceBuffer * gtk_source_buffer_new (GtkTextTagTable *table
);
Creates a new source buffer.
|
a GtkTextTagTable, or NULL to create a new one.
|
Returns : |
a new source buffer. |
GtkSourceBuffer * gtk_source_buffer_new_with_language (GtkSourceLanguage *language
);
Creates a new source buffer using the highlighting patterns in
language
. This is equivalent to creating a new source buffer with
a new tag table and then calling gtk_source_buffer_set_language()
.
|
a GtkSourceLanguage. |
Returns : |
a new source buffer which will highlight text
according to the highlighting patterns in language .
|
void gtk_source_buffer_set_highlight_syntax (GtkSourceBuffer *buffer
,gboolean highlight
);
Controls whether syntax is highlighted in the buffer. If highlight
is TRUE
, the text will be highlighted according to the syntax
patterns specified in the language set with
gtk_source_buffer_set_language()
. If highlight
is FALSE
, syntax highlighting
is disabled and all the GtkTextTag objects that have been added by the
syntax highlighting engine are removed from the buffer.
|
a GtkSourceBuffer. |
|
TRUE to enable syntax highlighting, FALSE to disable it.
|
gboolean gtk_source_buffer_get_highlight_syntax
(GtkSourceBuffer *buffer
);
Determines whether syntax highlighting is activated in the source buffer.
|
a GtkSourceBuffer. |
Returns : |
TRUE if syntax highlighting is enabled, FALSE otherwise.
|
void gtk_source_buffer_set_language (GtkSourceBuffer *buffer
,GtkSourceLanguage *language
);
Associate a GtkSourceLanguage with the source buffer. If language
is
not-NULL
and syntax highlighting is enabled (see gtk_source_buffer_set_highlight_syntax()
),
the syntax patterns defined in language
will be used to highlight the text
contained in the buffer. If language
is NULL
, the text contained in the
buffer is not highlighted.
The buffer holds a reference to language
.
|
a GtkSourceBuffer. |
|
a GtkSourceLanguage to set, or NULL .
|
GtkSourceLanguage * gtk_source_buffer_get_language (GtkSourceBuffer *buffer
);
Returns the GtkSourceLanguage associated with the buffer,
see gtk_source_buffer_set_language()
. The returned object should not be
unreferenced by the user.
|
a GtkSourceBuffer. |
Returns : |
GtkSourceLanguage associated with the buffer, or NULL .
|
void gtk_source_buffer_set_highlight_matching_brackets (GtkSourceBuffer *buffer
,gboolean highlight
);
Controls the bracket match highlighting function in the buffer. If
activated, when you position your cursor over a bracket character
(a parenthesis, a square bracket, etc.) the matching opening or
closing bracket character will be highlighted. You can specify the
style with the gtk_source_buffer_set_bracket_match_style()
function.
|
a GtkSourceBuffer. |
|
TRUE if you want matching brackets highlighted.
|
gboolean gtk_source_buffer_get_highlight_matching_brackets
(GtkSourceBuffer *buffer
);
Determines whether bracket match highlighting is activated for the source buffer.
|
a GtkSourceBuffer. |
Returns : |
TRUE if the source buffer will highlight matching
brackets.
|
void gtk_source_buffer_set_style_scheme (GtkSourceBuffer *buffer
,GtkSourceStyleScheme *scheme
);
Sets style scheme used by the buffer. If scheme
is NULL
no
style scheme is used.
|
a GtkSourceBuffer. |
|
style scheme. |
GtkSourceStyleScheme * gtk_source_buffer_get_style_scheme
(GtkSourceBuffer *buffer
);
Returns the GtkSourceStyleScheme currently used in buffer
.
|
a GtkSourceBuffer. |
Returns : |
the GtkSourceStyleScheme set by
gtk_source_buffer_set_style_scheme() , or NULL .
|
gint gtk_source_buffer_get_max_undo_levels
(GtkSourceBuffer *buffer
);
Determines the number of undo levels the buffer will track for buffer edits.
|
a GtkSourceBuffer. |
Returns : |
the maximum number of possible undo levels or -1 if no limit is set. |
void gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer *buffer
,gint max_undo_levels
);
Sets the number of undo levels for user actions the buffer will track. If the number of user actions exceeds the limit set by this function, older actions will be discarded.
If max_undo_levels
is -1, no limit is set.
A new action is started whenever the function
gtk_text_buffer_begin_user_action()
is called. In general, this
happens whenever the user presses any key which modifies the
buffer, but the undo manager will try to merge similar consecutive
actions, such as multiple character insertions into one action.
But, inserting a newline does start a new action.
|
a GtkSourceBuffer. |
|
the desired maximum number of undo levels. |
void gtk_source_buffer_redo (GtkSourceBuffer *buffer
);
Redoes the last undo operation. Use gtk_source_buffer_can_redo()
to check whether a call to this function will have any effect.
|
a GtkSourceBuffer. |
void gtk_source_buffer_undo (GtkSourceBuffer *buffer
);
Undoes the last user action which modified the buffer. Use
gtk_source_buffer_can_undo()
to check whether a call to this
function will have any effect.
Actions are defined as groups of operations between a call to
gtk_text_buffer_begin_user_action()
and
gtk_text_buffer_end_user_action()
, or sequences of similar edits
(inserts or deletes) on the same line.
|
a GtkSourceBuffer. |
gboolean gtk_source_buffer_can_redo (GtkSourceBuffer *buffer
);
Determines whether a source buffer can redo the last action (i.e. if the last operation was an undo).
|
a GtkSourceBuffer. |
Returns : |
TRUE if a redo is possible.
|
gboolean gtk_source_buffer_can_undo (GtkSourceBuffer *buffer
);
Determines whether a source buffer can undo the last action.
|
a GtkSourceBuffer. |
Returns : |
TRUE if it's possible to undo the last action.
|
void gtk_source_buffer_begin_not_undoable_action
(GtkSourceBuffer *buffer
);
Marks the beginning of a not undoable action on the buffer, disabling the undo manager. Typically you would call this function before initially setting the contents of the buffer (e.g. when loading a file in a text editor).
You may nest gtk_source_buffer_begin_not_undoable_action()
/
gtk_source_buffer_end_not_undoable_action()
blocks.
|
a GtkSourceBuffer. |
void gtk_source_buffer_end_not_undoable_action
(GtkSourceBuffer *buffer
);
Marks the end of a not undoable action on the buffer. When the last not undoable block is closed through the call to this function, the list of undo actions is cleared and the undo manager is re-enabled.
|
a GtkSourceBuffer. |
GtkSourceMark * gtk_source_buffer_create_source_mark (GtkSourceBuffer *buffer
,const gchar *name
,const gchar *category
,const GtkTextIter *where
);
Creates a source mark in the buffer
of category category
. A source mark is
a GtkTextMark but organised into categories. Depending on the category
a pixbuf can be specified that will be displayed along the line of the mark.
Like a GtkTextMark, a GtkSourceMark can be anonymous if the
passed name
is NULL
. Also, the buffer owns the marks so you
shouldn't unreference it.
Marks always have left gravity and are moved to the beginning of the line when the user deletes the line they were in.
Typical uses for a source mark are bookmarks, breakpoints, current executing instruction indication in a source file, etc..
|
a GtkSourceBuffer. |
|
the name of the mark, or NULL .
|
|
a string defining the mark category. |
|
location to place the mark. |
Returns : |
a new GtkSourceMark, owned by the buffer. |
Since 2.2
GSList * gtk_source_buffer_get_source_marks_at_line (GtkSourceBuffer *buffer
,gint line
,const gchar *category
);
Returns the list of marks of the given category at line
.
If category
is NULL, all marks at line
are returned.
|
a GtkSourceBuffer. |
|
a line number. |
|
category to search for or NULL
|
Returns : |
a newly allocated GSList. |
Since 2.2
GSList * gtk_source_buffer_get_source_marks_at_iter (GtkSourceBuffer *buffer
,GtkTextIter *iter
,const gchar *category
);
Returns the list of marks of the given category at iter
. If category
is NULL
it returns all marks at iter
.
|
a GtkSourceBuffer. |
|
an iterator. |
|
category to search for or NULL
|
Returns : |
a newly allocated GSList. |
Since 2.2
void gtk_source_buffer_remove_source_marks (GtkSourceBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
,const gchar *category
);
Remove all marks of category
between start
and end
from the buffer.
If category
is NULL, all marks in the range will be removed.
|
a GtkSourceBuffer. |
|
a GtkTextIter |
|
a GtkTextIter |
|
category to search for or NULL |
Since 2.2
gboolean gtk_source_buffer_forward_iter_to_source_mark (GtkSourceBuffer *buffer
,GtkTextIter *iter
,const gchar *category
);
Moves iter
to the position of the next GtkSourceMark of the given
category
. Returns TRUE if iter
was moved. If category
is NULL, the
next source mark can be of any category.
|
a GtkSourceBuffer. |
|
an iterator. |
|
category to search for or NULL
|
Returns : |
whether iter moved. |
Since 2.2
gboolean gtk_source_buffer_backward_iter_to_source_mark (GtkSourceBuffer *buffer
,GtkTextIter *iter
,const gchar *category
);
Moves iter
to the position of the previous GtkSourceMark of the given
category. Returns TRUE if iter
was moved. If category
is NULL, the
previous source mark can be of any category.
|
a GtkSourceBuffer. |
|
an iterator. |
|
category to search for or NULL
|
Returns : |
whether iter moved. |
Since 2.2
void gtk_source_buffer_ensure_highlight (GtkSourceBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
);
Forces buffer to analyze and highlight the given area synchronously.
This is a potentially slow operation and should be used only when you need to make sure that some text not currently visible is highlighted, for instance before printing.
|
a GtkSourceBuffer. |
|
start of the area to highlight. |
|
end of the area to highlight. |
"can-redo"
property"can-redo" gboolean : Read
Whether Redo operation is possible.
Default value: FALSE
"can-undo"
property"can-undo" gboolean : Read
Whether Undo operation is possible.
Default value: FALSE
"highlight-matching-brackets"
property"highlight-matching-brackets" gboolean : Read / Write
Whether to highlight matching brackets in the buffer.
Default value: TRUE
"highlight-syntax"
property"highlight-syntax" gboolean : Read / Write
Whether to highlight syntax in the buffer.
Default value: TRUE
"language"
property"language" GtkSourceLanguage* : Read / Write
Language object to get highlighting patterns from.
"max-undo-levels"
property"max-undo-levels" gint : Read / Write
Number of undo levels for the buffer. -1 means no limit. This property will only affect the default undo manager.
Allowed values: >= G_MAXULONG
Default value: 1000
"style-scheme"
property"style-scheme" GtkSourceStyleScheme* : Read / Write
Style scheme. It contains styles for syntax highlighting, optionally foreground, background, cursor color, current line color, and matching brackets style.
"undo-manager"
property"undo-manager" GtkSourceUndoManager* : Read / Write / Construct
The buffer undo manager.
"highlight-updated"
signalvoid user_function (GtkSourceBuffer *sourcebuffer, GtkTextIter *arg1, GtkTextIter *arg2, gpointer user_data) : Run Last
"source-mark-updated"
signalvoid user_function (GtkSourceBuffer *buffer, GtkTextMark *arg1, gpointer user_data) : Run Last
The ::source_mark_updated signal is emitted each time
a mark is added to, moved or removed from the buffer
.
|
the buffer that received the signal |
|
user data set when the signal handler was connected. |