[gimp] app: use a temporary GtkTextBuffer for (de)seriaizing markup
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: use a temporary GtkTextBuffer for (de)seriaizing markup
- Date: Sun, 28 Feb 2010 18:05:01 +0000 (UTC)
commit f135ebb97fd32a50bf021412da0da98a2c6d3d16
Author: Michael Natterer <mitch gimp org>
Date: Sun Feb 28 19:01:45 2010 +0100
app: use a temporary GtkTextBuffer for (de)seriaizing markup
The copy doesn't do anything yet, but this will enable us to do
transformations on the buffer contents before turning them into
markup, and the other way around.
app/widgets/gimptextbuffer.c | 53 ++++++++++++++++++++++++++++++++---------
1 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index 4e3b096..402587f 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -220,21 +220,36 @@ gimp_text_buffer_set_markup (GimpTextBuffer *buffer,
if (markup)
{
- GtkTextIter start;
- GError *error = NULL;
+ GtkTextBuffer *content;
+ GtkTextIter insert;
+ GError *error = NULL;
- gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &start);
+ content = gtk_text_buffer_new (gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer)));
+
+ gtk_text_buffer_get_start_iter (content, &insert);
if (! gtk_text_buffer_deserialize (GTK_TEXT_BUFFER (buffer),
- GTK_TEXT_BUFFER (buffer),
+ content,
buffer->markup_atom,
- &start,
+ &insert,
(const guint8 *) markup, -1,
&error))
{
g_printerr ("EEK: %s\n", error->message);
g_clear_error (&error);
}
+ else
+ {
+ GtkTextIter start, end;
+
+ gtk_text_buffer_get_bounds (content, &start, &end);
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &insert);
+
+ gtk_text_buffer_insert_range (GTK_TEXT_BUFFER (buffer),
+ &insert, &start, &end);
+ }
+
+ g_object_unref (content);
}
gimp_text_buffer_clear_insert_tags (buffer);
@@ -243,18 +258,32 @@ gimp_text_buffer_set_markup (GimpTextBuffer *buffer,
gchar *
gimp_text_buffer_get_markup (GimpTextBuffer *buffer)
{
- GtkTextIter start, end;
- gsize length;
+ GtkTextBuffer *content;
+ GtkTextIter insert;
+ GtkTextIter start, end;
+ gchar *markup;
+ gsize length;
g_return_val_if_fail (GIMP_IS_TEXT_BUFFER (buffer), NULL);
+ content = gtk_text_buffer_new (gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer)));
+
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
+ gtk_text_buffer_get_start_iter (content, &insert);
+
+ gtk_text_buffer_insert_range (content, &insert, &start, &end);
+
+ gtk_text_buffer_get_bounds (content, &start, &end);
+
+ markup = (gchar *) gtk_text_buffer_serialize (GTK_TEXT_BUFFER (buffer),
+ content,
+ buffer->markup_atom,
+ &start, &end,
+ &length);
+
+ g_object_unref (content);
- return (gchar *) gtk_text_buffer_serialize (GTK_TEXT_BUFFER (buffer),
- GTK_TEXT_BUFFER (buffer),
- buffer->markup_atom,
- &start, &end,
- &length);
+ return markup;
}
static gint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]