[tepl/wip/app-window-get-tab-group] ApplicationWindow: do not implement TabGroup iface, add get_tab_group()



commit 881cbf311776dd900094b7ce8b2f9e3ba1173837
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Jul 11 12:48:40 2017 +0200

    ApplicationWindow: do not implement TabGroup iface, add get_tab_group()
    
    I initially implemented the TeplTabGroup interface in
    TeplApplicationWindow to avoid one more get() call. But I plan to extend
    the TeplTabGroup interface, e.g. by adding properties or signals. So
    implementing the interface will require more code, and in
    TeplApplicationWindow this was just boilerplate. I think it's not a big
    problem to have several chained get() calls.
    
    So to implement e.g. a GAction that needs the active buffer, the code
    will look like:
    
    tepl_window = tepl_application_window_get_from_gtk_application_window (gtk_window);
    tab_group = tepl_application_window_get_tab_group (tepl_window);
    if (tab_group == NULL)
    {
        return;
    }
    active_buffer = tepl_tab_group_get_active_buffer (tab_group);
    if (active_buffer == NULL)
    {
        return;
    }
    
    To reduce the code, tepl_tab_group_get_active_buffer() could accept NULL
    as its self argument, to remove one == NULL check.
    
    Mmh maybe this commit was not a great idea after all.

 tepl/tepl-application-window.c |   68 ++++++++++------------------------------
 tepl/tepl-application-window.h |    2 +
 2 files changed, 19 insertions(+), 51 deletions(-)
---
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 763dced..31cfa40 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -35,9 +35,6 @@
  *
  * #TeplApplicationWindow extends the #GtkApplicationWindow class.
  *
- * An application needs to call tepl_application_window_set_tab_group() to
- * benefit from the #TeplTabGroup interface implemented by this class.
- *
  * Note that #TeplApplicationWindow extends the #GtkApplicationWindow class but
  * without subclassing it, because several libraries might want to extend
  * #GtkApplicationWindow and an application needs to be able to use all those
@@ -65,15 +62,7 @@ enum
 
 static GParamSpec *properties[N_PROPERTIES];
 
-static void tepl_tab_group_interface_init (gpointer g_iface,
-                                          gpointer iface_data);
-
-G_DEFINE_TYPE_WITH_CODE (TeplApplicationWindow,
-                        tepl_application_window,
-                        G_TYPE_OBJECT,
-                        G_ADD_PRIVATE (TeplApplicationWindow)
-                        G_IMPLEMENT_INTERFACE (TEPL_TYPE_TAB_GROUP,
-                                               tepl_tab_group_interface_init))
+G_DEFINE_TYPE_WITH_PRIVATE (TeplApplicationWindow, tepl_application_window, G_TYPE_OBJECT)
 
 static void
 tepl_application_window_get_property (GObject    *object,
@@ -179,42 +168,6 @@ tepl_application_window_class_init (TeplApplicationWindowClass *klass)
        g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
-static GList *
-tepl_application_window_get_tabs (TeplTabGroup *tab_group)
-{
-       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (tab_group);
-
-       if (tepl_window->priv->tab_group == NULL)
-       {
-               return NULL;
-       }
-
-       return tepl_tab_group_get_tabs (tepl_window->priv->tab_group);
-}
-
-static TeplTab *
-tepl_application_window_get_active_tab (TeplTabGroup *tab_group)
-{
-       TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (tab_group);
-
-       if (tepl_window->priv->tab_group == NULL)
-       {
-               return NULL;
-       }
-
-       return tepl_tab_group_get_active_tab (tepl_window->priv->tab_group);
-}
-
-static void
-tepl_tab_group_interface_init (gpointer g_iface,
-                              gpointer iface_data)
-{
-       TeplTabGroupInterface *interface = g_iface;
-
-       interface->get_tabs = tepl_application_window_get_tabs;
-       interface->get_active_tab = tepl_application_window_get_active_tab;
-}
-
 static void
 tepl_application_window_init (TeplApplicationWindow *tepl_window)
 {
@@ -272,6 +225,22 @@ tepl_application_window_get_application_window (TeplApplicationWindow *tepl_wind
 }
 
 /**
+ * tepl_application_window_get_tab_group:
+ * @tepl_window: a #TeplApplicationWindow.
+ *
+ * Returns: (transfer none) (nullable): the #TeplTabGroup of @tepl_window, or
+ * %NULL if none was set.
+ * Since: 3.0
+ */
+TeplTabGroup *
+tepl_application_window_get_tab_group (TeplApplicationWindow *tepl_window)
+{
+       g_return_val_if_fail (TEPL_IS_APPLICATION_WINDOW (tepl_window), NULL);
+
+       return tepl_window->priv->tab_group;
+}
+
+/**
  * tepl_application_window_set_tab_group:
  * @tepl_window: a #TeplApplicationWindow.
  * @tab_group: a #TeplTabGroup.
@@ -280,9 +249,6 @@ tepl_application_window_get_application_window (TeplApplicationWindow *tepl_wind
  * once, it is not possible to change the #TeplTabGroup afterwards (this
  * restriction may be lifted in the future if there is a compelling use-case).
  *
- * #TeplApplicationWindow implements the #TeplTabGroup interface by delegating
- * the requests to @tab_group.
- *
  * Since: 3.0
  */
 void
diff --git a/tepl/tepl-application-window.h b/tepl/tepl-application-window.h
index 277e78d..475977f 100644
--- a/tepl/tepl-application-window.h
+++ b/tepl/tepl-application-window.h
@@ -59,6 +59,8 @@ TeplApplicationWindow *       tepl_application_window_get_from_gtk_application_window
 
 GtkApplicationWindow * tepl_application_window_get_application_window          (TeplApplicationWindow 
*tepl_window);
 
+TeplTabGroup *         tepl_application_window_get_tab_group                   (TeplApplicationWindow 
*tepl_window);
+
 void                   tepl_application_window_set_tab_group                   (TeplApplicationWindow 
*tepl_window,
                                                                                 TeplTabGroup          
*tab_group);
 


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