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



commit 710cfc1f478a2d9b75b622ee1445972feeb19c9a
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.

 app/core/gimp.c                      |  2 +-
 app/core/gimpimage-color-profile.c   |  8 ++++----
 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/widgets/gimpimagecommenteditor.c |  4 ++--
 app/xcf/xcf-load.c                   |  2 +-
 pdb/groups/image.pdb                 |  4 ++--
 14 files changed, 40 insertions(+), 43 deletions(-)
---
diff --git a/app/core/gimp.c b/app/core/gimp.c
index ce6d7f8732..6a12fa877c 100644
--- a/app/core/gimp.c
+++ b/app/core/gimp.c
@@ -990,7 +990,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 472ad3932f..961f0fc879 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -232,11 +232,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);
     }
 }
 
@@ -482,7 +482,7 @@ gimp_image_assign_color_profile (GimpImage         *image,
 
   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);
 
   if (gimp_image_get_base_type (image) == GIMP_INDEXED)
     gimp_image_colormap_update_formats (image);
@@ -533,7 +533,7 @@ gimp_image_convert_color_profile (GimpImage                *image,
 
   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);
 
   switch (gimp_image_get_base_type (image))
     {
diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c
index d695e96ae0..407c5243c7 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 025cbc4949..6ff4620220 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 da851e6d84..a5a6e94d02 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -318,9 +318,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 fa940e10c7..d3d4ee5ef2 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
@@ -502,21 +501,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 8678a1a15c..199aa12a00 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 07da2f349b..99e2a13eaa 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 777bf63afe..5d41f883f9 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 744518f37b..969c153f41 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -2664,7 +2664,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;
     }
@@ -2690,7 +2690,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/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 f7bd071fa3..64378650d3 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -924,7 +924,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 cb12bfead8..e3beb17d16 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -2743,7 +2743,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;
 }
@@ -2770,7 +2770,7 @@ HELP
     %invoke = (
         code => <<'CODE'
 {
-  gimp_image_parasite_detach (image, name);
+  gimp_image_parasite_detach (image, name, TRUE);
 }
 CODE
     );


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