[gimp] Bug 789901 - Gimp allows duplicating non-duplicatable data objects ...



commit 2fe6575d7ea1e29de2fe2927030e35c3803c6c85
Author: Ell <ell_se yahoo com>
Date:   Sat Nov 4 21:47:08 2017 -0400

    Bug 789901 - Gimp allows duplicating non-duplicatable data objects ...
    
    ... leading to a crash
    
    Add gimp_data_is_copyable() and gimp_data_is_dulicatable().
    
    Use gimp_data_is_duplicatable() when setting the sensitivity of the
    various "foo-duplicate" actions, instead of inspecting the object's
    GimpDataClass::duplicate pointer directly, since this is no longer
    an indication of whether a GimpData object is duplicatable or not
    (since commit 33de4d5530b3768dbba3a98fca60dfe32a3fed59).

 app/actions/brushes-actions.c         |    2 +-
 app/actions/dynamics-actions.c        |    2 +-
 app/actions/mypaint-brushes-actions.c |    2 +-
 app/actions/palettes-actions.c        |    2 +-
 app/actions/patterns-actions.c        |    2 +-
 app/actions/tool-presets-actions.c    |    2 +-
 app/core/gimpdata.c                   |   21 ++++++++++++++++++++-
 7 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/app/actions/brushes-actions.c b/app/actions/brushes-actions.c
