[gimp] app: add GimpProcedure::get_sensntive()



commit 926dd1dffbbe859b47d2c0531aa3fd26a0cc529f
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jan 1 23:24:53 2016 +0100

    app: add GimpProcedure::get_sensntive()
    
    to replace gimp_plug_in_procedure_get_seisitive().

 app/actions/filters-actions.c     |    8 +--
 app/actions/plug-in-actions.c     |    8 ++-
 app/pdb/gimpprocedure.c           |   21 ++++++++
 app/pdb/gimpprocedure.h           |    4 ++
 app/plug-in/gimppluginprocedure.c |   94 +++++++++++++++++++-----------------
 app/plug-in/gimppluginprocedure.h |    3 -
 6 files changed, 83 insertions(+), 55 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index 913f8c7..97a0588 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -28,7 +28,7 @@
 #include "core/gimpimage.h"
 #include "core/gimplayermask.h"
 
-#include "plug-in/gimppluginprocedure.h" /* FIXME history */
+#include "pdb/gimpprocedure.h"
 
 #include "widgets/gimpactiongroup.h"
 #include "widgets/gimphelp-ids.h"
@@ -717,8 +717,7 @@ filters_actions_update (GimpActionGroup *group,
     GimpProcedure *proc = gimp_filter_history_nth (group->gimp, 0);
     gint           i;
 
-    /* FIXME history */
-    if (proc && gimp_plug_in_procedure_get_sensitive (GIMP_PLUG_IN_PROCEDURE (proc), drawable))
+    if (proc && gimp_procedure_get_sensitive (proc, GIMP_OBJECT (drawable)))
       {
         gimp_action_group_set_action_sensitive (group, "filters-repeat", TRUE);
         gimp_action_group_set_action_sensitive (group, "filters-reshow", TRUE);
@@ -736,8 +735,7 @@ filters_actions_update (GimpActionGroup *group,
 
         proc = gimp_filter_history_nth (group->gimp, i);
 
-        /* FIXME history */
-        sensitive = gimp_plug_in_procedure_get_sensitive (GIMP_PLUG_IN_PROCEDURE (proc), drawable);
+        sensitive = gimp_procedure_get_sensitive (proc, GIMP_OBJECT (drawable));
 
         gimp_action_group_set_action_sensitive (group, name, sensitive);
 
diff --git a/app/actions/plug-in-actions.c b/app/actions/plug-in-actions.c
index a2f042b..e7d5f74 100644
--- a/app/actions/plug-in-actions.c
+++ b/app/actions/plug-in-actions.c
@@ -156,8 +156,9 @@ plug_in_actions_update (GimpActionGroup *group,
           ! proc->file_proc                      &&
           proc->image_types_val)
         {
-          gboolean sensitive = gimp_plug_in_procedure_get_sensitive (proc,
-                                                                     drawable);
+          gboolean sensitive =
+            gimp_procedure_get_sensitive (GIMP_PROCEDURE (proc),
+                                          GIMP_OBJECT (drawable));
 
           gimp_action_group_set_action_sensitive (group,
                                                   gimp_object_get_name (proc),
@@ -373,7 +374,8 @@ plug_in_actions_add_proc (GimpActionGroup     *group,
       if (image)
         drawable = gimp_image_get_active_drawable (image);
 
-      sensitive = gimp_plug_in_procedure_get_sensitive (proc, drawable);
+      sensitive = gimp_procedure_get_sensitive (GIMP_PROCEDURE (proc),
+                                                GIMP_OBJECT (drawable));
 
       gimp_action_group_set_action_sensitive (group,
                                               gimp_object_get_name (proc),
diff --git a/app/pdb/gimpprocedure.c b/app/pdb/gimpprocedure.c
index b68db38..9c041cc 100644
--- a/app/pdb/gimpprocedure.c
+++ b/app/pdb/gimpprocedure.c
@@ -51,6 +51,8 @@ static gint64        gimp_procedure_get_memsize         (GimpObject      *object
 static const gchar * gimp_procedure_real_get_label      (GimpProcedure   *procedure);
 static const gchar * gimp_procedure_real_get_menu_label (GimpProcedure   *procedure);
 static const gchar * gimp_procedure_real_get_blurb      (GimpProcedure   *procedure);
+static gboolean      gimp_procedure_real_get_sensitive  (GimpProcedure   *procedure,
+                                                         GimpObject      *object);
 static GimpValueArray * gimp_procedure_real_execute     (GimpProcedure   *procedure,
                                                          Gimp            *gimp,
                                                          GimpContext     *context,
@@ -91,6 +93,7 @@ gimp_procedure_class_init (GimpProcedureClass *klass)
   klass->get_label               = gimp_procedure_real_get_label;
   klass->get_menu_label          = gimp_procedure_real_get_menu_label;
   klass->get_blurb               = gimp_procedure_real_get_blurb;
+  klass->get_sensitive           = gimp_procedure_real_get_sensitive;
   klass->execute                 = gimp_procedure_real_execute;
   klass->execute_async           = gimp_procedure_real_execute_async;
 }
@@ -181,6 +184,13 @@ gimp_procedure_real_get_blurb (GimpProcedure *procedure)
   return procedure->blurb;
 }
 
+static gboolean
+gimp_procedure_real_get_sensitive (GimpProcedure *procedure,
+                                   GimpObject    *object)
+{
+  return TRUE /* random fallback */;
+}
+
 static GimpValueArray *
 gimp_procedure_real_execute (GimpProcedure   *procedure,
                              Gimp            *gimp,
@@ -343,6 +353,17 @@ gimp_procedure_get_blurb (GimpProcedure *procedure)
   return GIMP_PROCEDURE_GET_CLASS (procedure)->get_blurb (procedure);
 }
 
+gboolean
+gimp_procedure_get_sensitive (GimpProcedure *procedure,
+                              GimpObject    *object)
+{
+  g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), FALSE);
+  g_return_val_if_fail (object == NULL || GIMP_IS_OBJECT (object), FALSE);
+
+  return GIMP_PROCEDURE_GET_CLASS (procedure)->get_sensitive (procedure,
+                                                              object);
+}
+
 GimpValueArray *
 gimp_procedure_execute (GimpProcedure   *procedure,
                         Gimp            *gimp,
diff --git a/app/pdb/gimpprocedure.h b/app/pdb/gimpprocedure.h
index 6602dd3..948386e 100644
--- a/app/pdb/gimpprocedure.h
+++ b/app/pdb/gimpprocedure.h
@@ -72,6 +72,8 @@ struct _GimpProcedureClass
   const gchar    * (* get_label)      (GimpProcedure   *procedure);
   const gchar    * (* get_menu_label) (GimpProcedure   *procedure);
   const gchar    * (* get_blurb)      (GimpProcedure   *procedure);
+  gboolean         (* get_sensitive)  (GimpProcedure   *procedure,
+                                       GimpObject      *object);
 
   GimpValueArray * (* execute)        (GimpProcedure   *procedure,
                                        Gimp            *gimp,
@@ -120,6 +122,8 @@ void             gimp_procedure_take_strings       (GimpProcedure    *procedure,
 const gchar    * gimp_procedure_get_label          (GimpProcedure    *procedure);
 const gchar    * gimp_procedure_get_menu_label     (GimpProcedure    *procedure);
 const gchar    * gimp_procedure_get_blurb          (GimpProcedure    *procedure);
+gboolean         gimp_procedure_get_sensitive      (GimpProcedure    *procedure,
+                                                    GimpObject       *object);
 
 void             gimp_procedure_add_argument       (GimpProcedure    *procedure,
                                                     GParamSpec       *pspec);
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index 4c3c04f..238e537 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -65,6 +65,8 @@ static const gchar * gimp_plug_in_procedure_get_label  (GimpProcedure  *procedur
 static const gchar * gimp_plug_in_procedure_get_menu_label
                                                        (GimpProcedure  *procedure);
 static const gchar * gimp_plug_in_procedure_get_blurb  (GimpProcedure  *procedure);
+static gboolean   gimp_plug_in_procedure_get_sensitive (GimpProcedure  *procedure,
+                                                        GimpObject     *object);
 static GimpValueArray * gimp_plug_in_procedure_execute (GimpProcedure  *procedure,
                                                         Gimp           *gimp,
                                                         GimpContext    *context,
@@ -117,6 +119,7 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
   proc_class->get_label             = gimp_plug_in_procedure_get_label;
   proc_class->get_menu_label        = gimp_plug_in_procedure_get_menu_label;
   proc_class->get_blurb             = gimp_plug_in_procedure_get_blurb;
+  proc_class->get_sensitive         = gimp_plug_in_procedure_get_sensitive;
   proc_class->execute               = gimp_plug_in_procedure_execute;
   proc_class->execute_async         = gimp_plug_in_procedure_execute_async;
 
@@ -302,6 +305,53 @@ gimp_plug_in_procedure_get_blurb (GimpProcedure *procedure)
   return NULL;
 }
 
+static gboolean
+gimp_plug_in_procedure_get_sensitive (GimpProcedure *procedure,
+                                      GimpObject    *object)
+{
+  GimpPlugInProcedure *proc       = GIMP_PLUG_IN_PROCEDURE (procedure);
+  GimpDrawable        *drawable;
+  GimpImageType        image_type = -1;
+  gboolean             sensitive  = FALSE;
+
+  g_return_val_if_fail (object == NULL || GIMP_IS_DRAWABLE (object), FALSE);
+
+  drawable = GIMP_DRAWABLE (object);
+
+  if (drawable)
+    {
+      const Babl *format = gimp_drawable_get_format (drawable);
+
+      image_type = gimp_babl_format_get_image_type (format);
+    }
+
+  switch (image_type)
+    {
+    case GIMP_RGB_IMAGE:
+      sensitive = proc->image_types_val & GIMP_PLUG_IN_RGB_IMAGE;
+      break;
+    case GIMP_RGBA_IMAGE:
+      sensitive = proc->image_types_val & GIMP_PLUG_IN_RGBA_IMAGE;
+      break;
+    case GIMP_GRAY_IMAGE:
+      sensitive = proc->image_types_val & GIMP_PLUG_IN_GRAY_IMAGE;
+      break;
+    case GIMP_GRAYA_IMAGE:
+      sensitive = proc->image_types_val & GIMP_PLUG_IN_GRAYA_IMAGE;
+      break;
+    case GIMP_INDEXED_IMAGE:
+      sensitive = proc->image_types_val & GIMP_PLUG_IN_INDEXED_IMAGE;
+      break;
+    case GIMP_INDEXEDA_IMAGE:
+      sensitive = proc->image_types_val & GIMP_PLUG_IN_INDEXEDA_IMAGE;
+      break;
+    default:
+      break;
+    }
+
+  return sensitive ? TRUE : FALSE;
+}
+
 static GimpValueArray *
 gimp_plug_in_procedure_execute (GimpProcedure  *procedure,
                                 Gimp           *gimp,
@@ -737,50 +787,6 @@ gimp_plug_in_procedure_get_help_id (const GimpPlugInProcedure *proc)
   return g_strdup (gimp_object_get_name (proc));
 }
 
-gboolean
-gimp_plug_in_procedure_get_sensitive (const GimpPlugInProcedure *proc,
-                                      GimpDrawable              *drawable)
-{
-  GimpImageType image_type = -1;
-  gboolean      sensitive  = FALSE;
-
-  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE);
-  g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), FALSE);
-
-  if (drawable)
-    {
-      const Babl *format = gimp_drawable_get_format (drawable);
-
-      image_type = gimp_babl_format_get_image_type (format);
-    }
-
-  switch (image_type)
-    {
-    case GIMP_RGB_IMAGE:
-      sensitive = proc->image_types_val & GIMP_PLUG_IN_RGB_IMAGE;
-      break;
-    case GIMP_RGBA_IMAGE:
-      sensitive = proc->image_types_val & GIMP_PLUG_IN_RGBA_IMAGE;
-      break;
-    case GIMP_GRAY_IMAGE:
-      sensitive = proc->image_types_val & GIMP_PLUG_IN_GRAY_IMAGE;
-      break;
-    case GIMP_GRAYA_IMAGE:
-      sensitive = proc->image_types_val & GIMP_PLUG_IN_GRAYA_IMAGE;
-      break;
-    case GIMP_INDEXED_IMAGE:
-      sensitive = proc->image_types_val & GIMP_PLUG_IN_INDEXED_IMAGE;
-      break;
-    case GIMP_INDEXEDA_IMAGE:
-      sensitive = proc->image_types_val & GIMP_PLUG_IN_INDEXEDA_IMAGE;
-      break;
-    default:
-      break;
-    }
-
-  return sensitive ? TRUE : FALSE;
-}
-
 static GimpPlugInImageType
 image_types_parse (const gchar *name,
                    const gchar *image_types)
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index d688236..aa2ec3b 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -112,9 +112,6 @@ void          gimp_plug_in_procedure_take_icon       (GimpPlugInProcedure
 
 gchar       * gimp_plug_in_procedure_get_help_id     (const GimpPlugInProcedure *proc);
 
-gboolean      gimp_plug_in_procedure_get_sensitive   (const GimpPlugInProcedure *proc,
-                                                      GimpDrawable              *drawable);
-
 void          gimp_plug_in_procedure_set_image_types (GimpPlugInProcedure       *proc,
                                                       const gchar               *image_types);
 void          gimp_plug_in_procedure_set_file_proc   (GimpPlugInProcedure       *proc,


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