[evince/wip/gpoo/gtk4-preparation-ev-sidebar-bookmarks: 10/11] shell: Use composite template for EvSidebar
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/gtk4-preparation-ev-sidebar-bookmarks: 10/11] shell: Use composite template for EvSidebar
- Date: Thu, 31 Mar 2022 03:07:24 +0000 (UTC)
commit 83bca84967be72cd5c679050cd8d69a70b798ecb
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Sat Mar 26 11:53:46 2022 -0300
shell: Use composite template for EvSidebar
* Switch to composite template
* Support internal-child property
Co-authored-by: Qiu Wenbo <qiuwenbo kylinos com cn>
shell/ev-sidebar.c | 74 +++++++++++++++++++++++++++-------------------
shell/evince-sidebar.ui | 24 +++++++++++++++
shell/evince.gresource.xml | 1 +
shell/meson.build | 1 +
4 files changed, 69 insertions(+), 31 deletions(-)
---
diff --git a/shell/ev-sidebar.c b/shell/ev-sidebar.c
index ff8ca1d16..fcf150f1e 100644
--- a/shell/ev-sidebar.c
+++ b/shell/ev-sidebar.c
@@ -35,6 +35,7 @@
#include "ev-sidebar.h"
#include "ev-sidebar-page.h"
+#include "ev-sidebar-links.h"
enum
{
@@ -60,7 +61,16 @@ typedef struct {
GtkTreeModel *page_model;
} EvSidebarPrivate;
-G_DEFINE_TYPE_WITH_PRIVATE (EvSidebar, ev_sidebar, GTK_TYPE_BOX)
+static void ev_sidebar_child_change_cb (GObject *gobject,
+ GParamSpec *pspec,
+ EvSidebar *ev_sidebar);
+static void ev_sidebar_buildable_iface_init (GtkBuildableIface *iface);
+static GtkBuildableIface *parent_buildable_iface;
+
+G_DEFINE_TYPE_WITH_CODE (EvSidebar, ev_sidebar, GTK_TYPE_BOX,
+ G_ADD_PRIVATE (EvSidebar)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+ ev_sidebar_buildable_iface_init))
#define GET_PRIVATE(o) ev_sidebar_get_instance_private (o)
@@ -149,11 +159,19 @@ static void
ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (ev_sidebar_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_sidebar_class);
g_object_class->dispose = ev_sidebar_dispose;
g_object_class->get_property = ev_sidebar_get_property;
g_object_class->set_property = ev_sidebar_set_property;
+ g_type_ensure (EV_TYPE_SIDEBAR_LINKS);
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/evince/ui/sidebar.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, EvSidebar, switcher);
+ gtk_widget_class_bind_template_child_private (widget_class, EvSidebar, stack);
+ gtk_widget_class_bind_template_callback (widget_class, ev_sidebar_child_change_cb);
+
g_object_class_install_property (g_object_class,
PROP_CURRENT_PAGE,
g_param_spec_object ("current-page",
@@ -190,8 +208,6 @@ static void
ev_sidebar_init (EvSidebar *ev_sidebar)
{
EvSidebarPrivate *priv;
- GtkWidget *switcher;
- GtkWidget *stack;
priv = GET_PRIVATE (ev_sidebar);
@@ -203,27 +219,7 @@ ev_sidebar_init (EvSidebar *ev_sidebar)
G_TYPE_STRING,
G_TYPE_STRING);
- switcher = gtk_stack_switcher_new ();
- priv->switcher = switcher;
- gtk_box_pack_end (GTK_BOX (ev_sidebar), switcher, FALSE, TRUE, 0);
- g_object_set (switcher, "icon-size", 1, NULL);
- gtk_container_set_border_width (GTK_CONTAINER (switcher), 6);
- gtk_widget_set_halign (switcher, GTK_ALIGN_FILL);
- gtk_widget_set_hexpand (switcher, TRUE);
- gtk_box_set_homogeneous (GTK_BOX (switcher), TRUE);
- gtk_widget_show (priv->switcher);
-
- stack = gtk_stack_new ();
- priv->stack = stack;
- gtk_stack_set_homogeneous (GTK_STACK (stack), TRUE);
- gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher),
- GTK_STACK (stack));
- gtk_box_pack_end (GTK_BOX (ev_sidebar), stack, TRUE, TRUE, 0);
- gtk_widget_show (priv->stack);
-
- g_signal_connect (stack, "notify::visible-child",
- G_CALLBACK (ev_sidebar_child_change_cb),
- ev_sidebar);
+ gtk_widget_init_template (GTK_WIDGET (ev_sidebar));
}
static gboolean
@@ -291,18 +287,34 @@ ev_sidebar_document_changed_cb (EvDocumentModel *model,
}
}
+static GObject *
+ev_sidebar_buildable_get_internal_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ const char *childname)
+{
+ EvSidebar *sidebar = EV_SIDEBAR (buildable);
+ EvSidebarPrivate *priv = GET_PRIVATE (sidebar);
+
+ if (g_strcmp0 (childname, "stack") == 0)
+ return G_OBJECT (priv->stack);
+
+ return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
+
+static void
+ev_sidebar_buildable_iface_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+
+ iface->get_internal_child = ev_sidebar_buildable_get_internal_child;
+}
+
/* Public functions */
GtkWidget *
ev_sidebar_new (void)
{
- GtkWidget *ev_sidebar;
-
- ev_sidebar = g_object_new (EV_TYPE_SIDEBAR,
- "orientation", GTK_ORIENTATION_VERTICAL,
- NULL);
-
- return ev_sidebar;
+ return GTK_WIDGET (g_object_new (EV_TYPE_SIDEBAR, NULL));
}
void
diff --git a/shell/evince-sidebar.ui b/shell/evince-sidebar.ui
new file mode 100644
index 000000000..21f6d801e
--- /dev/null
+++ b/shell/evince-sidebar.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="EvSidebar" parent="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkStack" id="stack">
+ <property name="expand">True</property>
+ <property name="visible">True</property>
+ <signal name="notify::visible-child" handler="ev_sidebar_child_change_cb" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkStackSwitcher" id="switcher">
+ <property name="stack">stack</property>
+ <property name="halign">fill</property>
+ <property name="hexpand">True</property>
+ <property name="homogeneous">True</property>
+ <property name="margin">6</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index f0ec07af8..c868efe38 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -25,6 +25,7 @@
<file alias="ui/password-view.ui" compressed="true"
preprocess="xml-stripblanks">evince-password-view.ui</file>
<file alias="ui/progress-message-area.ui" compressed="true"
preprocess="xml-stripblanks">evince-progress-message-area.ui</file>
<file alias="ui/properties-fonts.ui" compressed="true"
preprocess="xml-stripblanks">evince-properties-fonts.ui</file>
+ <file alias="ui/sidebar.ui" compressed="true" preprocess="xml-stripblanks">evince-sidebar.ui</file>
<file alias="ui/zoom-action.ui" compressed="true"
preprocess="xml-stripblanks">evince-zoom-action.ui</file>
</gresource>
</gresources>
diff --git a/shell/meson.build b/shell/meson.build
index 06a7a53b3..713972dff 100644
--- a/shell/meson.build
+++ b/shell/meson.build
@@ -40,6 +40,7 @@ resource_data = files(
'evince-password-view.ui',
'evince-properties-fonts.ui',
'evince-progress-message-area.ui',
+ 'evince-sidebar.ui',
'evince-zoom-action.ui',
'help-overlay.ui',
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]