[tepl] TabLabel: add close button



commit 61082915fb4ad1fbdf455342fa91552208ae8551
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Aug 6 11:17:44 2017 +0200

    TabLabel: add close button

 tepl/tepl-tab-label.c |   36 +++++++++++++++++++++++++++++++++++-
 tepl/tepl-utils.c     |   17 +++++++++++++++++
 tepl/tepl-utils.h     |    6 +++++-
 3 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/tepl/tepl-tab-label.c b/tepl/tepl-tab-label.c
index 2bc681e..5e6f0a5 100644
--- a/tepl/tepl-tab-label.c
+++ b/tepl/tepl-tab-label.c
@@ -17,7 +17,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
 #include "tepl-tab-label.h"
+#include <glib/gi18n-lib.h>
 #include "tepl-tab.h"
 #include "tepl-buffer.h"
 #include "tepl-signal-group.h"
@@ -29,6 +31,11 @@
  * @Title: TeplTabLabel
  *
  * #TeplTabLabel is the label/title of a #TeplTab, suitable for #GtkNotebook.
+ *
+ * A #TeplTabLabel contains:
+ * - a #GtkLabel with the #TeplBuffer:tepl-short-title.
+ * - a close button, when clicked the #TeplTab #TeplTab::close-request signal is
+ *   emitted.
  */
 
 struct _TeplTabLabelPrivate
@@ -210,16 +217,43 @@ tepl_tab_label_class_init (TeplTabLabelClass *klass)
 }
 
 static void
+close_button_clicked_cb (GtkButton    *close_button,
+                        TeplTabLabel *tab_label)
+{
+       if (tab_label->priv->tab != NULL)
+       {
+               g_signal_emit_by_name (tab_label->priv->tab, "close-request");
+       }
+}
+
+static void
 tepl_tab_label_init (TeplTabLabel *tab_label)
 {
+       GtkWidget *close_button;
+
        tab_label->priv = tepl_tab_label_get_instance_private (tab_label);
 
+       /* Label */
+
        tab_label->priv->label = GTK_LABEL (gtk_label_new (NULL));
-       gtk_widget_show (GTK_WIDGET (tab_label->priv->label));
        gtk_widget_set_vexpand (GTK_WIDGET (tab_label->priv->label), TRUE);
 
+       gtk_widget_show (GTK_WIDGET (tab_label->priv->label));
        gtk_container_add (GTK_CONTAINER (tab_label),
                           GTK_WIDGET (tab_label->priv->label));
+
+       /* Close button */
+
+       close_button = _tepl_utils_create_close_button ();
+       gtk_widget_set_tooltip_text (close_button, _("Close file"));
+
+       g_signal_connect (close_button,
+                         "clicked",
+                         G_CALLBACK (close_button_clicked_cb),
+                         tab_label);
+
+       gtk_widget_show (close_button);
+       gtk_container_add (GTK_CONTAINER (tab_label), close_button);
 }
 
 /**
diff --git a/tepl/tepl-utils.c b/tepl/tepl-utils.c
index be6ce77..ce0cdc9 100644
--- a/tepl/tepl-utils.c
+++ b/tepl/tepl-utils.c
@@ -368,3 +368,20 @@ _tepl_utils_get_fallback_basename_for_display (GFile *location)
 
        return basename;
 }
+
+GtkWidget *
+_tepl_utils_create_close_button (void)
+{
+       GtkWidget *close_button;
+       GtkStyleContext *style_context;
+
+       close_button = gtk_button_new_from_icon_name ("window-close-symbolic",
+                                                     GTK_ICON_SIZE_BUTTON);
+       gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+       gtk_widget_set_focus_on_click (close_button, FALSE);
+
+       style_context = gtk_widget_get_style_context (close_button);
+       gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_FLAT);
+
+       return close_button;
+}
diff --git a/tepl/tepl-utils.h b/tepl/tepl-utils.h
index c4a7684..98c4085 100644
--- a/tepl/tepl-utils.h
+++ b/tepl/tepl-utils.h
@@ -24,7 +24,7 @@
 #error "Only <tepl/tepl.h> can be included directly."
 #endif
 
-#include <gio/gio.h>
+#include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
@@ -49,6 +49,10 @@ gboolean     _tepl_utils_decode_uri                          (const gchar  *uri,
 G_GNUC_INTERNAL
 gchar *                _tepl_utils_get_fallback_basename_for_display   (GFile *location);
 
+/* Widget utilities */
+
+GtkWidget *    _tepl_utils_create_close_button                 (void);
+
 G_END_DECLS
 
 #endif /* TEPL_UTILS_H */


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