[gimp/gimp-2-10] app: fix undoing image parasite attach/detach to emit the right signals



commit 8d05d018209a3ca2a6cd8c2b9cb6894edba6114e
Author: Michael Natterer <mitch gimp org>
Date:   Thu May 30 16:44:23 2019 +0200

    app: fix undoing image parasite attach/detach to emit the right signals
    
    Add "gboolean push_undo" parameters to gimp_image_parasite_attach()
    and _detach() and use the API also from undo, instead of implementing
    attaching/removing manually and forgetting about the signals.
    
    Fixes updating of the image properties color profile page.
    
    (cherry picked from commit 710cfc1f478a2d9b75b622ee1445972feeb19c9a)

 app/actions/image-commands.c         |  2 +-
 app/core/gimp.c                      |  2 +-
 app/core/gimpimage-color-profile.c   |  6 +++---
 app/core/gimpimage-new.c             |  2 +-
 app/core/gimpimage.c                 | 27 +++++++++++++++------------
 app/core/gimpimage.h                 |  6 ++++--
 app/core/gimpimageundo.c             | 12 ++----------
 app/core/gimpitem.c                  |  2 +-
 app/file-data/file-data-gbr.c        |  2 +-
 app/file-data/file-data-gih.c        |  6 +++---
 app/file-data/file-data-pat.c        |  2 +-
 app/pdb/image-cmds.c                 |  4 ++--
 app/pdb/plug-in-compat-cmds.c        |  4 ++--
 app/widgets/gimpimagecommenteditor.c |  4 ++--
 app/xcf/xcf-load.c                   |  2 +-
 pdb/groups/image.pdb                 |  4 ++--
 pdb/groups/plug_in_compat.pdb        |  4 ++--
 17 files changed, 44 insertions(+), 47 deletions(-)
---
diff --git a/app/actions/image-commands.c b/app/actions/image-commands.c
index fde02a1d03..130495df6f 100644
--- a/app/actions/image-commands.c
+++ b/app/actions/image-commands.c
@@ -1269,7 +1269,7 @@ image_profile_assign_callback (GtkWidget                *dialog,
   gimp_image_set_is_color_managed (image, TRUE, TRUE);
 
   /*  omg...  */
-  gimp_image_parasite_detach (image, "icc-profile-name");
+  gimp_image_parasite_detach (image, "icc-profile-name", TRUE);
 
   gimp_image_undo_group_end (image);
 
diff --git a/app/core/gimp.c b/app/core/gimp.c
index e597ef5d34..6192f6fea5 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -981,7 +981,7 @@ gimp_create_image (Gimp              *gimp,
                                                       GIMP_PARASITE_PERSISTENT,
                                                       strlen (comment) + 1,
                                                       comment);
-          gimp_image_parasite_attach (image, parasite);
+          gimp_image_parasite_attach (image, parasite, FALSE);
           gimp_parasite_free (parasite);
         }
     }
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index b004cadbaf..ab8750cbe4 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -159,11 +159,11 @@ gimp_image_set_icc_parasite (GimpImage          *image,
       g_return_if_fail (gimp_image_validate_icc_parasite (image, icc_parasite,
                                                           NULL, NULL) == TRUE);
 
-      gimp_image_parasite_attach (image, icc_parasite);
+      gimp_image_parasite_attach (image, icc_parasite, TRUE);
     }
   else
     {
-      gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME);
+      gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME, TRUE);
     }
 }
 
@@ -421,7 +421,7 @@ gimp_image_convert_color_profile (GimpImage                *image,
   gimp_image_set_is_color_managed (image, TRUE, TRUE);
   gimp_image_set_color_profile (image, dest_profile, NULL);
   /*  omg...  */
-  gimp_image_parasite_detach (image, "icc-profile-name");
+  gimp_image_parasite_detach (image, "icc-profile-name", TRUE);
 
   gimp_image_undo_group_end (image);
 
diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c
index 02c0fa22cc..4d0fa7baa0 100644
--- a/app/core/gimpimage-new.c
+++ b/app/core/gimpimage-new.c
@@ -120,7 +120,7 @@ gimp_image_new_from_template (Gimp         *gimp,
                                     GIMP_PARASITE_PERSISTENT,
                                     strlen (comment) + 1,
                                     comment);
-      gimp_image_parasite_attach (image, parasite);
+      gimp_image_parasite_attach (image, parasite, FALSE);
       gimp_parasite_free (parasite);
     }
 
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 8fea956c55..ff97279096 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -3594,7 +3594,8 @@ gimp_image_parasite_validate (GimpImage           *image,
 
 void
 gimp_image_parasite_attach (GimpImage          *image,
-                            const GimpParasite *parasite)
+                            const GimpParasite *parasite,
+                            gboolean            push_undo)
 {
   GimpImagePrivate *private;
   GimpParasite      copy;
@@ -3622,7 +3623,8 @@ gimp_image_parasite_attach (GimpImage          *image,
       if (gimp_color_profile_is_equal (profile, builtin))
         {
           /* setting the builtin profile is equal to removing the profile */
-          gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME);
+          gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME,
+                                      push_undo);
           g_object_unref (profile);
           return;
         }
