[gimp/wip/Jehan/layers-dockable-refresh: 26/58] app, libgimp, pdb: add visibility lock API.




commit a40654cefcaa8fb3a9a42ea361142cd206cc9a4b
Author: Jehan <jehan girinstud io>
Date:   Fri Apr 23 17:01:19 2021 +0200

    app, libgimp, pdb: add visibility lock API.

 app/pdb/item-cmds.c    | 114 +++++++++++++++++++++++++++++++++++++++++++++++++
 libgimp/gimp.def       |   2 +
 libgimp/gimpitem_pdb.c |  74 ++++++++++++++++++++++++++++++++
 libgimp/gimpitem_pdb.h |  95 +++++++++++++++++++++--------------------
 pdb/groups/item.pdb    |  53 +++++++++++++++++++++++
 5 files changed, 292 insertions(+), 46 deletions(-)
---
diff --git a/app/pdb/item-cmds.c b/app/pdb/item-cmds.c
index 160954996a..796e9ae6f0 100644
--- a/app/pdb/item-cmds.c
+++ b/app/pdb/item-cmds.c
@@ -799,6 +799,62 @@ item_set_lock_position_invoker (GimpProcedure         *procedure,
                                            error ? *error : NULL);
 }
 
+static GimpValueArray *
+item_get_lock_visibility_invoker (GimpProcedure         *procedure,
+                                  Gimp                  *gimp,
+                                  GimpContext           *context,
+                                  GimpProgress          *progress,
+                                  const GimpValueArray  *args,
+                                  GError               **error)
+{
+  gboolean success = TRUE;
+  GimpValueArray *return_vals;
+  GimpItem *item;
+  gboolean lock_visibility = FALSE;
+
+  item = g_value_get_object (gimp_value_array_index (args, 0));
+
+  if (success)
+    {
+      lock_visibility = gimp_item_get_lock_visibility (GIMP_ITEM (item));
+    }
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_set_boolean (gimp_value_array_index (return_vals, 1), lock_visibility);
+
+  return return_vals;
+}
+
+static GimpValueArray *
+item_set_lock_visibility_invoker (GimpProcedure         *procedure,
+                                  Gimp                  *gimp,
+                                  GimpContext           *context,
+                                  GimpProgress          *progress,
+                                  const GimpValueArray  *args,
+                                  GError               **error)
+{
+  gboolean success = TRUE;
+  GimpItem *item;
+  gboolean lock_visibility;
+
+  item = g_value_get_object (gimp_value_array_index (args, 0));
+  lock_visibility = g_value_get_boolean (gimp_value_array_index (args, 1));
+
+  if (success)
+    {
+      if (gimp_item_can_lock_visibility (GIMP_ITEM (item)))
+        gimp_item_set_lock_visibility (GIMP_ITEM (item), lock_visibility, TRUE);
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 static GimpValueArray *
 item_get_color_tag_invoker (GimpProcedure         *procedure,
                             Gimp                  *gimp,
@@ -1755,6 +1811,64 @@ register_item_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
+  /*
+   * gimp-item-get-lock-visibility
+   */
+  procedure = gimp_procedure_new (item_get_lock_visibility_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-item-get-lock-visibility");
+  gimp_procedure_set_static_help (procedure,
+                                  "Get the 'lock visibility' state of the specified item.",
+                                  "This procedure returns the specified item's lock visibility state.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Jehan",
+                                         "Jehan",
+                                         "2021");
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_item ("item",
+                                                     "item",
+                                                     "The item",
+                                                     FALSE,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_procedure_add_return_value (procedure,
+                                   g_param_spec_boolean ("lock-visibility",
+                                                         "lock visibility",
+                                                         "Whether the item's visibility is locked",
+                                                         FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-item-set-lock-visibility
+   */
+  procedure = gimp_procedure_new (item_set_lock_visibility_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-item-set-lock-visibility");
+  gimp_procedure_set_static_help (procedure,
+                                  "Set the 'lock visibility' state of the specified item.",
+                                  "This procedure sets the specified item's lock visibility state.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Michael Natterer <mitch gimp org>",
+                                         "Michael Natterer",
+                                         "2009");
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_item ("item",
+                                                     "item",
+                                                     "The item",
+                                                     FALSE,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_boolean ("lock-visibility",
+                                                     "lock visibility",
+                                                     "The new item 'lock visibility' state",
+                                                     FALSE,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
   /*
    * gimp-item-get-color-tag
    */
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 154f44f094..8260814dfe 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -515,6 +515,7 @@ EXPORTS
        gimp_item_get_linked
        gimp_item_get_lock_content
        gimp_item_get_lock_position
+       gimp_item_get_lock_visibility
        gimp_item_get_name
        gimp_item_get_parasite
        gimp_item_get_parasite_list
@@ -545,6 +546,7 @@ EXPORTS
        gimp_item_set_linked
        gimp_item_set_lock_content
        gimp_item_set_lock_position
+       gimp_item_set_lock_visibility
        gimp_item_set_name
        gimp_item_set_tattoo
        gimp_item_set_visible
diff --git a/libgimp/gimpitem_pdb.c b/libgimp/gimpitem_pdb.c
index 839101285f..5b765db5c3 100644
--- a/libgimp/gimpitem_pdb.c
+++ b/libgimp/gimpitem_pdb.c
@@ -964,6 +964,80 @@ gimp_item_set_lock_position (GimpItem *item,
   return success;
 }
 
+/**
+ * gimp_item_get_lock_visibility:
+ * @item: The item.
+ *
+ * Get the 'lock visibility' state of the specified item.
+ *
+ * This procedure returns the specified item's lock visibility state.
+ *
+ * Returns: Whether the item's visibility is locked.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_item_get_lock_visibility (GimpItem *item)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean lock_visibility = FALSE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_ITEM, item,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-item-get-lock-visibility",
+                                              args);
+  gimp_value_array_unref (args);
+
+  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+    lock_visibility = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
+
+  gimp_value_array_unref (return_vals);
+
+  return lock_visibility;
+}
+
+/**
+ * gimp_item_set_lock_visibility:
+ * @item: The item.
+ * @lock_visibility: The new item 'lock visibility' state.
+ *
+ * Set the 'lock visibility' state of the specified item.
+ *
+ * This procedure sets the specified item's lock visibility state.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.8
+ **/
+gboolean
+gimp_item_set_lock_visibility (GimpItem *item,
+                               gboolean  lock_visibility)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          GIMP_TYPE_ITEM, item,
+                                          G_TYPE_BOOLEAN, lock_visibility,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-item-set-lock-visibility",
+                                              args);
+  gimp_value_array_unref (args);
+
+  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+  gimp_value_array_unref (return_vals);
+
+  return success;
+}
+
 /**
  * gimp_item_get_color_tag:
  * @item: The item.
diff --git a/libgimp/gimpitem_pdb.h b/libgimp/gimpitem_pdb.h
index 9bce970d62..d0daa3b286 100644
--- a/libgimp/gimpitem_pdb.h
+++ b/libgimp/gimpitem_pdb.h
@@ -32,52 +32,55 @@ G_BEGIN_DECLS
 /* For information look into the C source or the html documentation */
 
 
-gboolean      gimp_item_id_is_valid       (gint                item_id);
-gboolean      gimp_item_id_is_drawable    (gint                item_id);
-gboolean      gimp_item_id_is_layer       (gint                item_id);
-gboolean      gimp_item_id_is_text_layer  (gint                item_id);
-gboolean      gimp_item_id_is_channel     (gint                item_id);
-gboolean      gimp_item_id_is_layer_mask  (gint                item_id);
-gboolean      gimp_item_id_is_selection   (gint                item_id);
-gboolean      gimp_item_id_is_vectors     (gint                item_id);
-GimpImage*    gimp_item_get_image         (GimpItem           *item);
-gboolean      gimp_item_delete            (GimpItem           *item);
-gboolean      gimp_item_is_group          (GimpItem           *item);
-GimpItem*     gimp_item_get_parent        (GimpItem           *item);
-GimpItem**    gimp_item_get_children      (GimpItem           *item,
-                                           gint               *num_children);
-gboolean      gimp_item_get_expanded      (GimpItem           *item);
-gboolean      gimp_item_set_expanded      (GimpItem           *item,
-                                           gboolean            expanded);
-gchar*        gimp_item_get_name          (GimpItem           *item);
-gboolean      gimp_item_set_name          (GimpItem           *item,
-                                           const gchar        *name);
-gboolean      gimp_item_get_visible       (GimpItem           *item);
-gboolean      gimp_item_set_visible       (GimpItem           *item,
-                                           gboolean            visible);
-gboolean      gimp_item_get_linked        (GimpItem           *item);
-gboolean      gimp_item_set_linked        (GimpItem           *item,
-                                           gboolean            linked);
-gboolean      gimp_item_get_lock_content  (GimpItem           *item);
-gboolean      gimp_item_set_lock_content  (GimpItem           *item,
-                                           gboolean            lock_content);
-gboolean      gimp_item_get_lock_position (GimpItem           *item);
-gboolean      gimp_item_set_lock_position (GimpItem           *item,
-                                           gboolean            lock_position);
-GimpColorTag  gimp_item_get_color_tag     (GimpItem           *item);
-gboolean      gimp_item_set_color_tag     (GimpItem           *item,
-                                           GimpColorTag        color_tag);
-guint         gimp_item_get_tattoo        (GimpItem           *item);
-gboolean      gimp_item_set_tattoo        (GimpItem           *item,
-                                           guint               tattoo);
-gboolean      gimp_item_attach_parasite   (GimpItem           *item,
-                                           const GimpParasite *parasite);
-gboolean      gimp_item_detach_parasite   (GimpItem           *item,
-                                           const gchar        *name);
-GimpParasite* gimp_item_get_parasite      (GimpItem           *item,
-                                           const gchar        *name);
-gchar**       gimp_item_get_parasite_list (GimpItem           *item,
-                                           gint               *num_parasites);
+gboolean      gimp_item_id_is_valid         (gint                item_id);
+gboolean      gimp_item_id_is_drawable      (gint                item_id);
+gboolean      gimp_item_id_is_layer         (gint                item_id);
+gboolean      gimp_item_id_is_text_layer    (gint                item_id);
+gboolean      gimp_item_id_is_channel       (gint                item_id);
+gboolean      gimp_item_id_is_layer_mask    (gint                item_id);
+gboolean      gimp_item_id_is_selection     (gint                item_id);
+gboolean      gimp_item_id_is_vectors       (gint                item_id);
+GimpImage*    gimp_item_get_image           (GimpItem           *item);
+gboolean      gimp_item_delete              (GimpItem           *item);
+gboolean      gimp_item_is_group            (GimpItem           *item);
+GimpItem*     gimp_item_get_parent          (GimpItem           *item);
+GimpItem**    gimp_item_get_children        (GimpItem           *item,
+                                             gint               *num_children);
+gboolean      gimp_item_get_expanded        (GimpItem           *item);
+gboolean      gimp_item_set_expanded        (GimpItem           *item,
+                                             gboolean            expanded);
+gchar*        gimp_item_get_name            (GimpItem           *item);
+gboolean      gimp_item_set_name            (GimpItem           *item,
+                                             const gchar        *name);
+gboolean      gimp_item_get_visible         (GimpItem           *item);
+gboolean      gimp_item_set_visible         (GimpItem           *item,
+                                             gboolean            visible);
+gboolean      gimp_item_get_linked          (GimpItem           *item);
+gboolean      gimp_item_set_linked          (GimpItem           *item,
+                                             gboolean            linked);
+gboolean      gimp_item_get_lock_content    (GimpItem           *item);
+gboolean      gimp_item_set_lock_content    (GimpItem           *item,
+                                             gboolean            lock_content);
+gboolean      gimp_item_get_lock_position   (GimpItem           *item);
+gboolean      gimp_item_set_lock_position   (GimpItem           *item,
+                                             gboolean            lock_position);
+gboolean      gimp_item_get_lock_visibility (GimpItem           *item);
+gboolean      gimp_item_set_lock_visibility (GimpItem           *item,
+                                             gboolean            lock_visibility);
+GimpColorTag  gimp_item_get_color_tag       (GimpItem           *item);
+gboolean      gimp_item_set_color_tag       (GimpItem           *item,
+                                             GimpColorTag        color_tag);
+guint         gimp_item_get_tattoo          (GimpItem           *item);
+gboolean      gimp_item_set_tattoo          (GimpItem           *item,
+                                             guint               tattoo);
+gboolean      gimp_item_attach_parasite     (GimpItem           *item,
+                                             const GimpParasite *parasite);
+gboolean      gimp_item_detach_parasite     (GimpItem           *item,
+                                             const gchar        *name);
+GimpParasite* gimp_item_get_parasite        (GimpItem           *item,
+                                             const gchar        *name);
+gchar**       gimp_item_get_parasite_list   (GimpItem           *item,
+                                             gint               *num_parasites);
 
 
 G_END_DECLS
diff --git a/pdb/groups/item.pdb b/pdb/groups/item.pdb
index f8f808961a..24765f0696 100644
--- a/pdb/groups/item.pdb
+++ b/pdb/groups/item.pdb
@@ -752,6 +752,58 @@ CODE
     );
 }
 
+sub item_get_lock_visibility {
+    $blurb = "Get the 'lock visibility' state of the specified item.";
+
+    $help = "This procedure returns the specified item's lock visibility state.";
+
+    &jehan_pdb_misc('2021', '3.0');
+
+    @inargs = (
+       { name => 'item', type => 'item',
+         desc => 'The item' }
+    );
+
+    @outargs = (
+       { name => 'lock_visibility', type => 'boolean',
+         desc => "Whether the item's visibility is locked" }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  lock_visibility = gimp_item_get_lock_visibility (GIMP_ITEM (item));
+}
+CODE
+    );
+}
+
+sub item_set_lock_visibility {
+    $blurb = "Set the 'lock visibility' state of the specified item.";
+
+    $help = "This procedure sets the specified item's lock visibility state.";
+
+    &mitch_pdb_misc('2009', '2.8');
+
+    @inargs = (
+       { name => 'item', type => 'item',
+         desc => 'The item' },
+       { name => 'lock_visibility', type => 'boolean',
+         desc => "The new item 'lock visibility' state" }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  if (gimp_item_can_lock_visibility (GIMP_ITEM (item)))
+    gimp_item_set_lock_visibility (GIMP_ITEM (item), lock_visibility, TRUE);
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub item_get_color_tag {
     $blurb = "Get the color tag of the specified item.";
 
@@ -1000,6 +1052,7 @@ CODE
             item_get_linked item_set_linked
             item_get_lock_content item_set_lock_content
             item_get_lock_position item_set_lock_position
+            item_get_lock_visibility item_set_lock_visibility
             item_get_color_tag item_set_color_tag
             item_get_tattoo item_set_tattoo
            item_attach_parasite item_detach_parasite


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