[tepl] TabGroup: add set_active_tab() and make :active-tab property writable
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] TabGroup: add set_active_tab() and make :active-tab property writable
- Date: Sat, 22 Jul 2017 19:24:12 +0000 (UTC)
commit cbbbef2a165cdbcbcbac7e1880d66a6c9a9555d8
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jul 22 20:46:46 2017 +0200
TabGroup: add set_active_tab() and make :active-tab property writable
docs/reference/tepl-3.0-sections.txt | 1 +
tepl/tepl-application-window.c | 18 +++++++++++++++++
tepl/tepl-notebook.c | 21 +++++++++++++++++++
tepl/tepl-tab-group.c | 36 +++++++++++++++++++++++++++++++++-
tepl/tepl-tab-group.h | 12 ++++++++++-
tepl/tepl-tab.c | 5 ++++
6 files changed, 91 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 87ea96a..5af5346 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -438,6 +438,7 @@ tepl_tab_group_get_tabs
tepl_tab_group_get_views
tepl_tab_group_get_buffers
tepl_tab_group_get_active_tab
+tepl_tab_group_set_active_tab
tepl_tab_group_get_active_view
tepl_tab_group_get_active_buffer
<SUBSECTION Standard>
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 8fe224b..76c7927 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -122,6 +122,7 @@ tepl_application_window_set_property (GObject *object,
GParamSpec *pspec)
{
TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (object);
+ TeplTabGroup *tab_group = TEPL_TAB_GROUP (object);
switch (prop_id)
{
@@ -130,6 +131,10 @@ tepl_application_window_set_property (GObject *object,
tepl_window->priv->gtk_window = g_value_get_object (value);
break;
+ case PROP_ACTIVE_TAB:
+ tepl_tab_group_set_active_tab (tab_group, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -219,6 +224,18 @@ tepl_application_window_get_active_tab (TeplTabGroup *tab_group)
}
static void
+tepl_application_window_set_active_tab (TeplTabGroup *tab_group,
+ TeplTab *tab)
+{
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (tab_group);
+
+ if (tepl_window->priv->tab_group != NULL)
+ {
+ tepl_tab_group_set_active_tab (tepl_window->priv->tab_group, tab);
+ }
+}
+
+static void
tepl_tab_group_interface_init (gpointer g_iface,
gpointer iface_data)
{
@@ -226,6 +243,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;
}
static void
diff --git a/tepl/tepl-notebook.c b/tepl/tepl-notebook.c
index 85cbc8f..bff7ede 100644
--- a/tepl/tepl-notebook.c
+++ b/tepl/tepl-notebook.c
@@ -89,8 +89,14 @@ tepl_notebook_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
+ TeplTabGroup *tab_group = TEPL_TAB_GROUP (object);
+
switch (prop_id)
{
+ case PROP_ACTIVE_TAB:
+ tepl_tab_group_set_active_tab (tab_group, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -215,6 +221,20 @@ tepl_notebook_get_active_tab (TeplTabGroup *tab_group)
}
static void
+tepl_notebook_set_active_tab (TeplTabGroup *tab_group,
+ TeplTab *tab)
+{
+ gint page_num;
+
+ GtkNotebook *notebook = GTK_NOTEBOOK (tab_group);
+
+ page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (tab));
+ g_return_if_fail (page_num != -1);
+
+ gtk_notebook_set_current_page (notebook, page_num);
+}
+
+static void
tepl_tab_group_interface_init (gpointer g_iface,
gpointer iface_data)
{
@@ -222,6 +242,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;
}
static void
diff --git a/tepl/tepl-tab-group.c b/tepl/tepl-tab-group.c
index d36126e..84cd645 100644
--- a/tepl/tepl-tab-group.c
+++ b/tepl/tepl-tab-group.c
@@ -50,10 +50,17 @@ tepl_tab_group_get_active_tab_default (TeplTabGroup *tab_group)
}
static void
+tepl_tab_group_set_active_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;
/**
* TeplTabGroup:active-tab:
@@ -67,7 +74,7 @@ tepl_tab_group_default_init (TeplTabGroupInterface *interface)
"Active Tab",
"",
TEPL_TYPE_TAB,
- G_PARAM_READABLE |
+ G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
@@ -207,6 +214,33 @@ tepl_tab_group_get_active_tab (TeplTabGroup *tab_group)
}
/**
+ * tepl_tab_group_set_active_tab:
+ * @tab_group: a #TeplTabGroup.
+ * @tab: a #TeplTab part of @tab_group.
+ *
+ * Sets the #TeplTabGroup:active-tab. @tab must be part of @tab_group.
+ *
+ * Since: 3.0
+ */
+void
+tepl_tab_group_set_active_tab (TeplTabGroup *tab_group,
+ TeplTab *tab)
+{
+ GList *all_tabs;
+ gboolean tab_in_tab_group;
+
+ g_return_if_fail (TEPL_IS_TAB_GROUP (tab_group));
+ g_return_if_fail (TEPL_IS_TAB (tab));
+
+ all_tabs = tepl_tab_group_get_tabs (tab_group);
+ tab_in_tab_group = g_list_find (all_tabs, tab) != NULL;
+ g_list_free (all_tabs);
+ g_return_if_fail (tab_in_tab_group);
+
+ TEPL_TAB_GROUP_GET_INTERFACE (tab_group)->set_active_tab (tab_group, tab);
+}
+
+/**
* tepl_tab_group_get_active_view:
* @tab_group: a #TeplTabGroup.
*
diff --git a/tepl/tepl-tab-group.h b/tepl/tepl-tab-group.h
index 1ddca9f..c97ee5d 100644
--- a/tepl/tepl-tab-group.h
+++ b/tepl/tepl-tab-group.h
@@ -46,8 +46,12 @@ typedef struct _TeplTabGroupInterface TeplTabGroupInterface;
* tepl_tab_group_get_tabs().
* @get_active_tab: Virtual function pointer for tepl_tab_group_get_active_tab().
* By default, %NULL is returned.
+ * @set_active_tab: Virtual function pointer for
+ * tepl_tab_group_set_active_tab(). Does nothing by default.
*
- * The virtual function table for #TeplTabGroup.
+ * The virtual function table for #TeplTabGroup. When implementing one of the
+ * vfunc, you can assume that the pre-conditions are already checked (the
+ * parameters are valid).
*
* Since: 3.0
*/
@@ -58,6 +62,9 @@ struct _TeplTabGroupInterface
GList * (*get_tabs) (TeplTabGroup *tab_group);
TeplTab * (*get_active_tab) (TeplTabGroup *tab_group);
+
+ void (*set_active_tab) (TeplTabGroup *tab_group,
+ TeplTab *tab);
};
GType tepl_tab_group_get_type (void);
@@ -70,6 +77,9 @@ GList * tepl_tab_group_get_buffers (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);
+
TeplView * tepl_tab_group_get_active_view (TeplTabGroup *tab_group);
TeplBuffer * tepl_tab_group_get_active_buffer (TeplTabGroup *tab_group);
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 9f9b0a1..7b005cb 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -220,6 +220,7 @@ tepl_tab_set_property (GObject *object,
GParamSpec *pspec)
{
TeplTab *tab = TEPL_TAB (object);
+ TeplTabGroup *tab_group = TEPL_TAB_GROUP (object);
switch (prop_id)
{
@@ -227,6 +228,10 @@ tepl_tab_set_property (GObject *object,
set_view (tab, g_value_get_object (value));
break;
+ case PROP_ACTIVE_TAB:
+ tepl_tab_group_set_active_tab (tab_group, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]