@@ -3638,7 +3640,7 @@ gimp_image_parasite_attach (GimpImage          *image,
   /*  only set the dirty bit manually if we can be saved and the new
    *  parasite differs from the current one and we aren't undoable
    */
-  if (gimp_parasite_is_undoable (&copy))
+  if (push_undo && gimp_parasite_is_undoable (&copy))
     gimp_image_undo_push_image_parasite (image,
                                          C_("undo-type", "Attach Parasite to Image"),
                                          &copy);
@@ -3651,22 +3653,23 @@ gimp_image_parasite_attach (GimpImage          *image,
    */
   gimp_parasite_list_add (private->parasites, &copy);
 
-  if (gimp_parasite_has_flag (&copy, GIMP_PARASITE_ATTACH_PARENT))
+  if (push_undo && gimp_parasite_has_flag (&copy, GIMP_PARASITE_ATTACH_PARENT))
     {
       gimp_parasite_shift_parent (&copy);
       gimp_parasite_attach (image->gimp, &copy);
     }
 
-  g_signal_emit (image, gimp_image_signals[PARASITE_ATTACHED], 0,
-                 name);
-
   if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
     _gimp_image_update_color_profile (image, parasite);
+
+  g_signal_emit (image, gimp_image_signals[PARASITE_ATTACHED], 0,
+                 name);
 }
 
 void
 gimp_image_parasite_detach (GimpImage   *image,
-                            const gchar *name)
+                            const gchar *name,
+                            gboolean     push_undo)
 {
   GimpImagePrivate   *private;
   const GimpParasite *parasite;
@@ -3679,18 +3682,18 @@ gimp_image_parasite_detach (GimpImage   *image,
   if (! (parasite = gimp_parasite_list_find (private->parasites, name)))
     return;
 
-  if (gimp_parasite_is_undoable (parasite))
+  if (push_undo && gimp_parasite_is_undoable (parasite))
     gimp_image_undo_push_image_parasite_remove (image,
                                                 C_("undo-type", "Remove Parasite from Image"),
                                                 name);
 
   gimp_parasite_list_remove (private->parasites, name);
 
-  g_signal_emit (image, gimp_image_signals[PARASITE_DETACHED], 0,
-                 name);
-
   if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
     _gimp_image_update_color_profile (image, NULL);
+
+  g_signal_emit (image, gimp_image_signals[PARASITE_DETACHED], 0,
+                 name);
 }
 
 
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 26daa9453c..35ffd87a41 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -315,9 +315,11 @@ gboolean        gimp_image_parasite_validate     (GimpImage          *image,
                                                   const GimpParasite *parasite,
                                                   GError            **error);
 void            gimp_image_parasite_attach       (GimpImage          *image,
-                                                  const GimpParasite *parasite);
+                                                  const GimpParasite *parasite,
+                                                  gboolean            push_undo);
 void            gimp_image_parasite_detach       (GimpImage          *image,
-                                                  const gchar        *name);
+                                                  const gchar        *name,
+                                                  gboolean            push_undo);
 
 
 /*  tattoos  */
diff --git a/app/core/gimpimageundo.c b/app/core/gimpimageundo.c
index 9103f53c74..8aa9e111f5 100644
--- a/app/core/gimpimageundo.c
+++ b/app/core/gimpimageundo.c
@@ -39,7 +39,6 @@
 #include "gimpimage-metadata.h"
 #include "gimpimage-private.h"
 #include "gimpimageundo.h"
-#include "gimpparasitelist.h"
 
 
 enum
