[gnome-documents] tagged-entry: add a method to change the label of a tag
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] tagged-entry: add a method to change the label of a tag
- Date: Sat, 26 Nov 2011 08:09:13 +0000 (UTC)
commit e146887919be582c2dcbea6026029f7712bb3402
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Nov 26 03:05:56 2011 -0500
tagged-entry: add a method to change the label of a tag
And make add_tag return FALSE if a tag with the same id already exists.
src/lib/gd-tagged-entry.c | 37 ++++++++++++++++++++++++++++++++-----
src/lib/gd-tagged-entry.h | 10 +++++++---
2 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/src/lib/gd-tagged-entry.c b/src/lib/gd-tagged-entry.c
index b059b09..7bfac13 100644
--- a/src/lib/gd-tagged-entry.c
+++ b/src/lib/gd-tagged-entry.c
@@ -313,6 +313,7 @@ gd_tagged_entry_tag_get_relative_allocations (GdTaggedEntryTag *tag,
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_border (context, state, &border);
+ gd_tagged_entry_tag_ensure_layout (tag, entry);
pango_layout_get_pixel_size (tag->layout, &layout_width, &layout_height);
layout_allocation.x += border.left + padding.left;
@@ -873,7 +874,7 @@ gd_tagged_entry_new (void)
return g_object_new (GD_TYPE_TAGGED_ENTRY, NULL);
}
-void
+gboolean
gd_tagged_entry_add_tag (GdTaggedEntry *self,
const gchar *id,
const gchar *name)
@@ -881,10 +882,7 @@ gd_tagged_entry_add_tag (GdTaggedEntry *self,
GdTaggedEntryTag *tag;
if (gd_tagged_entry_find_tag_by_id (self, id) != NULL)
- {
- g_warning ("Tag %s already exists", id);
- return;
- }
+ return FALSE;
tag = gd_tagged_entry_tag_new (id, name);
self->priv->tags = g_list_append (self->priv->tags, tag);
@@ -896,6 +894,8 @@ gd_tagged_entry_add_tag (GdTaggedEntry *self,
}
gtk_widget_queue_resize (GTK_WIDGET (self));
+
+ return TRUE;
}
gboolean
@@ -917,3 +917,30 @@ gd_tagged_entry_remove_tag (GdTaggedEntry *self,
return res;
}
+
+gboolean
+gd_tagged_entry_set_tag_label (GdTaggedEntry *self,
+ const gchar *tag_id,
+ const gchar *label)
+{
+ GdTaggedEntryTag *tag;
+ gboolean res = FALSE;
+
+ tag = gd_tagged_entry_find_tag_by_id (self, tag_id);
+
+ if (tag != NULL)
+ {
+ res = TRUE;
+
+ if (g_strcmp0 (tag->label, label) != 0)
+ {
+ g_free (tag->label);
+ tag->label = g_strdup (label);
+ g_clear_object (&tag->layout);
+
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+ }
+ }
+
+ return res;
+}
diff --git a/src/lib/gd-tagged-entry.h b/src/lib/gd-tagged-entry.h
index 58beadb..f4743bd 100644
--- a/src/lib/gd-tagged-entry.h
+++ b/src/lib/gd-tagged-entry.h
@@ -70,13 +70,17 @@ GType gd_tagged_entry_get_type (void) G_GNUC_CONST;
GdTaggedEntry *gd_tagged_entry_new (void);
-void gd_tagged_entry_add_tag (GdTaggedEntry *entry,
- const gchar *id,
- const gchar *label);
+gboolean gd_tagged_entry_add_tag (GdTaggedEntry *entry,
+ const gchar *id,
+ const gchar *label);
gboolean gd_tagged_entry_remove_tag (GdTaggedEntry *self,
const gchar *id);
+gboolean gd_tagged_entry_set_tag_label (GdTaggedEntry *self,
+ const gchar *tag_id,
+ const gchar *label);
+
G_END_DECLS
#endif /* __GD_TAGGED_ENTRY_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]