[epiphany] Add EphyPageRow
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add EphyPageRow
- Date: Fri, 25 Jan 2019 16:45:37 +0000 (UTC)
commit 4df39601389f0194c8f00b5711bffbd8644e9e98
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Jan 24 15:05:13 2019 +0100
Add EphyPageRow
This listbox row representing a page will be used in the next commit.
src/ephy-page-row.c | 111 +++++++++++++++++++++++++++++++++++
src/ephy-page-row.h | 39 ++++++++++++
src/meson.build | 1 +
src/resources/epiphany.gresource.xml | 1 +
src/resources/gtk/page-row.ui | 45 ++++++++++++++
5 files changed, 197 insertions(+)
---
diff --git a/src/ephy-page-row.c b/src/ephy-page-row.c
new file mode 100644
index 000000000..a92c8a131
--- /dev/null
+++ b/src/ephy-page-row.c
@@ -0,0 +1,111 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2019 Purism SPC
+ * Copyright © 2019 Adrien Plazas <kekun plazas laposte net>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "ephy-page-row.h"
+
+enum {
+ CLOSED,
+
+ LAST_SIGNAL
+};
+
+struct _EphyPageRow {
+ GtkPopover parent_instance;
+
+ GtkBox *box;
+ GtkLabel *title;
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE (EphyPageRow, ephy_page_row, GTK_TYPE_LIST_BOX_ROW)
+
+static void
+close_clicked_cb (EphyPageRow *self)
+{
+ g_signal_emit (self, signals[CLOSED], 0);
+}
+
+static void
+ephy_page_row_class_init (EphyPageRowClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ signals[CLOSED] =
+ g_signal_new ("closed",
+ EPHY_TYPE_PAGE_ROW,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/gtk/page-row.ui");
+ gtk_widget_class_bind_template_child (widget_class, EphyPageRow, box);
+ gtk_widget_class_bind_template_child (widget_class, EphyPageRow, title);
+ gtk_widget_class_bind_template_callback (widget_class, close_clicked_cb);
+}
+
+static void
+ephy_page_row_init (EphyPageRow *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+EphyPageRow *
+ephy_page_row_new (GMenuModel *menu_model,
+ gint position)
+{
+ EphyPageRow *self;
+ GVariant *label;
+
+ g_assert (menu_model != NULL);
+ g_assert (position >= 0);
+ g_assert (position < g_menu_model_get_n_items (menu_model));
+
+ self = g_object_new (EPHY_TYPE_PAGE_ROW, NULL);
+
+ label = g_menu_model_get_item_attribute_value (menu_model,
+ position,
+ G_MENU_ATTRIBUTE_LABEL,
+ G_VARIANT_TYPE_STRING);
+ gtk_label_set_text (self->title, g_variant_get_string (label, NULL));
+
+ return self;
+}
+
+void
+ephy_page_row_set_adaptive_mode (EphyPageRow *self,
+ EphyAdaptiveMode adaptive_mode)
+{
+ g_assert (EPHY_IS_PAGE_ROW (self));
+
+ switch (adaptive_mode) {
+ case EPHY_ADAPTIVE_MODE_NORMAL:
+ gtk_widget_set_size_request (GTK_WIDGET (self->box), -1, -1);
+
+ break;
+ case EPHY_ADAPTIVE_MODE_NARROW:
+ gtk_widget_set_size_request (GTK_WIDGET (self->box), -1, 50);
+
+ break;
+ }
+}
diff --git a/src/ephy-page-row.h b/src/ephy-page-row.h
new file mode 100644
index 000000000..d34cd451c
--- /dev/null
+++ b/src/ephy-page-row.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2019 Purism SPC
+ * Copyright © 2019 Adrien Plazas <kekun plazas laposte net>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+#include "ephy-adaptive-mode.h"
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_PAGE_ROW (ephy_page_row_get_type())
+
+G_DECLARE_FINAL_TYPE (EphyPageRow, ephy_page_row, EPHY, PAGE_ROW, GtkListBoxRow)
+
+EphyPageRow *ephy_page_row_new (GMenuModel *menu_model,
+ int position);
+
+void ephy_page_row_set_adaptive_mode (EphyPageRow *self,
+ EphyAdaptiveMode adaptive_mode);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index bcb56dac7..b7a4149b7 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -34,6 +34,7 @@ libephymain_sources = [
'ephy-lockdown.c',
'ephy-mouse-gesture-controller.c',
'ephy-notebook.c',
+ 'ephy-page-row.c',
'ephy-search-engine-dialog.c',
'ephy-session.c',
'ephy-shell.c',
diff --git a/src/resources/epiphany.gresource.xml b/src/resources/epiphany.gresource.xml
index 0bbe6b819..e3f8f130f 100644
--- a/src/resources/epiphany.gresource.xml
+++ b/src/resources/epiphany.gresource.xml
@@ -24,6 +24,7 @@
<file preprocess="xml-stripblanks" compressed="true">gtk/history-dialog.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/notebook-context-menu.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/page-menu-popover.ui</file>
+ <file preprocess="xml-stripblanks" compressed="true">gtk/page-row.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/passwords-dialog.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/prefs-dialog.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/prefs-lang-dialog.ui</file>
diff --git a/src/resources/gtk/page-row.ui b/src/resources/gtk/page-row.ui
new file mode 100644
index 000000000..ff7550b75
--- /dev/null
+++ b/src/resources/gtk/page-row.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.16 -->
+ <template class="EphyPageRow" parent="GtkListBoxRow">
+ <child>
+ <object class="GtkBox" id="box">
+ <property name="margin_end">12</property>
+ <property name="margin_start">12</property>
+ <property name="spacing">12</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="title">
+ <property name="ellipsize">end</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="valign">center</property>
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="close_button">
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ <property name="relief">none</property>
+ <property name="valign">center</property>
+ <property name="visible">True</property>
+ <signal name="clicked" handler="close_clicked_cb" swapped="yes"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">window-close-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]