@@ -501,21 +500,14 @@ gimp_image_undo_pop (GimpUndo            *undo,
     case GIMP_UNDO_PARASITE_REMOVE:
       {
         GimpParasite *parasite = image_undo->parasite;
-        const gchar  *name;
 
         image_undo->parasite = gimp_parasite_copy
           (gimp_image_parasite_find (image, image_undo->parasite_name));
 
         if (parasite)
-          gimp_parasite_list_add (private->parasites, parasite);
+          gimp_image_parasite_attach (image, parasite, FALSE);
         else
-          gimp_parasite_list_remove (private->parasites,
-                                     image_undo->parasite_name);
-
-        name = parasite ? parasite->name : image_undo->parasite_name;
-
-        if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
-          _gimp_image_update_color_profile (image, parasite);
+          gimp_image_parasite_detach (image, image_undo->parasite_name, FALSE);
 
         if (parasite)
           gimp_parasite_free (parasite);
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index d7856ef071..1cc0992ad8 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -2133,7 +2133,7 @@ gimp_item_parasite_attach (GimpItem           *item,
   if (gimp_parasite_has_flag (&copy, GIMP_PARASITE_ATTACH_PARENT))
     {
       gimp_parasite_shift_parent (&copy);
-      gimp_image_parasite_attach (private->image, &copy);
+      gimp_image_parasite_attach (private->image, &copy, TRUE);
     }
   else if (gimp_parasite_has_flag (&copy, GIMP_PARASITE_ATTACH_GRANDPARENT))
     {
diff --git a/app/file-data/file-data-gbr.c b/app/file-data/file-data-gbr.c
index d1df78e6f4..63d4c0e401 100644
--- a/app/file-data/file-data-gbr.c
+++ b/app/file-data/file-data-gbr.c
@@ -393,7 +393,7 @@ file_gbr_brush_to_image (Gimp      *gimp,
   parasite = gimp_parasite_new ("gimp-brush-name",
                                 GIMP_PARASITE_PERSISTENT,
                                 strlen (name) + 1, name);
-  gimp_image_parasite_attach (image, parasite);
+  gimp_image_parasite_attach (image, parasite, FALSE);
   gimp_parasite_free (parasite);
 
   layer = file_gbr_brush_to_layer (image, brush);
diff --git a/app/file-data/file-data-gih.c b/app/file-data/file-data-gih.c
index 01e1592ea1..240eb9dbca 100644
--- a/app/file-data/file-data-gih.c
+++ b/app/file-data/file-data-gih.c
@@ -187,7 +187,7 @@ file_gih_pipe_to_image (Gimp          *gimp,
   parasite = gimp_parasite_new ("gimp-brush-pipe-name",
                                 GIMP_PARASITE_PERSISTENT,
                                 strlen (name) + 1, name);
-  gimp_image_parasite_attach (image, parasite);
+  gimp_image_parasite_attach (image, parasite, FALSE);
   gimp_parasite_free (parasite);
 
   g_snprintf (spacing, sizeof (spacing), "%d",
@@ -196,7 +196,7 @@ file_gih_pipe_to_image (Gimp          *gimp,
   parasite = gimp_parasite_new ("gimp-brush-pipe-spacing",
                                 GIMP_PARASITE_PERSISTENT,
                                 strlen (spacing) + 1, spacing);
-  gimp_image_parasite_attach (image, parasite);
+  gimp_image_parasite_attach (image, parasite, FALSE);
   gimp_parasite_free (parasite);
 
   for (i = 0; i < pipe->n_brushes; i++)
@@ -235,7 +235,7 @@ file_gih_pipe_to_image (Gimp          *gimp,
                                         GIMP_PARASITE_PERSISTENT,
                                         strlen (paramstring) + 1,
                                         paramstring);
-          gimp_image_parasite_attach (image, parasite);
+          gimp_image_parasite_attach (image, parasite, FALSE);
           gimp_parasite_free (parasite);
           g_free (paramstring);
         }
diff --git a/app/file-data/file-data-pat.c b/app/file-data/file-data-pat.c
index 4ecd7f180f..21506fe30e 100644
--- a/app/file-data/file-data-pat.c
+++ b/app/file-data/file-data-pat.c
@@ -211,7 +211,7 @@ file_pat_pattern_to_image (Gimp        *gimp,
   parasite = gimp_parasite_new ("gimp-pattern-name",
                                 GIMP_PARASITE_PERSISTENT,
                                 strlen (name) + 1, name);
-  gimp_image_parasite_attach (image, parasite);
+  gimp_image_parasite_attach (image, parasite, FALSE);
   gimp_parasite_free (parasite);
 
   format = gimp_image_get_layer_format (image, alpha);
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 09aa6ae892..9a6bdf680b 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -2847,7 +2847,7 @@ image_attach_parasite_invoker (GimpProcedure         *procedure,
   if (success)
     {
       if (gimp_image_parasite_validate (image, parasite, error))
-        gimp_image_parasite_attach (image, parasite);
+        gimp_image_parasite_attach (image, parasite, TRUE);
       else
         success = FALSE;
     }
@@ -2873,7 +2873,7 @@ image_detach_parasite_invoker (GimpProcedure         *procedure,
 
   if (success)
     {
-      gimp_image_parasite_detach (image, name);
+      gimp_image_parasite_detach (image, name, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/pdb/plug-in-compat-cmds.c b/app/pdb/plug-in-compat-cmds.c
index 17e1a48549..d029ac6308 100644
--- a/app/pdb/plug-in-compat-cmds.c
+++ b/app/pdb/plug-in-compat-cmds.c
@@ -2136,7 +2136,7 @@ plug_in_icc_profile_set_invoker (GimpProcedure         *procedure,
                                            _("Set color profile"));
 
               if (gimp_image_set_color_profile (image, p, error))
-                gimp_image_parasite_detach (image, "icc-profile-name");
+                gimp_image_parasite_detach (image, "icc-profile-name", TRUE);
               else
                 success = FALSE;
 
@@ -2191,7 +2191,7 @@ plug_in_icc_profile_set_rgb_invoker (GimpProcedure         *procedure,
                                            _("Set color profile"));
 
               if (gimp_image_set_color_profile (image, p, error))
-                gimp_image_parasite_detach (image, "icc-profile-name");
+                gimp_image_parasite_detach (image, "icc-profile-name", TRUE);
               else
                 success = FALSE;
 
diff --git a/app/widgets/gimpimagecommenteditor.c b/app/widgets/gimpimagecommenteditor.c
index c9be06f3a8..e41accc99b 100644
--- a/app/widgets/gimpimagecommenteditor.c
+++ b/app/widgets/gimpimagecommenteditor.c
@@ -212,12 +212,12 @@ gimp_image_comment_editor_buffer_changed (GtkTextBuffer          *buffer,
                                     GIMP_PARASITE_PERSISTENT,
                                     len + 1, text);
 
-      gimp_image_parasite_attach (image, parasite);
+      gimp_image_parasite_attach (image, parasite, TRUE);
       gimp_parasite_free (parasite);
     }
   else
     {
-      gimp_image_parasite_detach (image, GIMP_IMAGE_COMMENT_PARASITE);
+      gimp_image_parasite_detach (image, GIMP_IMAGE_COMMENT_PARASITE, TRUE);
     }
 
   editor->recoursing = FALSE;
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 0aeb601c01..8fc60c6f93 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -915,7 +915,7 @@ xcf_load_image_props (XcfInfo   *info,
                   }
                 else
                   {
-                    gimp_image_parasite_attach (image, p);
+                    gimp_image_parasite_attach (image, p, FALSE);
                   }
 
                 gimp_parasite_free (p);
diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb
index 4282660d21..690ccec46d 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -2895,7 +2895,7 @@ HELP
         code => <<'CODE'
 {
   if (gimp_image_parasite_validate (image, parasite, error))
-    gimp_image_parasite_attach (image, parasite);
+    gimp_image_parasite_attach (image, parasite, TRUE);
   else
     success = FALSE;
 }
@@ -2922,7 +2922,7 @@ HELP
     %invoke = (
         code => <<'CODE'
 {
-  gimp_image_parasite_detach (image, name);
+  gimp_image_parasite_detach (image, name, TRUE);
 }
 CODE
     );
diff --git a/pdb/groups/plug_in_compat.pdb b/pdb/groups/plug_in_compat.pdb
index 37b90bd7dd..826c845c0c 100644
--- a/pdb/groups/plug_in_compat.pdb
+++ b/pdb/groups/plug_in_compat.pdb
@@ -2041,7 +2041,7 @@ HELP
                                        _("Set color profile"));
 
           if (gimp_image_set_color_profile (image, p, error))
-            gimp_image_parasite_detach (image, "icc-profile-name");
+            gimp_image_parasite_detach (image, "icc-profile-name", TRUE);
           else
             success = FALSE;
 
@@ -2103,7 +2103,7 @@ HELP
                                        _("Set color profile"));
 
           if (gimp_image_set_color_profile (image, p, error))
-            gimp_image_parasite_detach (image, "icc-profile-name");
+            gimp_image_parasite_detach (image, "icc-profile-name", TRUE);
           else
             success = FALSE;
 


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