mirror of https://github.com/GNOME/gimp.git
Move get_item_by_name() from GimpItemStack to GimpItemTree
and turn its code into a simple hash table lookup.
This commit is contained in:
parent
8a7f2e8f51
commit
217d80bb78
|
@ -3226,42 +3226,42 @@ GimpLayer *
|
|||
gimp_image_get_layer_by_name (const GimpImage *image,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpItemStack *stack;
|
||||
GimpItemTree *tree;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
stack = GIMP_ITEM_STACK (gimp_image_get_layers (image));
|
||||
tree = gimp_image_get_layer_tree (image);
|
||||
|
||||
return GIMP_LAYER (gimp_item_stack_get_item_by_name (stack, name));
|
||||
return GIMP_LAYER (gimp_item_tree_get_item_by_name (tree, name));
|
||||
}
|
||||
|
||||
GimpChannel *
|
||||
gimp_image_get_channel_by_name (const GimpImage *image,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpItemStack *stack;
|
||||
GimpItemTree *tree;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
stack = GIMP_ITEM_STACK (gimp_image_get_channels (image));
|
||||
tree = gimp_image_get_channel_tree (image);
|
||||
|
||||
return GIMP_CHANNEL (gimp_item_stack_get_item_by_name (stack, name));
|
||||
return GIMP_CHANNEL (gimp_item_tree_get_item_by_name (tree, name));
|
||||
}
|
||||
|
||||
GimpVectors *
|
||||
gimp_image_get_vectors_by_name (const GimpImage *image,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpItemStack *stack;
|
||||
GimpItemTree *tree;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
stack = GIMP_ITEM_STACK (gimp_image_get_vectors (image));
|
||||
tree = gimp_image_get_vectors_tree (image);
|
||||
|
||||
return GIMP_VECTORS (gimp_item_stack_get_item_by_name (stack, name));
|
||||
return GIMP_VECTORS (gimp_item_tree_get_item_by_name (tree, name));
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
|
@ -233,37 +233,6 @@ gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
GimpItem *
|
||||
gimp_item_stack_get_item_by_name (GimpItemStack *stack,
|
||||
const gchar *name)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
|
||||
|
||||
for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
|
||||
{
|
||||
GimpItem *item = list->data;
|
||||
GimpContainer *children;
|
||||
|
||||
if (! strcmp (gimp_object_get_name (item), name))
|
||||
return item;
|
||||
|
||||
children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
|
||||
|
||||
if (children)
|
||||
{
|
||||
item = gimp_item_stack_get_item_by_name (GIMP_ITEM_STACK (children),
|
||||
name);
|
||||
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GimpItem *
|
||||
gimp_item_stack_get_parent_by_path (GimpItemStack *stack,
|
||||
GList *path,
|
||||
|
|
|
@ -53,8 +53,6 @@ GList * gimp_item_stack_get_item_iter (GimpItemStack *stack);
|
|||
GList * gimp_item_stack_get_item_list (GimpItemStack *stack);
|
||||
GimpItem * gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
|
||||
GimpTattoo tattoo);
|
||||
GimpItem * gimp_item_stack_get_item_by_name (GimpItemStack *stack,
|
||||
const gchar *name);
|
||||
GimpItem * gimp_item_stack_get_parent_by_path (GimpItemStack *stack,
|
||||
GList *path,
|
||||
gint *index);
|
||||
|
|
|
@ -313,6 +313,17 @@ gimp_item_tree_set_active_item (GimpItemTree *tree,
|
|||
}
|
||||
}
|
||||
|
||||
GimpItem *
|
||||
gimp_item_tree_get_item_by_name (GimpItemTree *tree,
|
||||
const gchar *name)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_ITEM_TREE (tree), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
return g_hash_table_lookup (GIMP_ITEM_TREE_GET_PRIVATE (tree)->name_hash,
|
||||
name);
|
||||
}
|
||||
|
||||
GimpItem *
|
||||
gimp_item_tree_get_insert_pos (GimpItemTree *tree,
|
||||
GimpItem *parent,
|
||||
|
|
|
@ -47,39 +47,42 @@ struct _GimpItemTreeClass
|
|||
};
|
||||
|
||||
|
||||
GType gimp_item_tree_get_type (void) G_GNUC_CONST;
|
||||
GimpItemTree * gimp_item_tree_new (GimpImage *image,
|
||||
GType container_type,
|
||||
GType item_type);
|
||||
GType gimp_item_tree_get_type (void) G_GNUC_CONST;
|
||||
GimpItemTree * gimp_item_tree_new (GimpImage *image,
|
||||
GType container_type,
|
||||
GType item_type);
|
||||
|
||||
GimpItem * gimp_item_tree_get_active_item (GimpItemTree *tree);
|
||||
void gimp_item_tree_set_active_item (GimpItemTree *tree,
|
||||
GimpItem *item);
|
||||
GimpItem * gimp_item_tree_get_active_item (GimpItemTree *tree);
|
||||
void gimp_item_tree_set_active_item (GimpItemTree *tree,
|
||||
GimpItem *item);
|
||||
|
||||
GimpItem * gimp_item_tree_get_insert_pos (GimpItemTree *tree,
|
||||
GimpItem *parent,
|
||||
gint *position);
|
||||
GimpItem * gimp_item_tree_get_item_by_name (GimpItemTree *tree,
|
||||
const gchar *name);
|
||||
|
||||
void gimp_item_tree_add_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
GimpItem *parent,
|
||||
gint position);
|
||||
GimpItem * gimp_item_tree_remove_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
GimpItem *new_active);
|
||||
GimpItem * gimp_item_tree_get_insert_pos (GimpItemTree *tree,
|
||||
GimpItem *parent,
|
||||
gint *position);
|
||||
|
||||
gboolean gimp_item_tree_reorder_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
GimpItem *new_parent,
|
||||
gint new_index,
|
||||
gboolean push_undo,
|
||||
const gchar *undo_desc);
|
||||
void gimp_item_tree_add_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
GimpItem *parent,
|
||||
gint position);
|
||||
GimpItem * gimp_item_tree_remove_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
GimpItem *new_active);
|
||||
|
||||
void gimp_item_tree_rename_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
const gchar *new_name,
|
||||
gboolean push_undo,
|
||||
const gchar *undo_desc);
|
||||
gboolean gimp_item_tree_reorder_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
GimpItem *new_parent,
|
||||
gint new_index,
|
||||
gboolean push_undo,
|
||||
const gchar *undo_desc);
|
||||
|
||||
void gimp_item_tree_rename_item (GimpItemTree *tree,
|
||||
GimpItem *item,
|
||||
const gchar *new_name,
|
||||
gboolean push_undo,
|
||||
const gchar *undo_desc);
|
||||
|
||||
|
||||
#endif /* __GIMP_ITEM_TREE_H__ */
|
||||
|
|
Loading…
Reference in New Issue