[evince/wip/gpoo/gtk4-preparation-ev-recent-view] shell: Use composite template for the recents view
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/gtk4-preparation-ev-recent-view] shell: Use composite template for the recents view
- Date: Fri, 25 Mar 2022 03:11:15 +0000 (UTC)
commit b2aac2600d7ff842e274695150eda1768fd7325c
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Thu Mar 24 23:55:19 2022 -0300
shell: Use composite template for the recents view
Co-authored-by: Qiu Wenbo <qiuwenbo kylinos com cn>
shell/ev-recent-view.c | 106 +++++---------------------------------------
shell/ev-recent-view.h | 4 +-
shell/evince-recent-view.ui | 50 +++++++++++++++++++++
shell/evince.gresource.xml | 1 +
4 files changed, 65 insertions(+), 96 deletions(-)
---
diff --git a/shell/ev-recent-view.c b/shell/ev-recent-view.c
index 74a97a469..e8c0916ed 100644
--- a/shell/ev-recent-view.c
+++ b/shell/ev-recent-view.c
@@ -66,7 +66,7 @@ enum {
static guint signals[NUM_SIGNALS] = { 0, };
-G_DEFINE_TYPE_WITH_PRIVATE (EvRecentView, ev_recent_view, GTK_TYPE_SCROLLED_WINDOW)
+G_DEFINE_TYPE_WITH_PRIVATE (EvRecentView, ev_recent_view, GTK_TYPE_BOX)
#define ICON_VIEW_SIZE 128
#define MAX_RECENT_VIEW_ITEMS 64
@@ -232,53 +232,6 @@ on_query_tooltip_event (GtkWidget *widget,
return TRUE;
}
-static gboolean
-on_button_release_event (GtkWidget *view,
- GdkEventButton *event,
- EvRecentView *ev_recent_view)
-{
- EvRecentViewPrivate *priv = GET_PRIVATE (ev_recent_view);
- GtkTreePath *path;
-
- /* eat double/triple click events */
- if (event->type != GDK_BUTTON_RELEASE)
- return TRUE;
-
- if (priv->pressed_item_tree_path == NULL)
- return FALSE;
-
- path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (priv->view), event->x, event->y);
- if (path == NULL)
- return FALSE;
-
- if (gtk_tree_path_compare (path, priv->pressed_item_tree_path) == 0) {
- g_clear_pointer (&priv->pressed_item_tree_path, gtk_tree_path_free);
- gtk_icon_view_item_activated (GTK_ICON_VIEW (priv->view), path);
- gtk_tree_path_free (path);
-
- return TRUE;
- }
-
- g_clear_pointer (&priv->pressed_item_tree_path, gtk_tree_path_free);
- gtk_tree_path_free (path);
-
- return FALSE;
-}
-
-static gboolean
-on_button_press_event (GtkWidget *view,
- GdkEventButton *event,
- EvRecentView *ev_recent_view)
-{
- EvRecentViewPrivate *priv = GET_PRIVATE (ev_recent_view);
-
- g_clear_pointer (&priv->pressed_item_tree_path, gtk_tree_path_free);
- priv->pressed_item_tree_path =
- gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (priv->view), event->x, event->y);
-
- return TRUE;
-}
-
static void
on_icon_view_item_activated (GtkIconView *iconview,
GtkTreePath *path,
@@ -802,46 +755,9 @@ ev_recent_view_constructed (GObject *object)
{
EvRecentView *ev_recent_view = EV_RECENT_VIEW (object);
EvRecentViewPrivate *priv = GET_PRIVATE (ev_recent_view);
- GtkCellRenderer *renderer;
G_OBJECT_CLASS (ev_recent_view_parent_class)->constructed (object);
- priv->view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->model));
-
- gtk_icon_view_set_column_spacing (GTK_ICON_VIEW (priv->view), 20);
- gtk_icon_view_set_margin (GTK_ICON_VIEW (priv->view), 16);
- gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (priv->view), GTK_SELECTION_NONE);
- gtk_widget_set_hexpand (priv->view, TRUE);
- gtk_widget_set_vexpand (priv->view, TRUE);
- gtk_widget_set_has_tooltip (priv->view, TRUE);
-
- renderer = gtk_cell_renderer_pixbuf_new ();
- g_object_set (renderer, "xalign", 0.5, "yalign", 0.5, NULL);
-
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->view), renderer, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->view), renderer,
- "surface", EV_RECENT_VIEW_COLUMN_ICON);
-
- renderer = gd_two_lines_renderer_new ();
- g_object_set (renderer,
- "xalign", 0.5,
- "alignment", PANGO_ALIGN_CENTER,
- "wrap-mode", PANGO_WRAP_WORD_CHAR,
- "wrap-width", 128,
- "text-lines", 3,
- NULL);
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->view), renderer, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->view), renderer,
- "text", EV_RECENT_VIEW_COLUMN_PRIMARY_TEXT);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->view), renderer,
- "line-two", EV_RECENT_VIEW_COLUMN_SECONDARY_TEXT);
-
- g_signal_connect (priv->view, "button-press-event",
- G_CALLBACK (on_button_press_event),
- ev_recent_view);
- g_signal_connect (priv->view, "button-release-event",
- G_CALLBACK (on_button_release_event),
- ev_recent_view);
g_signal_connect (priv->view, "item-activated",
G_CALLBACK (on_icon_view_item_activated),
ev_recent_view);
@@ -849,9 +765,10 @@ ev_recent_view_constructed (GObject *object)
G_CALLBACK (on_query_tooltip_event),
ev_recent_view);
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->view), "content-view");
- gtk_container_add (GTK_CONTAINER (ev_recent_view), priv->view);
- gtk_widget_show (priv->view);
+ gtk_icon_view_set_model (GTK_ICON_VIEW (priv->view),
+ GTK_TREE_MODEL (priv->model));
+
+ gtk_widget_show_all (GTK_WIDGET (ev_recent_view));
ev_recent_view_refresh (ev_recent_view);
}
@@ -861,6 +778,8 @@ ev_recent_view_init (EvRecentView *ev_recent_view)
{
EvRecentViewPrivate *priv = GET_PRIVATE (ev_recent_view);
+ gtk_widget_init_template (GTK_WIDGET (ev_recent_view));
+
priv->recent_manager = gtk_recent_manager_get_default ();
priv->model = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING,
@@ -868,12 +787,6 @@ ev_recent_view_init (EvRecentView *ev_recent_view)
G_TYPE_STRING,
CAIRO_GOBJECT_TYPE_SURFACE,
G_TYPE_POINTER);
-
- gtk_widget_set_hexpand (GTK_WIDGET (ev_recent_view), TRUE);
- gtk_widget_set_vexpand (GTK_WIDGET (ev_recent_view), TRUE);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ev_recent_view),
- GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
priv->recent_manager_changed_handler_id =
g_signal_connect_swapped (priv->recent_manager,
"changed",
@@ -885,10 +798,15 @@ static void
ev_recent_view_class_init (EvRecentViewClass *klass)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
g_object_class->constructed = ev_recent_view_constructed;
g_object_class->dispose = ev_recent_view_dispose;
+ g_type_ensure (GD_TYPE_TWO_LINES_RENDERER);
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/evince/ui/recent-view.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, EvRecentView, view);
+
signals[ITEM_ACTIVATED] =
g_signal_new ("item-activated",
EV_TYPE_RECENT_VIEW,
diff --git a/shell/ev-recent-view.h b/shell/ev-recent-view.h
index ea1186cc7..0110574b5 100644
--- a/shell/ev-recent-view.h
+++ b/shell/ev-recent-view.h
@@ -36,12 +36,12 @@ typedef struct _EvRecentViewClass EvRecentViewClass;
struct _EvRecentView
{
- GtkScrolledWindow parent;
+ GtkBox parent;
};
struct _EvRecentViewClass
{
- GtkScrolledWindowClass parent_class;
+ GtkBoxClass parent_class;
};
GType ev_recent_view_get_type (void) G_GNUC_CONST;
diff --git a/shell/evince-recent-view.ui b/shell/evince-recent-view.ui
new file mode 100644
index 000000000..2e3c7f405
--- /dev/null
+++ b/shell/evince-recent-view.ui
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="EvRecentView" parent="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkScrolledWindow" id="swindow">
+ <property name="vexpand">True</property>
+ <property name="hexpand">True</property>
+ <property name="hscrollbar-policy">never</property>
+ <property name="vscrollbar-policy">automatic</property>
+ <child>
+ <object class="GtkIconView" id="view">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="has-tooltip">True</property>
+ <property name="column-spacing">20</property>
+ <property name="margin">16</property>
+ <property name="activate-on-single-click">True</property>
+ <property name="selection-mode">none</property>
+ <style>
+ <class name="content-view" />
+ </style>
+ <child>
+ <object class="GtkCellRendererPixbuf">
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ </object>
+ <attributes>
+ <attribute name="surface">3</attribute>
+ </attributes>
+ </child>
+ <child>
+ <object class="GdTwoLinesRenderer">
+ <property name="xalign">0.5</property>
+ <property name="alignment">center</property>
+ <property name="wrap-mode">2</property>
+ <property name="wrap-width">128</property>
+ <property name="text-lines">3</property>
+ </object>
+ <attributes>
+ <attribute name="text">1</attribute>
+ <attribute name="line-two">2</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 37302a567..aefd7586e 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -23,6 +23,7 @@
<file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">evince-menus.ui</file>
<file alias="ui/password-view.ui" compressed="true"
preprocess="xml-stripblanks">evince-password-view.ui</file>
<file alias="ui/properties-fonts.ui" compressed="true"
preprocess="xml-stripblanks">evince-properties-fonts.ui</file>
+ <file alias="ui/recent-view.ui" compressed="true"
preprocess="xml-stripblanks">evince-recent-view.ui</file>
<file alias="ui/zoom-action.ui" compressed="true"
preprocess="xml-stripblanks">evince-zoom-action.ui</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]