index d0e3acd..9cf6cf1 100644
--- a/app/actions/brushes-actions.c
+++ b/app/actions/brushes-actions.c
@@ -140,7 +140,7 @@ brushes_actions_update (GimpActionGroup *group,
 
   SET_SENSITIVE ("brushes-edit",                 brush);
   SET_SENSITIVE ("brushes-open-as-image",        file && ! GIMP_IS_BRUSH_GENERATED (brush));
-  SET_SENSITIVE ("brushes-duplicate",            brush && GIMP_DATA_GET_CLASS (data)->duplicate);
+  SET_SENSITIVE ("brushes-duplicate",            brush && gimp_data_is_duplicatable (data));
   SET_SENSITIVE ("brushes-copy-location",        file);
   SET_SENSITIVE ("brushes-show-in-file-manager", file);
   SET_SENSITIVE ("brushes-delete",               brush && gimp_data_is_deletable (data));
diff --git a/app/actions/dynamics-actions.c b/app/actions/dynamics-actions.c
index b6c9ff7..48fcab4 100644
--- a/app/actions/dynamics-actions.c
+++ b/app/actions/dynamics-actions.c
@@ -128,7 +128,7 @@ dynamics_actions_update (GimpActionGroup *group,
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
   SET_SENSITIVE ("dynamics-edit",                 dynamics);
-  SET_SENSITIVE ("dynamics-duplicate",            dynamics && GIMP_DATA_GET_CLASS (data)->duplicate);
+  SET_SENSITIVE ("dynamics-duplicate",            dynamics && gimp_data_is_duplicatable (data));
   SET_SENSITIVE ("dynamics-copy-location",        file);
   SET_SENSITIVE ("dynamics-show-in-file-manager", file);
   SET_SENSITIVE ("dynamics-delete",               dynamics && gimp_data_is_deletable (data));
diff --git a/app/actions/mypaint-brushes-actions.c b/app/actions/mypaint-brushes-actions.c
index d3d8a7d..8572b90 100644
--- a/app/actions/mypaint-brushes-actions.c
+++ b/app/actions/mypaint-brushes-actions.c
@@ -133,7 +133,7 @@ mypaint_brushes_actions_update (GimpActionGroup *group,
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
   SET_SENSITIVE ("mypaint-brushes-edit",                 brush && FALSE);
-  SET_SENSITIVE ("mypaint-brushes-duplicate",            brush && GIMP_DATA_GET_CLASS (data)->duplicate);
+  SET_SENSITIVE ("mypaint-brushes-duplicate",            brush && gimp_data_is_duplicatable (data));
   SET_SENSITIVE ("mypaint-brushes-copy-location",        file);
   SET_SENSITIVE ("mypaint-brushes-show-in-file-manager", file);
   SET_SENSITIVE ("mypaint-brushes-delete",               brush && gimp_data_is_deletable (data));
diff --git a/app/actions/palettes-actions.c b/app/actions/palettes-actions.c
index d3a2b3b..08d6848 100644
--- a/app/actions/palettes-actions.c
+++ b/app/actions/palettes-actions.c
@@ -149,7 +149,7 @@ palettes_actions_update (GimpActionGroup *group,
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
   SET_SENSITIVE ("palettes-edit",                 palette);
-  SET_SENSITIVE ("palettes-duplicate",            palette && GIMP_DATA_GET_CLASS (data)->duplicate);
+  SET_SENSITIVE ("palettes-duplicate",            palette && gimp_data_is_duplicatable (data));
   SET_SENSITIVE ("palettes-merge",                sel_count > 1);
   SET_SENSITIVE ("palettes-copy-location",        file);
   SET_SENSITIVE ("palettes-show-in-file-manager", file);
diff --git a/app/actions/patterns-actions.c b/app/actions/patterns-actions.c
index d253083..f825976 100644
--- a/app/actions/patterns-actions.c
+++ b/app/actions/patterns-actions.c
@@ -140,7 +140,7 @@ patterns_actions_update (GimpActionGroup *group,
 
   SET_SENSITIVE ("patterns-edit",                 pattern && FALSE);
   SET_SENSITIVE ("patterns-open-as-image",        file);
-  SET_SENSITIVE ("patterns-duplicate",            pattern && GIMP_DATA_GET_CLASS (data)->duplicate);
+  SET_SENSITIVE ("patterns-duplicate",            pattern && gimp_data_is_duplicatable (data));
   SET_SENSITIVE ("patterns-copy-location",        file);
   SET_SENSITIVE ("patterns-show-in-file-manager", file);
   SET_SENSITIVE ("patterns-delete",               pattern && gimp_data_is_deletable (data));
diff --git a/app/actions/tool-presets-actions.c b/app/actions/tool-presets-actions.c
index 83a275e..99e31f9 100644
--- a/app/actions/tool-presets-actions.c
+++ b/app/actions/tool-presets-actions.c
@@ -144,7 +144,7 @@ tool_presets_actions_update (GimpActionGroup *group,
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
   SET_SENSITIVE ("tool-presets-edit",                 tool_preset);
-  SET_SENSITIVE ("tool-presets-duplicate",            tool_preset && GIMP_DATA_GET_CLASS (data)->duplicate);
+  SET_SENSITIVE ("tool-presets-duplicate",            tool_preset && gimp_data_is_duplicatable (data));
   SET_SENSITIVE ("tool-presets-copy-location",        file);
   SET_SENSITIVE ("tool-presets-show-in-file-manager", file);
   SET_SENSITIVE ("tool-presets-save",                 tool_preset);
diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c
index 4f124fd..5dcc26e 100644
--- a/app/core/gimpdata.c
+++ b/app/core/gimpdata.c
@@ -1112,6 +1112,14 @@ gimp_data_get_mtime (GimpData *data)
   return private->mtime;
 }
 
+gboolean
+gimp_data_is_copyable (GimpData *data)
+{
+  g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
+
+  return GIMP_DATA_GET_CLASS (data)->copy != NULL;
+}
+
 /**
  * gimp_data_copy:
  * @data:     a #GimpData object
@@ -1134,6 +1142,17 @@ gimp_data_copy (GimpData *data,
     GIMP_DATA_GET_CLASS (data)->copy (data, src_data);
 }
 
+gboolean
+gimp_data_is_duplicatable (GimpData *data)
+{
+  g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
+
+  if (GIMP_DATA_GET_CLASS (data)->duplicate == gimp_data_real_duplicate)
+    return gimp_data_is_copyable (data);
+  else
+    return GIMP_DATA_GET_CLASS (data)->duplicate != NULL;
+}
+
 /**
  * gimp_data_duplicate:
  * @data: a #GimpData object
@@ -1149,7 +1168,7 @@ gimp_data_duplicate (GimpData *data)
 {
   g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
 
-  if (GIMP_DATA_GET_CLASS (data)->duplicate)
+  if (gimp_data_is_duplicatable (data))
     {
       GimpData        *new     = GIMP_DATA_GET_CLASS (data)->duplicate (data);
       GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (new);


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