[gimp] app: add "gboolean push_undo" to gimp_item_parasite_attach/detach()



commit 90419e067206de85b7e30e11dbd6e0f6b0fc97fc
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jan 30 20:40:43 2011 +0100

    app: add "gboolean push_undo" to gimp_item_parasite_attach/detach()
    
    and use this API instead of manually fiddling with the item's
    GimpParasiteList.

 app/core/gimpitem.c           |   37 ++++++++++++++++++++++++-------------
 app/core/gimpitem.h           |    6 ++++--
 app/core/gimpitempropundo.c   |    5 ++---
 app/pdb/parasite-cmds.c       |   12 ++++++------
 app/text/gimptextlayer-xcf.c  |    5 ++++-
 app/text/gimptextlayer.c      |   11 +++++++----
 app/xcf/xcf-load.c            |    6 +++---
 tools/pdbgen/pdb/parasite.pdb |   12 ++++++------
 8 files changed, 56 insertions(+), 38 deletions(-)
---
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 407e124..49dc808 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -1596,7 +1596,8 @@ gimp_item_replace_item (GimpItem *item,
 
 void
 gimp_item_parasite_attach (GimpItem           *item,
-                           const GimpParasite *parasite)
+                           const GimpParasite *parasite,
+                           gboolean            push_undo)
 {
   GimpParasite  copy;
 
@@ -1608,7 +1609,10 @@ gimp_item_parasite_attach (GimpItem           *item,
    */
   copy = *parasite;
 
-  if (gimp_item_is_attached (item))
+  if (! gimp_item_is_attached (item))
+    push_undo = FALSE;
+
+  if (push_undo)
     {
       /*  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
@@ -1655,7 +1659,8 @@ gimp_item_parasite_attach (GimpItem           *item,
 
 void
 gimp_item_parasite_detach (GimpItem    *item,
-                           const gchar *name)
+                           const gchar *name,
+                           gboolean     push_undo)
 {
   const GimpParasite *parasite;
 
@@ -1667,17 +1672,23 @@ gimp_item_parasite_detach (GimpItem    *item,
   if (! parasite)
     return;
 
-  if (gimp_parasite_is_undoable (parasite))
-    {
-      gimp_image_undo_push_item_parasite_remove (item->image,
-                                                 C_("undo-type", "Remove Parasite from Item"),
-                                                 item,
-                                                 gimp_parasite_name (parasite));
-    }
-  else if (gimp_parasite_is_persistent (parasite))
+  if (! gimp_item_is_attached (item))
+    push_undo = FALSE;
+
+  if (push_undo)
     {
-      gimp_image_undo_push_cantundo (item->image,
-                                     C_("undo-type", "Remove Parasite from Item"));
+      if (gimp_parasite_is_undoable (parasite))
+        {
+          gimp_image_undo_push_item_parasite_remove (item->image,
+                                                     C_("undo-type", "Remove Parasite from Item"),
+                                                     item,
+                                                     gimp_parasite_name (parasite));
+        }
+      else if (gimp_parasite_is_persistent (parasite))
+        {
+          gimp_image_undo_push_cantundo (item->image,
+                                         C_("undo-type", "Remove Parasite from Item"));
+        }
     }
 
   gimp_parasite_list_remove (item->parasites, name);
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index 091c9a6..777da67 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -290,9 +290,11 @@ void            gimp_item_replace_item       (GimpItem           *item,
                                               GimpItem           *replace);
 
 void            gimp_item_parasite_attach    (GimpItem           *item,
-                                              const GimpParasite *parasite);
+                                              const GimpParasite *parasite,
+                                              gboolean            push_undo);
 void            gimp_item_parasite_detach    (GimpItem           *item,
-                                              const gchar        *name);
+                                              const gchar        *name,
+                                              gboolean            push_undo);
 const GimpParasite * gimp_item_parasite_find (const GimpItem     *item,
                                               const gchar        *name);
 gchar        ** gimp_item_parasite_list      (const GimpItem     *item,
diff --git a/app/core/gimpitempropundo.c b/app/core/gimpitempropundo.c
index 8dd1b92..9413f3b 100644
--- a/app/core/gimpitempropundo.c
+++ b/app/core/gimpitempropundo.c
@@ -288,10 +288,9 @@ gimp_item_prop_undo_pop (GimpUndo            *undo,
           (gimp_item_parasite_find (item, item_prop_undo->parasite_name));
 
         if (parasite)
-          gimp_parasite_list_add (item->parasites, parasite);
+          gimp_item_parasite_attach (item, parasite, FALSE);
         else
-          gimp_parasite_list_remove (item->parasites,
-                                     item_prop_undo->parasite_name);
+          gimp_item_parasite_detach (item, item_prop_undo->parasite_name, FALSE);
 
         if (parasite)
           gimp_parasite_free (parasite);
diff --git a/app/pdb/parasite-cmds.c b/app/pdb/parasite-cmds.c
index b0eda39..4178032 100644
--- a/app/pdb/parasite-cmds.c
+++ b/app/pdb/parasite-cmds.c
@@ -301,7 +301,7 @@ item_parasite_attach_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      gimp_item_parasite_attach (item, parasite);
+      gimp_item_parasite_attach (item, parasite, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
@@ -325,7 +325,7 @@ item_parasite_detach_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      gimp_item_parasite_detach (item, name);
+      gimp_item_parasite_detach (item, name, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
@@ -417,7 +417,7 @@ drawable_parasite_attach_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      gimp_item_parasite_attach (GIMP_ITEM (drawable), parasite);
+      gimp_item_parasite_attach (GIMP_ITEM (drawable), parasite, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
@@ -441,7 +441,7 @@ drawable_parasite_detach_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      gimp_item_parasite_detach (GIMP_ITEM (drawable), name);
+      gimp_item_parasite_detach (GIMP_ITEM (drawable), name, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
@@ -533,7 +533,7 @@ vectors_parasite_attach_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite);
+      gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
@@ -557,7 +557,7 @@ vectors_parasite_detach_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      gimp_item_parasite_detach (GIMP_ITEM (vectors), name);
+      gimp_item_parasite_detach (GIMP_ITEM (vectors), name, TRUE);
     }
 
   return gimp_procedure_get_return_values (procedure, success,
diff --git a/app/text/gimptextlayer-xcf.c b/app/text/gimptextlayer-xcf.c
index c4b4c56..715ef28 100644
--- a/app/text/gimptextlayer-xcf.c
+++ b/app/text/gimptextlayer-xcf.c
@@ -121,7 +121,10 @@ gimp_text_layer_xcf_save_prepare (GimpTextLayer *layer)
     {
       GimpParasite *parasite = gimp_text_to_parasite (text);
 
-      gimp_parasite_list_add (GIMP_ITEM (layer)->parasites, parasite);
+      /*  Don't push an undo because the parasite only exists temporarily
+       *  while the text layer is saved to XCF.
+       */
+      gimp_item_parasite_attach (GIMP_ITEM (layer), parasite, FALSE);
     }
 }
 
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 8a09507..82227f2 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -539,13 +539,16 @@ gimp_item_is_text_layer (GimpItem *item)
 static void
 gimp_text_layer_text_changed (GimpTextLayer *layer)
 {
-  /*   If the text layer was created from a parasite, it's time to
-   *   remove that parasite now.
+  /*  If the text layer was created from a parasite, it's time to
+   *  remove that parasite now.
    */
   if (layer->text_parasite)
     {
-      gimp_parasite_list_remove (GIMP_ITEM (layer)->parasites,
-                                 layer->text_parasite);
+      /*  Don't push an undo because the parasite only exists temporarily
+       *  while the text layer is loaded from XCF.
+       */
+      gimp_item_parasite_detach (GIMP_ITEM (layer), layer->text_parasite,
+                                 FALSE);
       layer->text_parasite = NULL;
     }
 
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 7488b9a..e9f2f47 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -816,7 +816,7 @@ xcf_load_layer_props (XcfInfo    *info,
             while (info->cp - base < prop_size)
               {
                 p = xcf_load_parasite (info);
-                gimp_item_parasite_attach (GIMP_ITEM (*layer), p);
+                gimp_item_parasite_attach (GIMP_ITEM (*layer), p, FALSE);
                 gimp_parasite_free (p);
               }
 
@@ -1001,7 +1001,7 @@ xcf_load_channel_props (XcfInfo      *info,
             while ((info->cp - base) < prop_size)
               {
                 p = xcf_load_parasite (info);
-                gimp_item_parasite_attach (GIMP_ITEM (*channel), p);
+                gimp_item_parasite_attach (GIMP_ITEM (*channel), p, FALSE);
                 gimp_parasite_free (p);
               }
 
@@ -1859,7 +1859,7 @@ xcf_load_vector (XcfInfo   *info,
       if (! parasite)
         return FALSE;
 
-      gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite);
+      gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, FALSE);
       gimp_parasite_free (parasite);
     }
 
diff --git a/tools/pdbgen/pdb/parasite.pdb b/tools/pdbgen/pdb/parasite.pdb
index 41365dd..0416864 100644
--- a/tools/pdbgen/pdb/parasite.pdb
+++ b/tools/pdbgen/pdb/parasite.pdb
@@ -275,7 +275,7 @@ HELP
     %invoke = (
 	code => <<'CODE'
 {
-  gimp_item_parasite_attach (item, parasite);
+  gimp_item_parasite_attach (item, parasite, TRUE);
 }
 CODE
     );
@@ -300,7 +300,7 @@ HELP
     %invoke = (
 	code => <<'CODE'
 {
-  gimp_item_parasite_detach (item, name);
+  gimp_item_parasite_detach (item, name, TRUE);
 }
 CODE
     );
@@ -375,7 +375,7 @@ sub drawable_parasite_attach {
     %invoke = (
 	code => <<'CODE'
 {
-  gimp_item_parasite_attach (GIMP_ITEM (drawable), parasite);
+  gimp_item_parasite_attach (GIMP_ITEM (drawable), parasite, TRUE);
 }
 CODE
     );
@@ -395,7 +395,7 @@ sub drawable_parasite_detach {
     %invoke = (
 	code => <<'CODE'
 {
-  gimp_item_parasite_detach (GIMP_ITEM (drawable), name);
+  gimp_item_parasite_detach (GIMP_ITEM (drawable), name, TRUE);
 }
 CODE
     );
@@ -468,7 +468,7 @@ sub vectors_parasite_attach {
     %invoke = (
 	code => <<'CODE'
 {
-  gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite);
+  gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, TRUE);
 }
 CODE
     );
@@ -488,7 +488,7 @@ sub vectors_parasite_detach {
     %invoke = (
 	code => <<'CODE'
 {
-  gimp_item_parasite_detach (GIMP_ITEM (vectors), name);
+  gimp_item_parasite_detach (GIMP_ITEM (vectors), name, TRUE);
 }
 CODE
     );



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