[gimp] app: don't remove all tags when toggling style buttons and then inserting



commit b19db0dea951433777f9093c90a16453a8d369b6
Author: Michael Natterer <mitch gimp org>
Date:   Mon Mar 1 22:39:42 2010 +0100

    app: don't remove all tags when toggling style buttons and then inserting
    
    Instead, keep a list of tags to explicitely remove around (the list of
    unchecked toggles), and remove only these tags, so the tags that have
    no widget in the UI are not affected by the insert_tags logic.

 app/widgets/gimptextbuffer.c      |   63 +++++++++++++++++++++++++-----------
 app/widgets/gimptextbuffer.h      |    6 ++-
 app/widgets/gimptextstyleeditor.c |   24 ++++++++++---
 app/widgets/gimptextstyleeditor.h |    9 +++--
 4 files changed, 71 insertions(+), 31 deletions(-)
---
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index 374f7d2..4bf1a15 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -674,13 +674,17 @@ gimp_text_buffer_name_to_tag (GimpTextBuffer *buffer,
 
 void
 gimp_text_buffer_set_insert_tags (GimpTextBuffer *buffer,
-                                  GList          *style)
+                                  GList          *insert_tags,
+                                  GList          *remove_tags)
 {
   g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
 
-  g_list_free (buffer->insert_tags);
-  buffer->insert_tags = style;
   buffer->insert_tags_set = TRUE;
+
+  g_list_free (buffer->insert_tags);
+  g_list_free (buffer->remove_tags);
+  buffer->insert_tags = insert_tags;
+  buffer->remove_tags = remove_tags;
 }
 
 void
@@ -688,9 +692,12 @@ gimp_text_buffer_clear_insert_tags (GimpTextBuffer *buffer)
 {
   g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
 
+  buffer->insert_tags_set = FALSE;
+
   g_list_free (buffer->insert_tags);
+  g_list_free (buffer->remove_tags);
   buffer->insert_tags = NULL;
-  buffer->insert_tags_set = FALSE;
+  buffer->remove_tags = NULL;
 }
 
 void
@@ -699,8 +706,9 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
 {
   GtkTextIter  iter, start;
   gint         start_offset;
-  GList       *insert_tags;
   gboolean     insert_tags_set;
+  GList       *insert_tags;
+  GList       *remove_tags;
   GSList      *tags_off = NULL;
 
   g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
@@ -710,13 +718,15 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
 
   start_offset = gtk_text_iter_get_offset (&iter);
 
-  insert_tags     = buffer->insert_tags;
   insert_tags_set = buffer->insert_tags_set;
-  buffer->insert_tags     = NULL;
+  insert_tags     = buffer->insert_tags;
+  remove_tags     = buffer->remove_tags;
+
   buffer->insert_tags_set = FALSE;
+  buffer->insert_tags     = NULL;
+  buffer->remove_tags     = NULL;
 
-  if (! insert_tags_set)
-    tags_off = gtk_text_iter_get_toggled_tags (&iter, FALSE);
+  tags_off = gtk_text_iter_get_toggled_tags (&iter, FALSE);
 
   gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
 
@@ -729,30 +739,45 @@ gimp_text_buffer_insert (GimpTextBuffer *buffer,
     {
       GList *list;
 
-      gtk_text_buffer_remove_all_tags (GTK_TEXT_BUFFER (buffer),
-                                       &start, &iter);
+      for (list = remove_tags; list; list = g_list_next (list))
+        {
+          GtkTextTag *tag = list->data;
+
+          gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (buffer), tag,
+                                      &start, &iter);
+        }
 
       for (list = insert_tags; list; list = g_list_next (list))
         {
-          gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), list->data,
+          GtkTextTag *tag = list->data;
+
+          gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
                                      &start, &iter);
         }
-
-      g_list_free (insert_tags);
     }
-  else
+
+  if (tags_off)
     {
-      GSList *list;
+      GSList *slist;
 
-      for (list = tags_off; list; list = g_slist_next (list))
+      for (slist = tags_off; slist; slist = g_slist_next (slist))
         {
-          gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), list->data,
-                                     &start, &iter);
+          GtkTextTag *tag = slist->data;
+
+          if (! g_list_find (remove_tags, tag) &&
+              ! g_list_find (buffer->spacing_tags, tag))
+            {
+              gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
+                                         &start, &iter);
+            }
         }
 
       g_slist_free (tags_off);
     }
 
+  g_list_free (remove_tags);
+  g_list_free (insert_tags);
+
   gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
 }
 
