[tepl] Implement TeplTabList interface



commit 5568bf5bbf90a2b523ecfac6bd33cff5895cf3b0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 24 07:06:03 2017 +0200

    Implement TeplTabList interface

 docs/reference/tepl-3.0-sections.txt |   18 +++
 docs/reference/tepl-docs.xml.in      |    1 +
 po/POTFILES.in                       |    1 +
 tepl/Makefile.am                     |    2 +
 tepl/tepl-tab-list.c                 |  194 ++++++++++++++++++++++++++++++++++
 tepl/tepl-tab-list.h                 |   76 +++++++++++++
 tepl/tepl-types.h                    |    1 +
 tepl/tepl.h                          |    1 +
 8 files changed, 294 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index ea63224..cb1381e 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -362,6 +362,24 @@ tepl_tab_get_type
 </SECTION>
 
 <SECTION>
+<FILE>tab-list</FILE>
+TeplTabList
+TeplTabListInterface
+tepl_tab_list_get_tabs
+tepl_tab_list_get_views
+tepl_tab_list_get_buffers
+tepl_tab_list_get_active_tab
+tepl_tab_list_get_active_view
+tepl_tab_list_get_active_buffer
+<SUBSECTION Standard>
+TEPL_IS_TAB_LIST
+TEPL_TAB_LIST
+TEPL_TAB_LIST_GET_INTERFACE
+TEPL_TYPE_TAB_LIST
+tepl_tab_list_get_type
+</SECTION>
+
+<SECTION>
 <FILE>utils</FILE>
 tepl_utils_recent_chooser_menu_get_item_uri
 </SECTION>
diff --git a/docs/reference/tepl-docs.xml.in b/docs/reference/tepl-docs.xml.in
index e37d0e8..58f2896 100644
--- a/docs/reference/tepl-docs.xml.in
+++ b/docs/reference/tepl-docs.xml.in
@@ -21,6 +21,7 @@
       <title>Framework</title>
       <xi:include href="xml/application.xml"/>
       <xi:include href="xml/application-window.xml"/>
+      <xi:include href="xml/tab-list.xml"/>
       <xi:include href="xml/tab.xml"/>
       <xi:include href="xml/view.xml"/>
       <xi:include href="xml/buffer.xml"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 88ab969..de15d83 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,5 +21,6 @@ tepl/tepl-menu-item.c
 tepl/tepl-menu-shell.c
 tepl/tepl-metadata-manager.c
 tepl/tepl-tab.c
+tepl/tepl-tab-list.c
 tepl/tepl-utils.c
 tepl/tepl-view.c
diff --git a/tepl/Makefile.am b/tepl/Makefile.am
index a292039..a8d5e85 100644
--- a/tepl/Makefile.am
+++ b/tepl/Makefile.am
@@ -33,6 +33,7 @@ tepl_public_headers =                         \
        tepl-metadata-manager.h                 \
        tepl-types.h                            \
        tepl-tab.h                              \
+       tepl-tab-list.h                         \
        tepl-utils.h                            \
        tepl-view.h
 
@@ -57,6 +58,7 @@ tepl_public_c_files =                         \
        tepl-menu-shell.c                       \
        tepl-metadata-manager.c                 \
        tepl-tab.c                              \
+       tepl-tab-list.c                         \
        tepl-utils.c                            \
        tepl-view.c
 
