84 |
|
|
85 |
Buffer = gtk_text_view_get_buffer(Text); |
Buffer = gtk_text_view_get_buffer(Text); |
86 |
gtk_text_buffer_get_selection_bounds (Buffer, NULL, &end); |
gtk_text_buffer_get_selection_bounds (Buffer, NULL, &end); |
87 |
|
|
88 |
return gtk_text_iter_get_offset (&end); |
return gtk_text_iter_get_offset (&end); |
89 |
} |
} |
90 |
|
|
105 |
|
|
106 |
|
|
107 |
/* Returns the contents of the buffer; must be g_free'd */ |
/* Returns the contents of the buffer; must be g_free'd */ |
|
|
|
108 |
gchar *get_text (GtkTextBuffer *Buffer) |
gchar *get_text (GtkTextBuffer *Buffer) |
109 |
{ |
{ |
110 |
GtkTextIter start, end; |
GtkTextIter start, end; |
117 |
return str; |
return str; |
118 |
} |
} |
119 |
|
|
120 |
/* Replaces the currently selected text with new text */ |
/* Returns the contents of the buffer, from beginning to cursor; |
121 |
|
must be g_free'd */ |
122 |
|
gchar *get_text_to_cursor (GtkTextBuffer *Buffer) |
123 |
|
{ |
124 |
|
GtkTextIter start, end; |
125 |
|
GtkTextMark *mark; |
126 |
|
gchar *str; |
127 |
|
|
128 |
|
mark = gtk_text_buffer_get_mark (Buffer, "insert"); |
129 |
|
gtk_text_buffer_get_start_iter (Buffer, &start); |
130 |
|
gtk_text_buffer_get_iter_at_mark (Buffer, &end, mark); |
131 |
|
str = gtk_text_buffer_get_slice(Buffer, |
132 |
|
&start, &end, FALSE); |
133 |
|
|
134 |
|
return str; |
135 |
|
} |
136 |
|
|
137 |
|
/* Returns the contents of the buffer, from cursor to end; must be g_free'd */ |
138 |
|
gchar *get_text_from_cursor (GtkTextBuffer *Buffer) |
139 |
|
{ |
140 |
|
GtkTextIter start, end; |
141 |
|
GtkTextMark *mark; |
142 |
|
gchar *str; |
143 |
|
|
144 |
|
mark = gtk_text_buffer_get_mark (Buffer, "insert"); |
145 |
|
gtk_text_buffer_get_iter_at_mark (Buffer, &start, mark); |
146 |
|
gtk_text_buffer_get_end_iter (Buffer, &end); |
147 |
|
str = gtk_text_buffer_get_text (Buffer, |
148 |
|
&start, &end, FALSE); |
149 |
|
|
150 |
|
return str; |
151 |
|
} |
152 |
|
|
153 |
|
/* Returns the line, 0-base, that the cursor is on */ |
154 |
|
gint get_line_of_cursor (GtkTextBuffer *Buffer) |
155 |
|
{ |
156 |
|
GtkTextIter iter; |
157 |
|
GtkTextMark *mark; |
158 |
|
|
159 |
|
mark = gtk_text_buffer_get_mark (Buffer, "insert"); |
160 |
|
gtk_text_buffer_get_iter_at_mark (Buffer, &iter, mark); |
161 |
|
|
162 |
|
return gtk_text_iter_get_line (&iter); |
163 |
|
} |
164 |
|
|
165 |
|
/* Replaces the currently selected text with new text */ |
166 |
void replace_selection (GtkTextBuffer *Buffer, const gchar *str) |
void replace_selection (GtkTextBuffer *Buffer, const gchar *str) |
167 |
{ |
{ |
168 |
GtkTextIter start, end; |
GtkTextIter start, end; |
177 |
|
|
178 |
/* Replaces the indicated text with new text; reinitializes start and end to |
/* Replaces the indicated text with new text; reinitializes start and end to |
179 |
point to beginning and end of inserted text*/ |
point to beginning and end of inserted text*/ |
|
|
|
180 |
void replace_text (GtkTextBuffer *Buffer, GtkTextIter *start, GtkTextIter *end, const gchar *text) |
void replace_text (GtkTextBuffer *Buffer, GtkTextIter *start, GtkTextIter *end, const gchar *text) |
181 |
{ |
{ |
182 |
GtkTextMark *mark; |
GtkTextMark *mark; |