[tepl] TabGroup: add append_tab()



commit 0461192b247fd5a4902295fd5810300f99e6496f
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 22 21:58:30 2017 +0200

    TabGroup: add append_tab()

 docs/reference/tepl-3.0-sections.txt |    1 +
 tepl/tepl-application-window.c       |   13 +++++++++++++
 tepl/tepl-notebook.c                 |   14 ++++++++++++--
 tepl/tepl-tab-group.c                |   33 +++++++++++++++++++++++++++++++++
 tepl/tepl-tab-group.h                |   24 +++++++++++++++++-------
 5 files changed, 76 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 5af5346..e917246 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -441,6 +441,7 @@ tepl_tab_group_get_active_tab
 tepl_tab_group_set_active_tab
 tepl_tab_group_get_active_view
 tepl_tab_group_get_active_buffer
+tepl_tab_group_append_tab
 <SUBSECTION Standard>
 TEPL_IS_TAB_GROUP
 TEPL_TAB_GROUP
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 5646bae..cea6b05 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -237,6 +237,18 @@ tepl_application_window_set_active_tab (TeplTabGroup *tab_group,
 }
 
 static void
+tepl_application_window_append_tab (TeplTabGroup *tab_group,
+                                   TeplTab      *tab)
+{
+       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (tab_group);
+
+       if (tepl_window->priv->tab_group != NULL)
+       {
+               tepl_tab_group_append_tab (tepl_window->priv->tab_group, tab, FALSE);
+       }
+}
+
+static void
 tepl_tab_group_interface_init (gpointer g_iface,
                               gpointer iface_data)
 {
@@ -245,6 +257,7 @@ tepl_tab_group_interface_init (gpointer g_iface,
        interface->get_tabs = tepl_application_window_get_tabs;
        interface->get_active_tab = tepl_application_window_get_active_tab;
        interface->set_active_tab = tepl_application_window_set_active_tab;
+       interface->append_tab = tepl_application_window_append_tab;
 }
 
 static void
diff --git a/tepl/tepl-notebook.c b/tepl/tepl-notebook.c
index 6f02966..dfb9ae9 100644
--- a/tepl/tepl-notebook.c
+++ b/tepl/tepl-notebook.c
@@ -228,9 +228,8 @@ static void
 tepl_notebook_set_active_tab (TeplTabGroup *tab_group,
                              TeplTab      *tab)
 {
-       gint page_num;
-
        GtkNotebook *notebook = GTK_NOTEBOOK (tab_group);
+       gint page_num;
 
        page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (tab));
        g_return_if_fail (page_num != -1);
@@ -239,6 +238,16 @@ tepl_notebook_set_active_tab (TeplTabGroup *tab_group,
 }
 
 static void
+tepl_notebook_append_tab (TeplTabGroup *tab_group,
+                         TeplTab      *tab)
+{
+       GtkNotebook *notebook = GTK_NOTEBOOK (tab_group);
+
+       /* TODO implement a TeplTabLabel widget. */
+       gtk_notebook_append_page (notebook, GTK_WIDGET (tab), NULL);
+}
+
+static void
 tepl_tab_group_interface_init (gpointer g_iface,
                               gpointer iface_data)
 {
@@ -247,6 +256,7 @@ tepl_tab_group_interface_init (gpointer g_iface,
        interface->get_tabs = tepl_notebook_get_tabs;
        interface->get_active_tab = tepl_notebook_get_active_tab;
        interface->set_active_tab = tepl_notebook_set_active_tab;
+       interface->append_tab = tepl_notebook_append_tab;
 }
 
 static void
diff --git a/tepl/tepl-tab-group.c b/tepl/tepl-tab-group.c
index 84cd645..fac0e53 100644
--- a/tepl/tepl-tab-group.c
+++ b/tepl/tepl-tab-group.c
@@ -56,11 +56,18 @@ tepl_tab_group_set_active_tab_default (TeplTabGroup *tab_group,
 }
 
 static void
+tepl_tab_group_append_tab_default (TeplTabGroup *tab_group,
+                                  TeplTab      *tab)
+{
+}
+
+static void
 tepl_tab_group_default_init (TeplTabGroupInterface *interface)
 {
        interface->get_tabs = tepl_tab_group_get_tabs_default;
        interface->get_active_tab = tepl_tab_group_get_active_tab_default;
        interface->set_active_tab = tepl_tab_group_set_active_tab_default;
+       interface->append_tab = tepl_tab_group_append_tab_default;
 
        /**
         * TeplTabGroup:active-tab:
@@ -281,3 +288,29 @@ tepl_tab_group_get_active_buffer (TeplTabGroup *tab_group)
 
        return active_tab != NULL ? tepl_tab_get_buffer (active_tab) : NULL;
 }
+
+/**
+ * tepl_tab_group_append_tab:
+ * @tab_group: a #TeplTabGroup.
+ * @tab: a #TeplTab.
+ * @jump_to: whether to set @tab as the active tab after appending it.
+ *
+ * Appends @tab to @tab_group.
+ *
+ * Since: 3.0
+ */
+void
+tepl_tab_group_append_tab (TeplTabGroup *tab_group,
+                          TeplTab      *tab,
+                          gboolean      jump_to)
+{
+       g_return_if_fail (TEPL_IS_TAB_GROUP (tab_group));
+       g_return_if_fail (TEPL_IS_TAB (tab));
+
+       TEPL_TAB_GROUP_GET_INTERFACE (tab_group)->append_tab (tab_group, tab);
+
+       if (jump_to)
+       {
+               tepl_tab_group_set_active_tab (tab_group, tab);
+       }
+}
diff --git a/tepl/tepl-tab-group.h b/tepl/tepl-tab-group.h
index c97ee5d..168fadc 100644
--- a/tepl/tepl-tab-group.h
+++ b/tepl/tepl-tab-group.h
@@ -48,6 +48,9 @@ typedef struct _TeplTabGroupInterface TeplTabGroupInterface;
  *   By default, %NULL is returned.
  * @set_active_tab: Virtual function pointer for
  *   tepl_tab_group_set_active_tab(). Does nothing by default.
+ * @append_tab: Virtual function pointer for tepl_tab_group_append_tab(). Does
+ *   nothing by default. The @jump_to parameter is already implemented with
+ *   tepl_tab_group_set_active_tab().
  *
  * The virtual function table for #TeplTabGroup. When implementing one of the
  * vfunc, you can assume that the pre-conditions are already checked (the
@@ -65,25 +68,32 @@ struct _TeplTabGroupInterface
 
        void            (*set_active_tab)       (TeplTabGroup *tab_group,
                                                 TeplTab      *tab);
+
+       void            (*append_tab)           (TeplTabGroup *tab_group,
+                                                TeplTab      *tab);
 };
 
-GType          tepl_tab_group_get_type         (void);
+GType          tepl_tab_group_get_type                 (void);
 
-GList *                tepl_tab_group_get_tabs         (TeplTabGroup *tab_group);
+GList *                tepl_tab_group_get_tabs                 (TeplTabGroup *tab_group);
 
 GList *                tepl_tab_group_get_views                (TeplTabGroup *tab_group);
 
-GList *                tepl_tab_group_get_buffers      (TeplTabGroup *tab_group);
+GList *                tepl_tab_group_get_buffers              (TeplTabGroup *tab_group);
 
-TeplTab *      tepl_tab_group_get_active_tab   (TeplTabGroup *tab_group);
+TeplTab *      tepl_tab_group_get_active_tab           (TeplTabGroup *tab_group);
 
-void           tepl_tab_group_set_active_tab   (TeplTabGroup *tab_group,
-                                                TeplTab      *tab);
+void           tepl_tab_group_set_active_tab           (TeplTabGroup *tab_group,
+                                                        TeplTab      *tab);
 
-TeplView *     tepl_tab_group_get_active_view  (TeplTabGroup *tab_group);
+TeplView *     tepl_tab_group_get_active_view          (TeplTabGroup *tab_group);
 
 TeplBuffer *   tepl_tab_group_get_active_buffer        (TeplTabGroup *tab_group);
 
+void           tepl_tab_group_append_tab               (TeplTabGroup *tab_group,
+                                                        TeplTab      *tab,
+                                                        gboolean      jump_to);
+
 G_END_DECLS
 
 #endif /* TEPL_TAB_GROUP_H */


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