[tepl] TabGroup: add the :active-buffer property
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] TabGroup: add the :active-buffer property
- Date: Fri, 21 Jul 2017 11:14:06 +0000 (UTC)
commit 906108a0ae99ccfcc3becb908de5c8b24fbf0266
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jul 21 05:38:35 2017 +0200
TabGroup: add the :active-buffer property
tepl/tepl-application-window.c | 20 ++++++++++++++
tepl/tepl-notebook.c | 54 +++++++++++++++++++++++++++++++++++++--
tepl/tepl-tab-group.c | 16 ++++++++++++
tepl/tepl-tab.c | 20 ++++++++++++++
4 files changed, 107 insertions(+), 3 deletions(-)
---
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index aa36406..8fe224b 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -68,6 +68,7 @@ enum
PROP_APPLICATION_WINDOW,
PROP_ACTIVE_TAB,
PROP_ACTIVE_VIEW,
+ PROP_ACTIVE_BUFFER,
};
#define TEPL_APPLICATION_WINDOW_KEY "tepl-application-window-key"
@@ -104,6 +105,10 @@ tepl_application_window_get_property (GObject *object,
g_value_set_object (value, tepl_tab_group_get_active_view (TEPL_TAB_GROUP
(tepl_window)));
break;
+ case PROP_ACTIVE_BUFFER:
+ g_value_set_object (value, tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP
(tepl_window)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -184,6 +189,7 @@ tepl_application_window_class_init (TeplApplicationWindowClass *klass)
g_object_class_override_property (object_class, PROP_ACTIVE_TAB, "active-tab");
g_object_class_override_property (object_class, PROP_ACTIVE_VIEW, "active-view");
+ g_object_class_override_property (object_class, PROP_ACTIVE_BUFFER, "active-buffer");
}
static GList *
@@ -294,6 +300,14 @@ active_view_notify_cb (TeplTabGroup *tab_group,
g_object_notify (G_OBJECT (tepl_window), "active-view");
}
+static void
+active_buffer_notify_cb (TeplTabGroup *tab_group,
+ GParamSpec *pspec,
+ TeplApplicationWindow *tepl_window)
+{
+ g_object_notify (G_OBJECT (tepl_window), "active-buffer");
+}
+
/**
* tepl_application_window_set_tab_group:
* @tepl_window: a #TeplApplicationWindow.
@@ -335,6 +349,12 @@ tepl_application_window_set_tab_group (TeplApplicationWindow *tepl_window,
G_CALLBACK (active_view_notify_cb),
tepl_window,
0);
+
+ g_signal_connect_object (tab_group,
+ "notify::active-buffer",
+ G_CALLBACK (active_buffer_notify_cb),
+ tepl_window,
+ 0);
}
/* ex:set ts=8 noet: */
diff --git a/tepl/tepl-notebook.c b/tepl/tepl-notebook.c
index d7ab54a..85cbc8f 100644
--- a/tepl/tepl-notebook.c
+++ b/tepl/tepl-notebook.c
@@ -20,6 +20,7 @@
#include "tepl-notebook.h"
#include "tepl-tab-group.h"
#include "tepl-tab.h"
+#include "tepl-signal-group.h"
/**
* SECTION:notebook
@@ -33,7 +34,7 @@
struct _TeplNotebookPrivate
{
- gint something;
+ TeplSignalGroup *view_signal_group;
};
enum
@@ -41,6 +42,7 @@ enum
PROP_0,
PROP_ACTIVE_TAB,
PROP_ACTIVE_VIEW,
+ PROP_ACTIVE_BUFFER,
};
static void tepl_tab_group_interface_init (gpointer g_iface,
@@ -71,6 +73,10 @@ tepl_notebook_get_property (GObject *object,
g_value_set_object (value, tepl_tab_group_get_active_view (tab_group));
break;
+ case PROP_ACTIVE_BUFFER:
+ g_value_set_object (value, tepl_tab_group_get_active_buffer (tab_group));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -92,6 +98,47 @@ tepl_notebook_set_property (GObject *object,
}
static void
+tepl_notebook_dispose (GObject *object)
+{
+ TeplNotebook *notebook = TEPL_NOTEBOOK (object);
+
+ g_clear_pointer (¬ebook->priv->view_signal_group,
+ (GDestroyNotify) _tepl_signal_group_free);
+
+ G_OBJECT_CLASS (tepl_notebook_parent_class)->dispose (object);
+}
+
+static void
+buffer_notify_cb (GtkTextView *view,
+ GParamSpec *pspec,
+ TeplNotebook *notebook)
+{
+ g_object_notify (G_OBJECT (notebook), "active-buffer");
+}
+
+static void
+active_tab_changed (TeplNotebook *notebook)
+{
+ TeplView *view;
+
+ g_clear_pointer (¬ebook->priv->view_signal_group,
+ (GDestroyNotify) _tepl_signal_group_free);
+
+ view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (notebook));
+ notebook->priv->view_signal_group = _tepl_signal_group_new (G_OBJECT (view));
+
+ _tepl_signal_group_add_handler_id (notebook->priv->view_signal_group,
+ g_signal_connect (view,
+ "notify::buffer",
+ G_CALLBACK (buffer_notify_cb),
+ notebook));
+
+ g_object_notify (G_OBJECT (notebook), "active-tab");
+ g_object_notify (G_OBJECT (notebook), "active-view");
+ g_object_notify (G_OBJECT (notebook), "active-buffer");
+}
+
+static void
tepl_notebook_switch_page (GtkNotebook *notebook,
GtkWidget *page,
guint page_num)
@@ -107,8 +154,7 @@ tepl_notebook_switch_page (GtkNotebook *notebook,
* active-tab property. Is it enough? Do we also need to connect to
* other GtkNotebook signals?
*/
- g_object_notify (G_OBJECT (notebook), "active-tab");
- g_object_notify (G_OBJECT (notebook), "active-view");
+ active_tab_changed (TEPL_NOTEBOOK (notebook));
}
static void
@@ -119,11 +165,13 @@ tepl_notebook_class_init (TeplNotebookClass *klass)
object_class->get_property = tepl_notebook_get_property;
object_class->set_property = tepl_notebook_set_property;
+ object_class->dispose = tepl_notebook_dispose;
notebook_class->switch_page = tepl_notebook_switch_page;
g_object_class_override_property (object_class, PROP_ACTIVE_TAB, "active-tab");
g_object_class_override_property (object_class, PROP_ACTIVE_VIEW, "active-view");
+ g_object_class_override_property (object_class, PROP_ACTIVE_BUFFER, "active-buffer");
}
static GList *
diff --git a/tepl/tepl-tab-group.c b/tepl/tepl-tab-group.c
index aadf9ee..d36126e 100644
--- a/tepl/tepl-tab-group.c
+++ b/tepl/tepl-tab-group.c
@@ -20,6 +20,7 @@
#include "tepl-tab-group.h"
#include "tepl-tab.h"
#include "tepl-view.h"
+#include "tepl-buffer.h"
/**
* SECTION:tab-group
@@ -83,6 +84,21 @@ tepl_tab_group_default_init (TeplTabGroupInterface *interface)
TEPL_TYPE_VIEW,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * TeplTabGroup:active-buffer:
+ *
+ * The #TeplBuffer of the active tab.
+ *
+ * Since: 3.0
+ */
+ g_object_interface_install_property (interface,
+ g_param_spec_object ("active-buffer",
+ "Active Buffer",
+ "",
+ TEPL_TYPE_BUFFER,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
}
/**
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index e4d78fa..9f9b0a1 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -57,6 +57,7 @@ enum
PROP_VIEW,
PROP_ACTIVE_TAB,
PROP_ACTIVE_VIEW,
+ PROP_ACTIVE_BUFFER,
};
static void tepl_tab_group_interface_init (gpointer g_iface,
@@ -146,6 +147,14 @@ tepl_tab_pack_info_bar_default (TeplTab *tab,
}
static void
+buffer_notify_cb (GtkTextView *view,
+ GParamSpec *pspec,
+ TeplTab *tab)
+{
+ g_object_notify (G_OBJECT (tab), "active-buffer");
+}
+
+static void
set_view (TeplTab *tab,
TeplView *view)
{
@@ -163,6 +172,12 @@ set_view (TeplTab *tab,
TEPL_TAB_GET_CLASS (tab)->pack_view (tab, view);
+ g_signal_connect_object (view,
+ "notify::buffer",
+ G_CALLBACK (buffer_notify_cb),
+ tab,
+ 0);
+
g_object_notify (G_OBJECT (tab), "view");
}
@@ -188,6 +203,10 @@ tepl_tab_get_property (GObject *object,
g_value_set_object (value, tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tab)));
break;
+ case PROP_ACTIVE_BUFFER:
+ g_value_set_object (value, tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tab)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -256,6 +275,7 @@ tepl_tab_class_init (TeplTabClass *klass)
g_object_class_override_property (object_class, PROP_ACTIVE_TAB, "active-tab");
g_object_class_override_property (object_class, PROP_ACTIVE_VIEW, "active-view");
+ g_object_class_override_property (object_class, PROP_ACTIVE_BUFFER, "active-buffer");
}
static GList *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]