diff --git a/app/widgets/gimptextbuffer.h b/app/widgets/gimptextbuffer.h
index 02055b4..ab695ff 100644
--- a/app/widgets/gimptextbuffer.h
+++ b/app/widgets/gimptextbuffer.h
@@ -43,8 +43,9 @@ struct _GimpTextBuffer
   GList         *baseline_tags;
   GList         *spacing_tags;
 
-  GList         *insert_tags;
   gboolean       insert_tags_set;
+  GList         *insert_tags;
+  GList         *remove_tags;
 
   GdkAtom        markup_atom;
 };
@@ -86,7 +87,8 @@ GtkTextTag     * gimp_text_buffer_name_to_tag       (GimpTextBuffer    *buffer,
                                                      const gchar       *value);
 
 void             gimp_text_buffer_set_insert_tags   (GimpTextBuffer    *buffer,
-                                                     GList             *style);
+                                                     GList             *insert_tags,
+                                                     GList             *remove_tags);
 void             gimp_text_buffer_clear_insert_tags (GimpTextBuffer    *buffer);
 void             gimp_text_buffer_insert            (GimpTextBuffer    *buffer,
                                                      const gchar       *text);
diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c
index 388de54..5c9a116 100644
--- a/app/widgets/gimptextstyleeditor.c
+++ b/app/widgets/gimptextstyleeditor.c
@@ -278,22 +278,33 @@ gimp_text_style_editor_new (GimpTextBuffer *buffer,
 }
 
 GList *
-gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor)
+gimp_text_style_editor_list_tags (GimpTextStyleEditor  *editor,
+                                  GList               **remove_tags)
 {
   GList *toggles;
   GList *tags = NULL;
 
   g_return_val_if_fail (GIMP_IS_TEXT_STYLE_EDITOR (editor), NULL);
+  g_return_val_if_fail (remove_tags != NULL, NULL);
+
+  *remove_tags = NULL;
 
   for (toggles = editor->toggles; toggles; toggles = g_list_next (toggles))
     {
+      GtkTextTag *tag = g_object_get_data (toggles->data, "tag");
+
       if (gtk_toggle_button_get_active (toggles->data))
         {
-          tags = g_list_prepend (tags,
-                                 g_object_get_data (toggles->data, "tag"));
+          tags = g_list_prepend (tags, tag);
+        }
+      else
+        {
+          *remove_tags = g_list_prepend (*remove_tags, tag);
         }
     }
 
+  *remove_tags = g_list_reverse (*remove_tags);
+
   return g_list_reverse (tags);
 }
 
@@ -353,7 +364,8 @@ gimp_text_style_editor_tag_toggled (GtkToggleButton     *toggle,
 {
   GtkTextBuffer *buffer = GTK_TEXT_BUFFER (editor->buffer);
   GtkTextTag    *tag    = g_object_get_data (G_OBJECT (toggle), "tag");
-  GList         *list;
+  GList         *insert_tags;
+  GList         *remove_tags;
 
   if (gtk_text_buffer_get_has_selection (buffer))
     {
@@ -375,8 +387,8 @@ gimp_text_style_editor_tag_toggled (GtkToggleButton     *toggle,
       gtk_text_buffer_end_user_action (buffer);
     }
 
-  list = gimp_text_style_editor_list_tags (editor);
-  gimp_text_buffer_set_insert_tags (editor->buffer, list);
+  insert_tags = gimp_text_style_editor_list_tags (editor, &remove_tags);
+  gimp_text_buffer_set_insert_tags (editor->buffer, insert_tags, remove_tags);
 }
 
 static void
diff --git a/app/widgets/gimptextstyleeditor.h b/app/widgets/gimptextstyleeditor.h
index 2890e6d..caacf1e 100644
--- a/app/widgets/gimptextstyleeditor.h
+++ b/app/widgets/gimptextstyleeditor.h
@@ -60,11 +60,12 @@ struct _GimpTextStyleEditorClass
 
 GType       gimp_text_style_editor_get_type  (void) G_GNUC_CONST;
 
-GtkWidget * gimp_text_style_editor_new       (GimpTextBuffer      *buffer,
-                                              gdouble              resolution_x,
-                                              gdouble              resolution_y);
+GtkWidget * gimp_text_style_editor_new       (GimpTextBuffer       *buffer,
+                                              gdouble               resolution_x,
+                                              gdouble               resolution_y);
 
-GList     * gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor);
+GList     * gimp_text_style_editor_list_tags (GimpTextStyleEditor  *editor,
+                                              GList               **remove_tags);
 
 
 #endif /*  __GIMP_TEXT_STYLE_EDITOR_H__  */



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