[gimp] app: use the tags left of the cursor when inserting



commit 11479d3abdde1180cfa0fe7c45a073ab5c11a89e
Author: Michael Natterer <mitch gimp org>
Date:   Fri Feb 26 03:04:11 2010 +0100

    app: use the tags left of the cursor when inserting
    
    and make sure the style editor's buttons are correct at the beginning
    and end of spans (take the tags toggled on/off at these positions into
    account).

 app/widgets/gimptextbuffer.c      |   25 ++++++++++++++++++++++++-
 app/widgets/gimptextstyleeditor.c |   14 +++++++++++---
 2 files changed, 35 insertions(+), 4 deletions(-)
---
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index 5d42ab0..ba2a9e0 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -279,9 +279,32 @@ void
 gimp_text_buffer_insert (GimpTextBuffer *buffer,
                          const gchar    *text)
 {
+  GtkTextIter  iter, start;
+  gint         start_offset;
+  GSList      *tags_off;
+  GSList      *list;
+
   g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
 
-  gtk_text_buffer_insert_at_cursor (GTK_TEXT_BUFFER (buffer), text, -1);
+  gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &iter,
+                                    gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer)));
+
+  start_offset = gtk_text_iter_get_offset (&iter);
+
+  tags_off = gtk_text_iter_get_toggled_tags (&iter, FALSE);
+
+  gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, text, -1);
+
+  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &start,
+                                      start_offset);
+
+  for (list = tags_off; list; list = g_slist_next (list))
+    {
+      gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), list->data,
+                                 &start, &iter);
+    }
+
+  g_slist_free (tags_off);
 }
 
 gint
diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c
index 36b3419..c270736 100644
--- a/app/widgets/gimptextstyleeditor.c
+++ b/app/widgets/gimptextstyleeditor.c
@@ -321,6 +321,8 @@ typedef struct
 {
   GimpTextStyleEditor *editor;
   GSList              *tags;
+  GSList              *tags_on;
+  GSList              *tags_off;
   GtkTextIter          iter;
   gboolean             any_active;
 } UpdateTogglesData;
@@ -358,7 +360,9 @@ gimp_text_style_editor_update_cursor (GtkTextTag        *tag,
                                    data->editor);
 
   gtk_toggle_button_set_active (toggle,
-                                g_slist_find (data->tags, tag) != NULL);
+                                (g_slist_find (data->tags, tag) &&
+                                 ! g_slist_find (data->tags_on, tag)) ||
+                                g_slist_find (data->tags_off, tag));
 
   g_signal_handlers_unblock_by_func (toggle,
                                      gimp_text_style_editor_tag_toggled,
@@ -411,13 +415,17 @@ gimp_text_style_editor_mark_set (GtkTextBuffer       *buffer,
       gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
                                         gtk_text_buffer_get_insert (buffer));
 
-      data.editor = editor;
-      data.tags   = gtk_text_iter_get_tags (&cursor);
+      data.editor   = editor;
+      data.tags     = gtk_text_iter_get_tags (&cursor);
+      data.tags_on  = gtk_text_iter_get_toggled_tags (&cursor, TRUE);
+      data.tags_off = gtk_text_iter_get_toggled_tags (&cursor, FALSE);
 
       g_hash_table_foreach (editor->tag_to_toggle_hash,
                             (GHFunc) gimp_text_style_editor_update_cursor,
                             &data);
 
       g_slist_free (data.tags);
+      g_slist_free (data.tags_on);
+      g_slist_free (data.tags_off);
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]