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.
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user