[gimp] app: implement a select_items() method for GimpContainerComboBox…
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: implement a select_items() method for GimpContainerComboBox…
- Date: Thu, 23 Dec 2021 13:03:28 +0000 (UTC)
commit 1a3dbe2099f63b10f9feca1fa88cd018cdcebdd7
Author: Jehan <jehan girinstud io>
Date: Thu Jun 10 09:54:22 2021 +0200
app: implement a select_items() method for GimpContainerComboBox…
… and use gimp_container_view_select_items() when the context changes.
Even though some types of containers still expect only a single
selected content, we should slowly move to multiple item code. The
reason is to avoid 2 code paths which makes the code more complicated
and bug-prone. When all child classes of GimpContainerView will have a
valid select_items() implementation, we can work on getting rid of the
select_item() in favor of the multi-item one.
app/widgets/gimpcontainercombobox.c | 38 +++++++++++++++++++++++++++++++++++++
app/widgets/gimpcontainerview.c | 9 ++++++++-
2 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/app/widgets/gimpcontainercombobox.c b/app/widgets/gimpcontainercombobox.c
index d559890b12..16b1ab9fe3 100644
--- a/app/widgets/gimpcontainercombobox.c
+++ b/app/widgets/gimpcontainercombobox.c
@@ -77,6 +77,9 @@ static void gimp_container_combo_box_rename_item (GimpContainerView *v
static gboolean gimp_container_combo_box_select_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data);
+static gboolean gimp_container_combo_box_select_items(GimpContainerView *view,
+ GList *viewables,
+ GList *paths);
static void gimp_container_combo_box_clear_items (GimpContainerView *view);
static void gimp_container_combo_box_set_view_size (GimpContainerView *view);
@@ -127,6 +130,7 @@ gimp_container_combo_box_view_iface_init (GimpContainerViewInterface *iface)
iface->reorder_item = gimp_container_combo_box_reorder_item;
iface->rename_item = gimp_container_combo_box_rename_item;
iface->select_item = gimp_container_combo_box_select_item;
+ 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;
@@ -380,6 +384,40 @@ gimp_container_combo_box_select_item (GimpContainerView *view,
return TRUE;
}
+static gboolean
+gimp_container_combo_box_select_items (GimpContainerView *view,
+ GList *viewables,
+ GList *paths)
+{
+ GtkComboBox *combo_box = GTK_COMBO_BOX (view);
+
+ g_return_val_if_fail (GIMP_IS_CONTAINER_VIEW (view), FALSE);
+ /* Only zero or one items may selected in a GimpContainerComboBox. */
+ g_return_val_if_fail (g_list_length (viewables) < 2, FALSE);
+
+ if (gtk_combo_box_get_model (GTK_COMBO_BOX (view)))
+ {
+ g_signal_handlers_block_by_func (combo_box,
+ gimp_container_combo_box_changed,
+ view);
+
+ if (viewables)
+ {
+ gimp_container_view_item_selected (view, viewables->data);
+ }
+ else
+ {
+ gtk_combo_box_set_active (combo_box, -1);
+ }
+
+ g_signal_handlers_unblock_by_func (combo_box,
+ gimp_container_combo_box_changed,
+ view);
+ }
+
+ return TRUE;
+}
+
static void
gimp_container_combo_box_clear_items (GimpContainerView *view)
{
diff --git a/app/widgets/gimpcontainerview.c b/app/widgets/gimpcontainerview.c
index eac2c20020..e6a8441f06 100644
--- a/app/widgets/gimpcontainerview.c
+++ b/app/widgets/gimpcontainerview.c
@@ -1383,8 +1383,15 @@ gimp_container_view_context_changed (GimpContext *context,
GimpViewable *viewable,
GimpContainerView *view)
{
- if (! gimp_container_view_select_item (view, viewable))
+ GList *viewables = NULL;
+
+ if (viewable)
+ viewables = g_list_prepend (viewables, viewable);
+
+ if (! gimp_container_view_select_items (view, viewables))
g_warning ("%s: select_item() failed (should not happen)", G_STRFUNC);
+
+ g_list_free (viewables);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]