[gnome-builder] tabs: only show close-button for foreground tab.



commit ebcf6887869c559dc483aa1a051c1ffb0ca2d0ae
Author: Christian Hergert <christian hergert me>
Date:   Mon Sep 8 21:54:33 2014 -0700

    tabs: only show close-button for foreground tab.

 src/gnome-builder.mk            |    1 +
 src/tabs/gb-notebook.c          |   54 +++++++++++++++++++++++++++++++--------
 src/tabs/gb-tab-label-private.h |   32 +++++++++++++++++++++++
 src/tabs/gb-tab-label.c         |    9 ++++++
 4 files changed, 85 insertions(+), 11 deletions(-)
---
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 959f933..d4f84a9 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -60,6 +60,7 @@ gnome_builder_SOURCES = \
        src/tabs/gb-notebook.h \
        src/tabs/gb-tab-label.c \
        src/tabs/gb-tab-label.h \
+       src/tabs/gb-tab-label-private.h \
        src/tabs/gb-tab.c \
        src/tabs/gb-tab.h \
        src/theatrics/gb-box-theatric.c \
diff --git a/src/tabs/gb-notebook.c b/src/tabs/gb-notebook.c
index 54cd46d..52a732e 100644
--- a/src/tabs/gb-notebook.c
+++ b/src/tabs/gb-notebook.c
@@ -23,6 +23,7 @@
 #include "gb-log.h"
 #include "gb-notebook.h"
 #include "gb-tab-label.h"
+#include "gb-tab-label-private.h"
 #include "gb-widget.h"
 
 G_DEFINE_TYPE (GbNotebook, gb_notebook, GTK_TYPE_NOTEBOOK)
@@ -84,27 +85,27 @@ gb_notebook_add_tab (GbNotebook *notebook,
    g_return_if_fail (GB_IS_NOTEBOOK (notebook));
    g_return_if_fail (GB_IS_TAB (tab));
 
-   gtk_container_add_with_properties (GTK_CONTAINER (notebook),
-                                      GTK_WIDGET (tab),
-                                      "detachable", TRUE,
-                                      "reorderable", TRUE,
-                                      "tab-expand", TRUE,
-                                      "tab-fill", TRUE,
-                                      NULL);
-
    tab_label = g_object_new (GB_TYPE_TAB_LABEL,
                              "tab", tab,
                              "visible", TRUE,
                              NULL);
    g_object_set_data (G_OBJECT (tab_label), "GB_TAB", tab);
-   gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook),
-                               GTK_WIDGET (tab),
-                               GTK_WIDGET (tab_label));
    g_signal_connect_object (tab_label,
                             "close-clicked",
                             G_CALLBACK (gb_notebook_tab_label_close_clicked),
                             notebook,
                             G_CONNECT_SWAPPED);
+
+   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+                             GTK_WIDGET (tab),
+                             GTK_WIDGET (tab_label));
+
+   gtk_container_child_set (GTK_CONTAINER (notebook), GTK_WIDGET (tab),
+                            "detachable", TRUE,
+                            "reorderable", TRUE,
+                            "tab-expand", TRUE,
+                            "tab-fill", TRUE,
+                            NULL);
 }
 
 static void
@@ -131,11 +132,42 @@ gb_notebook_drag_begin (GtkWidget      *widget,
 }
 
 static void
+gb_notebook_switch_page (GtkNotebook *notebook,
+                         GtkWidget   *page,
+                         guint        page_num)
+{
+  GtkWidget *tab_label;
+  GtkWidget *prev_page;
+  gint prev_page_num;
+
+  g_return_if_fail (GB_IS_NOTEBOOK (notebook));
+
+  prev_page_num = gtk_notebook_get_current_page (notebook);
+
+  if (prev_page_num != -1)
+    {
+      prev_page = gtk_notebook_get_nth_page (notebook, prev_page_num);
+      tab_label = gtk_notebook_get_tab_label (notebook, prev_page);
+      _gb_tab_label_set_show_close_button (GB_TAB_LABEL (tab_label), FALSE);
+    }
+
+  GTK_NOTEBOOK_CLASS (gb_notebook_parent_class)->switch_page (notebook,
+                                                              page,
+                                                              page_num);
+
+  tab_label = gtk_notebook_get_tab_label (notebook, page);
+  _gb_tab_label_set_show_close_button (GB_TAB_LABEL (tab_label), TRUE);
+}
+
+static void
 gb_notebook_class_init (GbNotebookClass *klass)
 {
    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+   GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
 
    widget_class->drag_begin = gb_notebook_drag_begin;
+
+   notebook_class->switch_page = gb_notebook_switch_page;
 }
 
 static void
diff --git a/src/tabs/gb-tab-label-private.h b/src/tabs/gb-tab-label-private.h
new file mode 100644
index 0000000..9e2f388
--- /dev/null
+++ b/src/tabs/gb-tab-label-private.h
@@ -0,0 +1,32 @@
+/* gb-tab-label-private.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_TAB_LABEL_PRIVATE_H
+#define GB_TAB_LABEL_PRIVATE_H
+
+#include "gb-tab-label.h"
+
+G_BEGIN_DECLS
+
+void _gb_tab_label_set_show_close_button (GbTabLabel *tab_label,
+                                          gboolean    show_close_button)
+     G_GNUC_INTERNAL;
+
+G_END_DECLS
+
+#endif /* GB_TAB_LABEL_PRIVATE_H */
diff --git a/src/tabs/gb-tab-label.c b/src/tabs/gb-tab-label.c
index f3a36f6..2b9526c 100644
--- a/src/tabs/gb-tab-label.c
+++ b/src/tabs/gb-tab-label.c
@@ -60,6 +60,15 @@ gb_tab_label_new (GbTab *tab)
   return g_object_new (GB_TYPE_TAB_LABEL, "tab", tab, NULL);
 }
 
+void
+_gb_tab_label_set_show_close_button (GbTabLabel *tab_label,
+                                     gboolean    show_close_button)
+{
+  g_return_if_fail (GB_IS_TAB_LABEL (tab_label));
+
+  gtk_widget_set_visible (tab_label->priv->close_button, show_close_button);
+}
+
 GbTab *
 gb_tab_label_get_tab (GbTabLabel *label)
 {


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