[gimp/wip/Jehan/layers-dockable-refresh: 76/80] app: implement GimpContainerViewInterface's get_selected() for…




commit bbd5629f7e03e0e80af5b6f545834a36c97939ea
Author: Jehan <jehan girinstud io>
Date:   Thu Nov 4 17:47:24 2021 +0100

    app: implement GimpContainerViewInterface's get_selected() for…
    
    … GimpContainerComboBox and add a warning when the implementation is
    missing.
    
    Basically the default get_selected() implementation only works for
    context properties, not for more generic usage of GimpContainerView. The
    new warning will be a lot more informative and will help any future
    cases where we might experience this bug.

 app/widgets/gimpcontainercombobox.c | 36 ++++++++++++++++++++++++++++++++++++
 app/widgets/gimpcontainerview.c     | 11 +++++++++++
 2 files changed, 47 insertions(+)
---
diff --git a/app/widgets/gimpcontainercombobox.c b/app/widgets/gimpcontainercombobox.c
index df12453860..f04e31d092 100644
--- a/app/widgets/gimpcontainercombobox.c
+++ b/app/widgets/gimpcontainercombobox.c
@@ -79,6 +79,9 @@ static gboolean  gimp_container_combo_box_select_items(GimpContainerView      *v
                                                        GList                  *paths);
 static void     gimp_container_combo_box_clear_items  (GimpContainerView      *view);
 static void    gimp_container_combo_box_set_view_size (GimpContainerView      *view);
+static gint    gimp_container_combo_box_get_selected  (GimpContainerView      *view,
+                                                       GList                 **items,
+                                                       GList                 **items_data);
 
 static void     gimp_container_combo_box_changed      (GtkComboBox            *combo_box,
                                                        GimpContainerView      *view);
@@ -129,6 +132,7 @@ gimp_container_combo_box_view_iface_init (GimpContainerViewInterface *iface)
   iface->select_items  = gimp_container_combo_box_select_items;
   iface->clear_items   = gimp_container_combo_box_clear_items;
   iface->set_view_size = gimp_container_combo_box_set_view_size;
+  iface->get_selected  = gimp_container_combo_box_get_selected;
 
   iface->insert_data_free = (GDestroyNotify) gtk_tree_iter_free;
 }
@@ -426,6 +430,38 @@ gimp_container_combo_box_set_view_size (GimpContainerView *view)
     gimp_container_tree_store_set_view_size (GIMP_CONTAINER_TREE_STORE (model));
 }
 
+static gint
+gimp_container_combo_box_get_selected (GimpContainerView  *view,
+                                       GList             **items,
+                                       GList             **items_data)
+{
+  GtkComboBox      *combo_box = GTK_COMBO_BOX (view);
+  GimpViewRenderer *renderer  = NULL;
+  GtkTreeIter       iter;
+  gint              selected  = 0;
+
+  if (gtk_combo_box_get_active_iter (combo_box, &iter))
+    gtk_tree_model_get (gtk_combo_box_get_model (combo_box), &iter,
+                        GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
+                        -1);
+
+  if (items)
+    {
+      if (renderer != NULL && renderer->viewable != NULL)
+        {
+          *items   = g_list_prepend (NULL, renderer->viewable);
+          selected = 1;
+        }
+      else
+        {
+          *items = NULL;
+        }
+    }
+  g_clear_object (&renderer);
+
+  return selected;
+}
+
 static void
 gimp_container_combo_box_changed (GtkComboBox       *combo,
                                   GimpContainerView *view)
diff --git a/app/widgets/gimpcontainerview.c b/app/widgets/gimpcontainerview.c
index 058910ddb0..64e61e7b48 100644
--- a/app/widgets/gimpcontainerview.c
+++ b/app/widgets/gimpcontainerview.c
@@ -1067,6 +1067,17 @@ gimp_container_view_real_get_selected (GimpContainerView  *view,
     return 0;
 
   children_type = gimp_container_get_children_type (private->container);
+  if (gimp_context_type_to_property (children_type) == -1)
+    {
+      /* If you experience this warning, it means you should implement
+       * your own definition for get_selected() because the default one
+       * won't work for you (only made for context properties).
+       */
+      g_warning ("%s: TODO: implement GimpContainerViewInterface's get_selected() for type '%s'.\n",
+                 G_STRFUNC, g_type_name (G_OBJECT_TYPE (view)));
+      return 0;
+    }
+
   object = gimp_context_get_by_type (private->context,
                                      children_type);
 


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