diff --git a/tepl/tepl-tab-list.c b/tepl/tepl-tab-list.c
new file mode 100644
index 0000000..ddc63f3
--- /dev/null
+++ b/tepl/tepl-tab-list.c
@@ -0,0 +1,194 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tepl-tab-list.h"
+#include "tepl-tab.h"
+
+/**
+ * SECTION:tab-list
+ * @Short_description: Interface for a list of #TeplTab's
+ * @Title: TeplTabList
+ *
+ * The tepl_tab_list_get_tabs() function permits to get the list of #TeplTab's.
+ * The tepl_tab_list_get_active_tab() function permits to get the #TeplTab
+ * currently shown in the #TeplTabList.
+ *
+ * #TeplTabList also contains convenience functions to get #TeplView's and
+ * #TeplBuffer's instead of #TeplTab's.
+ */
+
+G_DEFINE_INTERFACE (TeplTabList, tepl_tab_list, G_TYPE_OBJECT)
+
+static GList *
+tepl_tab_list_get_tabs_default (TeplTabList *tab_list)
+{
+       return NULL;
+}
+
+static TeplTab *
+tepl_tab_list_get_active_tab_default (TeplTabList *tab_list)
+{
+       return NULL;
+}
+
+static void
+tepl_tab_list_default_init (TeplTabListInterface *interface)
+{
+       interface->get_tabs = tepl_tab_list_get_tabs_default;
+       interface->get_active_tab = tepl_tab_list_get_active_tab_default;
+}
+
+/**
+ * tepl_tab_list_get_tabs:
+ * @tab_list: a #TeplTabList.
+ *
+ * Returns: (transfer container) (element-type TeplTab): the list of all the
+ * #TeplTab's contained in @tab_list.
+ * Since: 3.0
+ */
+GList *
+tepl_tab_list_get_tabs (TeplTabList *tab_list)
+{
+       g_return_val_if_fail (TEPL_IS_TAB_LIST (tab_list), NULL);
+
+       return TEPL_TAB_LIST_GET_INTERFACE (tab_list)->get_tabs (tab_list);
+}
+
+/**
+ * tepl_tab_list_get_views:
+ * @tab_list: a #TeplTabList.
+ *
+ * Convenience function.
+ *
+ * Returns: (transfer container) (element-type TeplView): the list of all the
+ * #TeplView's contained in @tab_list.
+ * Since: 3.0
+ */
+GList *
+tepl_tab_list_get_views (TeplTabList *tab_list)
+{
+       GList *tabs;
+       GList *views = NULL;
+       GList *l;
+
+       g_return_val_if_fail (TEPL_IS_TAB_LIST (tab_list), NULL);
+
+       tabs = tepl_tab_list_get_tabs (tab_list);
+
+       for (l = tabs; l != NULL; l = l->next)
+       {
+               TeplTab *cur_tab = l->data;
+               views = g_list_prepend (views, tepl_tab_get_view (cur_tab));
+       }
+
+       views = g_list_reverse (views);
+
+       g_list_free (tabs);
+       return views;
+}
+
+/**
+ * tepl_tab_list_get_buffers:
+ * @tab_list: a #TeplTabList.
+ *
+ * Convenience function.
+ *
+ * Returns: (transfer container) (element-type TeplBuffer): the list of all the
+ * #TeplBuffer's contained in @tab_list.
+ * Since: 3.0
+ */
+GList *
+tepl_tab_list_get_buffers (TeplTabList *tab_list)
+{
+       GList *tabs;
+       GList *buffers = NULL;
+       GList *l;
+
+       g_return_val_if_fail (TEPL_IS_TAB_LIST (tab_list), NULL);
+
+       tabs = tepl_tab_list_get_tabs (tab_list);
+
+       for (l = tabs; l != NULL; l = l->next)
+       {
+               TeplTab *cur_tab = l->data;
+               buffers = g_list_prepend (buffers, tepl_tab_get_buffer (cur_tab));
+       }
+
+       buffers = g_list_reverse (buffers);
+
+       g_list_free (tabs);
+       return buffers;
+}
+
+/**
+ * tepl_tab_list_get_active_tab:
+ * @tab_list: a #TeplTabList.
+ *
+ * Returns: (transfer none): the #TeplTab currently shown in @tab_list.
+ * Since: 3.0
+ */
+TeplTab *
+tepl_tab_list_get_active_tab (TeplTabList *tab_list)
+{
+       g_return_val_if_fail (TEPL_IS_TAB_LIST (tab_list), NULL);
+
+       return TEPL_TAB_LIST_GET_INTERFACE (tab_list)->get_active_tab (tab_list);
+}
+
+/**
+ * tepl_tab_list_get_active_view:
+ * @tab_list: a #TeplTabList.
+ *
+ * Convenience function.
+ *
+ * Returns: (transfer none): the #TeplView of the active tab.
+ * Since: 3.0
+ */
+TeplView *
+tepl_tab_list_get_active_view (TeplTabList *tab_list)
+{
+       TeplTab *active_tab;
+
+       g_return_val_if_fail (TEPL_IS_TAB_LIST (tab_list), NULL);
+
+       active_tab = tepl_tab_list_get_active_tab (tab_list);
+
+       return active_tab != NULL ? tepl_tab_get_view (active_tab) : NULL;
+}
+
+/**
+ * tepl_tab_list_get_active_buffer:
+ * @tab_list: a #TeplTabList.
+ *
+ * Convenience function.
+ *
+ * Returns: (transfer none): the #TeplBuffer of the active tab.
+ * Since: 3.0
+ */
+TeplBuffer *
+tepl_tab_list_get_active_buffer (TeplTabList *tab_list)
+{
+       TeplTab *active_tab;
+
+       g_return_val_if_fail (TEPL_IS_TAB_LIST (tab_list), NULL);
+
+       active_tab = tepl_tab_list_get_active_tab (tab_list);
+
+       return active_tab != NULL ? tepl_tab_get_buffer (active_tab) : NULL;
+}
diff --git a/tepl/tepl-tab-list.h b/tepl/tepl-tab-list.h
new file mode 100644
index 0000000..e713c57
--- /dev/null
+++ b/tepl/tepl-tab-list.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEPL_TAB_LIST_H
+#define TEPL_TAB_LIST_H
+
+#if !defined (TEPL_H_INSIDE) && !defined (TEPL_COMPILATION)
+#error "Only <tepl/tepl.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+#include <tepl/tepl-types.h>
+
+G_BEGIN_DECLS
+
+#define TEPL_TYPE_TAB_LIST               (tepl_tab_list_get_type ())
+#define TEPL_TAB_LIST(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEPL_TYPE_TAB_LIST, 
TeplTabList))
+#define TEPL_IS_TAB_LIST(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEPL_TYPE_TAB_LIST))
+#define TEPL_TAB_LIST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEPL_TYPE_TAB_LIST, 
TeplTabListInterface))
+
+typedef struct _TeplTabListInterface TeplTabListInterface;
+
+/**
+ * TeplTabListInterface:
+ * @parent_interface: The parent interface.
+ * @get_tabs: Virtual function pointer for tepl_tab_list_get_tabs(). By default,
+ *   %NULL is returned.
+ * @get_active_tab: Virtual function pointer for tepl_tab_list_get_active_tab().
+ *   By default, %NULL is returned.
+ *
+ * The virtual function table for #TeplTabList.
+ *
+ * Since: 3.0
+ */
+struct _TeplTabListInterface
+{
+       GTypeInterface parent_interface;
+
+       GList *         (*get_tabs)             (TeplTabList *tab_list);
+
+       TeplTab *       (*get_active_tab)       (TeplTabList *tab_list);
+};
+
+GType          tepl_tab_list_get_type          (void);
+
+GList *                tepl_tab_list_get_tabs          (TeplTabList *tab_list);
+
+GList *                tepl_tab_list_get_views         (TeplTabList *tab_list);
+
+GList *                tepl_tab_list_get_buffers       (TeplTabList *tab_list);
+
+TeplTab *      tepl_tab_list_get_active_tab    (TeplTabList *tab_list);
+
+TeplView *     tepl_tab_list_get_active_view   (TeplTabList *tab_list);
+
+TeplBuffer *   tepl_tab_list_get_active_buffer (TeplTabList *tab_list);
+
+G_END_DECLS
+
+#endif /* TEPL_TAB_LIST_H */
diff --git a/tepl/tepl-types.h b/tepl/tepl-types.h
index 0d4d3db..b988e49 100644
--- a/tepl/tepl-types.h
+++ b/tepl/tepl-types.h
@@ -45,6 +45,7 @@ typedef struct _TeplGutterRendererFolds               TeplGutterRendererFolds;
 typedef struct _TeplInfoBar                    TeplInfoBar;
 typedef struct _TeplMenuShell                  TeplMenuShell;
 typedef struct _TeplTab                                TeplTab;
+typedef struct _TeplTabList                    TeplTabList;
 typedef struct _TeplView                       TeplView;
 
 G_END_DECLS
diff --git a/tepl/tepl.h b/tepl/tepl.h
index 5729971..d9d75fa 100644
--- a/tepl/tepl.h
+++ b/tepl/tepl.h
@@ -45,6 +45,7 @@
 #include <tepl/tepl-menu-shell.h>
 #include <tepl/tepl-metadata-manager.h>
 #include <tepl/tepl-tab.h>
+#include <tepl/tepl-tab-list.h>
 #include <tepl/tepl-utils.h>
 #include <tepl/tepl-view.h>
 


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