Skip to content

Commit

Permalink
Add boolean return value for gtk_text_tag_table_add()
Browse files Browse the repository at this point in the history
The user doesn't need to check the return value, because if FALSE is
returned it is a programmer error. But it permits a nicer behavior for
gtk_text_buffer_create_tag() in case of failure.

https://bugzilla.gnome.org/show_bug.cgi?id=614717
  • Loading branch information
Sébastien Wilmet committed May 12, 2014
1 parent a06fc47 commit 68ad33c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions gtk/gtktexttagtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,27 @@ gtk_text_tag_table_buildable_add_child (GtkBuildable *buildable,
*
* @tag must not be in a tag table already, and may not have
* the same name as an already-added tag.
*
* Returns: %TRUE on success.
**/
void
gboolean
gtk_text_tag_table_add (GtkTextTagTable *table,
GtkTextTag *tag)
{
GtkTextTagTablePrivate *priv;
guint size;

g_return_if_fail (GTK_IS_TEXT_TAG_TABLE (table));
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
g_return_if_fail (tag->priv->table == NULL);
g_return_val_if_fail (GTK_IS_TEXT_TAG_TABLE (table), FALSE);
g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
g_return_val_if_fail (tag->priv->table == NULL, FALSE);

priv = table->priv;

if (tag->priv->name && g_hash_table_lookup (priv->hash, tag->priv->name))
{
g_warning ("A tag named '%s' is already in the tag table.",
tag->priv->name);
return;
return FALSE;
}

g_object_ref (tag);
Expand All @@ -277,6 +279,7 @@ gtk_text_tag_table_add (GtkTextTagTable *table,
tag->priv->priority = size - 1;

g_signal_emit (table, signals[TAG_ADDED], 0, tag);
return TRUE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gtk/gtktexttagtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ GType gtk_text_tag_table_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkTextTagTable *gtk_text_tag_table_new (void);
GDK_AVAILABLE_IN_ALL
void gtk_text_tag_table_add (GtkTextTagTable *table,
gboolean gtk_text_tag_table_add (GtkTextTagTable *table,
GtkTextTag *tag);
GDK_AVAILABLE_IN_ALL
void gtk_text_tag_table_remove (GtkTextTagTable *table,
Expand Down

0 comments on commit 68ad33c

Please sign in to comment.