[gedit/wip/search] Add has_close_button prop to the tag



commit 886c5e469bf9407c0614c780a3d6d94a7940bf05
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date:   Sat Jul 13 00:46:12 2013 +0200

    Add has_close_button prop to the tag

 gedit/gd-tagged-entry.c |   42 +++++++++++++++++++++++++++++++++++++-----
 gedit/gd-tagged-entry.h |    7 ++++++-
 2 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/gedit/gd-tagged-entry.c b/gedit/gd-tagged-entry.c
index 4447f4f..f679fa3 100644
--- a/gedit/gd-tagged-entry.c
+++ b/gedit/gd-tagged-entry.c
@@ -34,6 +34,7 @@ typedef struct {
   gchar *id;
   gchar *label;
   gchar *style;
+  gboolean has_close_button;
 
   GdkPixbuf *close_pixbuf;
   GtkStateFlags last_button_state;
@@ -418,7 +419,7 @@ gd_tagged_entry_tag_draw (GdTaggedEntryTag *tag,
 
   gtk_style_context_restore (context);
 
-  if (!entry->priv->button_visible)
+  if (!entry->priv->button_visible || !tag->has_close_button)
     goto done;
 
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
@@ -499,7 +500,8 @@ gd_tagged_entry_tag_realize (GdTaggedEntryTag *tag,
 static GdTaggedEntryTag *
 gd_tagged_entry_tag_new (const gchar *id,
                          const gchar *label,
-                         const gchar *style)
+                         const gchar *style,
+                         gboolean     has_close_button)
 {
   GdTaggedEntryTag *tag;
 
@@ -508,6 +510,7 @@ gd_tagged_entry_tag_new (const gchar *id,
   tag->id = g_strdup (id);
   tag->label = g_strdup (label);
   tag->style = g_strdup (style);
+  tag->has_close_button = has_close_button;
   tag->last_button_state = GTK_STATE_FLAG_NORMAL;
 
   return tag;
@@ -953,14 +956,16 @@ gboolean
 gd_tagged_entry_add_tag_styled (GdTaggedEntry *self,
                                 const gchar   *id,
                                 const gchar   *name,
-                                const gchar   *style)
+                                const gchar   *style,
+                                gboolean       has_close_button)
 {
   GdTaggedEntryTag *tag;
 
   if (gd_tagged_entry_find_tag_by_id (self, id) != NULL)
     return FALSE;
 
-  tag = gd_tagged_entry_tag_new (id, name, style);
+  has_close_button = has_close_button != FALSE;
+  tag = gd_tagged_entry_tag_new (id, name, style, has_close_button);
   self->priv->tags = g_list_append (self->priv->tags, tag);
 
   if (gtk_widget_get_mapped (GTK_WIDGET (self)))
@@ -979,7 +984,7 @@ gd_tagged_entry_add_tag (GdTaggedEntry *self,
                          const gchar   *id,
                          const gchar   *name)
 {
-  return gd_tagged_entry_add_tag_styled (self, id, name, "documents-entry-tag");
+  return gd_tagged_entry_add_tag_styled (self, id, name, "documents-entry-tag", TRUE);
 }
 
 gboolean
@@ -1030,6 +1035,33 @@ gd_tagged_entry_set_tag_label (GdTaggedEntry *self,
   return res;
 }
 
+gboolean
+gd_tagged_entry_set_tag_has_close_button (GdTaggedEntry *self,
+                                          const gchar *tag_id,
+                                          gboolean has_close_button)
+{
+  GdTaggedEntryTag *tag;
+  gboolean res = FALSE;
+
+  has_close_button = has_close_button != FALSE;
+  tag = gd_tagged_entry_find_tag_by_id (self, tag_id);
+
+  if (tag != NULL)
+    {
+      res = TRUE;
+
+      if (tag->has_close_button != has_close_button)
+        {
+          tag->has_close_button = has_close_button;
+          g_clear_object (&tag->layout);
+
+          gtk_widget_queue_resize (GTK_WIDGET (self));
+        }
+    }
+
+  return res;
+}
+
 void
 gd_tagged_entry_set_tag_button_visible (GdTaggedEntry *self,
                                         gboolean       visible)
diff --git a/gedit/gd-tagged-entry.h b/gedit/gd-tagged-entry.h
index 73a72a8..e13ac28 100644
--- a/gedit/gd-tagged-entry.h
+++ b/gedit/gd-tagged-entry.h
@@ -77,7 +77,8 @@ gboolean gd_tagged_entry_get_tag_button_visible (GdTaggedEntry *self);
 gboolean gd_tagged_entry_add_tag_styled (GdTaggedEntry *self,
                                          const gchar   *id,
                                          const gchar   *name,
-                                         const gchar   *style);
+                                         const gchar   *style,
+                                         gboolean       has_close_button);
 
 gboolean gd_tagged_entry_add_tag (GdTaggedEntry *entry,
                                   const gchar *id,
@@ -90,6 +91,10 @@ gboolean gd_tagged_entry_set_tag_label (GdTaggedEntry *self,
                                         const gchar *tag_id,
                                         const gchar *label);
 
+gboolean gd_tagged_entry_set_tag_has_close_button (GdTaggedEntry *self,
+                                                   const gchar *tag_id,
+                                                   gboolean has_close_button);
+
 G_END_DECLS
 
 #endif /* __GD_TAGGED_ENTRY_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]