[evince/wip/gpoo/print-preview-ui: 2/6] previewer: Use GtkHeaderBar in print preview
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/print-preview-ui: 2/6] previewer: Use GtkHeaderBar in print preview
- Date: Thu, 8 Nov 2018 17:17:45 +0000 (UTC)
commit 898b55518ada1a53730d2f4bbfb047f779fdbd87
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Thu Nov 8 11:35:25 2018 -0300
previewer: Use GtkHeaderBar in print preview
* Makes the UI looks like the main application
* Replace and remove deprecated widgets
Addresses issues on #405
previewer/Makefile.am | 4 +-
previewer/ev-previewer-toolbar.c | 193 ++++++++++++++++++++++
previewer/ev-previewer-toolbar.h | 57 +++++++
previewer/ev-previewer-window.c | 335 +++++++++++++-------------------------
previewer/ev-previewer-window.h | 2 +
previewer/ev-previewer.c | 15 ++
previewer/meson.build | 3 +-
previewer/previewer-ui.xml | 28 ----
previewer/previewer.gresource.xml | 2 +-
previewer/previewer.ui | 78 +++++++++
10 files changed, 463 insertions(+), 254 deletions(-)
---
diff --git a/previewer/Makefile.am b/previewer/Makefile.am
index 6d12709b..50c814bd 100644
--- a/previewer/Makefile.am
+++ b/previewer/Makefile.am
@@ -4,6 +4,8 @@ bin_PROGRAMS = evince-previewer
evince_previewer_SOURCES = \
ev-previewer.c \
+ ev-previewer-toolbar.h \
+ ev-previewer-toolbar.c \
ev-previewer-window.h \
ev-previewer-window.c \
$(NULL)
@@ -42,7 +44,7 @@ ev-previewer-resources.c: previewer.gresource.xml Makefile $(shell $(GLIB_COMPIL
EXTRA_DIST = \
previewer.gresource.xml \
evince-previewer.css \
- previewer-ui.xml \
+ previewer.ui \
$(NULL)
CLEANFILES = \
diff --git a/previewer/ev-previewer-toolbar.c b/previewer/ev-previewer-toolbar.c
new file mode 100644
index 00000000..2d0fd1ad
--- /dev/null
+++ b/previewer/ev-previewer-toolbar.c
@@ -0,0 +1,193 @@
+/* ev-toolbar.h
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012-2014 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2014-2018 Germán Poo-Caamaño <gpoo gnome org>
+ *
+ * Evince 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n.h>
+
+#include "ev-previewer-toolbar.h"
+
+/*
+#include "ev-stock-icons.h"
+#include "ev-zoom-action.h"
+#include "ev-application.h"
+ */
+#include "ev-page-action-widget.h"
+#include <math.h>
+
+enum
+{
+ PROP_0,
+ PROP_WINDOW
+};
+
+struct _EvPreviewerToolbarPrivate {
+ EvPreviewerWindow *window;
+
+ GtkWidget *page_selector;
+ GtkWidget *print_button;
+ GtkWidget *previous_button;
+ GtkWidget *next_button;
+ GtkWidget *zoom_in_button;
+ GtkWidget *zoom_out_button;
+ GtkWidget *zoom_default_button;
+};
+
+G_DEFINE_TYPE (EvPreviewerToolbar, ev_previewer_toolbar, GTK_TYPE_HEADER_BAR)
+
+static void
+ev_previewer_toolbar_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EvPreviewerToolbar *ev_previewer_toolbar = EV_PREVIEWER_TOOLBAR (object);
+
+ switch (prop_id) {
+ case PROP_WINDOW:
+ ev_previewer_toolbar->priv->window = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ev_previewer_toolbar_constructed (GObject *object)
+{
+ EvPreviewerToolbar *ev_previewer_toolbar = EV_PREVIEWER_TOOLBAR (object);
+ GtkWidget *tool_item;
+ GtkWidget *button;
+ GtkWidget *hbox;
+ GtkBuilder *builder;
+
+ G_OBJECT_CLASS (ev_previewer_toolbar_parent_class)->constructed (object);
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/evince/previewer/ui/previewer.ui");
+
+ hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_EXPAND);
+ gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
+
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "go-previous-page"));
+ ev_previewer_toolbar->priv->previous_button = button;
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "go-next-page"));
+ ev_previewer_toolbar->priv->next_button = button;
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_previewer_toolbar), hbox);
+ gtk_widget_show (hbox);
+
+ /* Page selector */
+ tool_item = GTK_WIDGET (g_object_new (EV_TYPE_PAGE_ACTION_WIDGET, NULL));
+ gtk_widget_set_tooltip_text (tool_item, _("Select page or search in the index"));
+ atk_object_set_name (gtk_widget_get_accessible (tool_item), _("Select page"));
+ ev_page_action_widget_set_model (EV_PAGE_ACTION_WIDGET (tool_item),
+ ev_previewer_window_get_document_model
(ev_previewer_toolbar->priv->window));
+ ev_previewer_toolbar->priv->page_selector = tool_item;
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_previewer_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+
+ /* Print */
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "print"));
+ ev_previewer_toolbar->priv->print_button = button;
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_previewer_toolbar), button);
+ gtk_widget_show (button);
+
+ /* Zoom */
+ hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_EXPAND);
+ gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
+
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-in"));
+ ev_previewer_toolbar->priv->zoom_in_button = button;
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-default"));
+ ev_previewer_toolbar->priv->zoom_default_button = button;
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-out"));
+ ev_previewer_toolbar->priv->zoom_out_button = button;
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
+
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_previewer_toolbar), hbox);
+
+ gtk_widget_show (hbox);
+
+ g_object_unref (builder);
+}
+
+static void
+ev_previewer_toolbar_class_init (EvPreviewerToolbarClass *klass)
+{
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->set_property = ev_previewer_toolbar_set_property;
+ g_object_class->constructed = ev_previewer_toolbar_constructed;
+
+ g_object_class_install_property (g_object_class,
+ PROP_WINDOW,
+ g_param_spec_object ("window",
+ "Window",
+ "The evince previewer window",
+ EV_TYPE_PREVIEWER_WINDOW,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_type_class_add_private (g_object_class, sizeof (EvPreviewerToolbarPrivate));
+}
+
+static void
+ev_previewer_toolbar_init (EvPreviewerToolbar *ev_previewer_toolbar)
+{
+ ev_previewer_toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (ev_previewer_toolbar,
EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbarPrivate);
+}
+
+GtkWidget *
+ev_previewer_toolbar_new (EvPreviewerWindow *window)
+{
+ g_return_val_if_fail (EV_IS_PREVIEWER_WINDOW (window), NULL);
+
+ return GTK_WIDGET (g_object_new (EV_TYPE_PREVIEWER_TOOLBAR,
+ "window", window,
+ NULL));
+}
+
+GtkWidget *
+ev_previewer_toolbar_get_page_selector (EvPreviewerToolbar *ev_previewer_toolbar)
+{
+ g_return_val_if_fail (EV_IS_PREVIEWER_TOOLBAR (ev_previewer_toolbar), NULL);
+
+ return ev_previewer_toolbar->priv->page_selector;
+}
diff --git a/previewer/ev-previewer-toolbar.h b/previewer/ev-previewer-toolbar.h
new file mode 100644
index 00000000..1bf61546
--- /dev/null
+++ b/previewer/ev-previewer-toolbar.h
@@ -0,0 +1,57 @@
+/* ev-toolbar.h
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2018 Germán Poo-Caamaño <gpoo gnome org>
+ *
+ * Evince 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __EV_PREVIEWER_TOOLBAR_H__
+#define __EV_PREVIEWER_TOOLBAR_H__
+
+#include <gtk/gtk.h>
+#include "ev-previewer-window.h"
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_PREVIEWER_TOOLBAR (ev_previewer_toolbar_get_type())
+#define EV_PREVIEWER_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_CAST((object),
EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbar))
+#define EV_IS_PREVIEWER_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_TYPE((object),
EV_TYPE_PREVIEWER_TOOLBAR))
+#define EV_PREVIEWER_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PREVIEWER_TOOLBAR,
EvPreviewerToolbarClass))
+#define EV_IS_PREVIEWER_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PREVIEWER_TOOLBAR))
+#define EV_PREVIEWER_TOOLBAR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object),
EV_TYPE_PREVIEWER_TOOLBAR, EvPreviewerToolbarClass))
+
+typedef struct _EvPreviewerToolbar EvPreviewerToolbar;
+typedef struct _EvPreviewerToolbarClass EvPreviewerToolbarClass;
+typedef struct _EvPreviewerToolbarPrivate EvPreviewerToolbarPrivate;
+
+struct _EvPreviewerToolbar {
+ GtkHeaderBar base_instance;
+
+ EvPreviewerToolbarPrivate *priv;
+};
+
+struct _EvPreviewerToolbarClass {
+ GtkHeaderBarClass base_class;
+};
+
+GType ev_previewer_toolbar_get_type (void);
+GtkWidget *ev_previewer_toolbar_new (EvPreviewerWindow *window);
+GtkWidget *ev_previewer_toolbar_get_page_selector (EvPreviewerToolbar *ev_previewer_toolbar);
+
+G_END_DECLS
+
+#endif /* __EV_PREVIEWER_TOOLBAR_H__ */
diff --git a/previewer/ev-previewer-window.c b/previewer/ev-previewer-window.c
index c39972cc..7984b8d1 100644
--- a/previewer/ev-previewer-window.c
+++ b/previewer/ev-previewer-window.c
@@ -2,6 +2,7 @@
* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2009 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2018 Germán Poo-Caamaño <gpoo gnome org>
*
* Evince is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
@@ -25,9 +26,10 @@
#endif
#include <glib/gi18n.h>
#include <evince-view.h>
-#include "ev-page-action.h"
+#include "ev-page-action-widget.h"
#include "ev-previewer-window.h"
+#include "ev-previewer-toolbar.h"
struct _EvPreviewerWindow {
GtkApplicationWindow base_instance;
@@ -35,13 +37,10 @@ struct _EvPreviewerWindow {
EvDocumentModel *model;
EvDocument *document;
- GtkActionGroup *action_group;
- GtkActionGroup *accels_group;
- GtkUIManager *ui_manager;
-
- GtkWidget *swindow;
EvView *view;
- gdouble dpi;
+
+ GtkWidget *toolbar;
+ GSimpleActionGroup *action_group;
/* Printing */
GtkPrintSettings *print_settings;
@@ -97,78 +96,87 @@ ev_previewer_window_error_dialog_run (EvPreviewerWindow *window,
#endif
static void
-ev_previewer_window_close (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_close (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+
gtk_widget_destroy (GTK_WIDGET (window));
}
static void
-ev_previewer_window_previous_page (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_previous_page (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+
ev_view_previous_page (window->view);
}
static void
-ev_previewer_window_next_page (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_next_page (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+
ev_view_next_page (window->view);
}
static void
-ev_previewer_window_zoom_in (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_zoom_in (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+
ev_document_model_set_sizing_mode (window->model, EV_SIZING_FREE);
ev_view_zoom_in (window->view);
}
static void
-ev_previewer_window_zoom_out (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_zoom_out (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+
ev_document_model_set_sizing_mode (window->model, EV_SIZING_FREE);
ev_view_zoom_out (window->view);
}
static void
-ev_previewer_window_zoom_fit_page (GtkToggleAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_zoom_default (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
- ev_document_model_set_sizing_mode (window->model,
- gtk_toggle_action_get_active (action) ?
- EV_SIZING_FIT_PAGE : EV_SIZING_FREE);
-}
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
-static void
-ev_previewer_window_zoom_fit_width (GtkToggleAction *action,
- EvPreviewerWindow *window)
-{
ev_document_model_set_sizing_mode (window->model,
- gtk_toggle_action_get_active (action) ?
- EV_SIZING_FIT_WIDTH : EV_SIZING_FREE);
+ EV_SIZING_AUTOMATIC);
}
static void
ev_previewer_window_action_page_activated (GtkAction *action,
- EvLink *link,
- EvPreviewerWindow *window)
+ EvLink *link,
+ EvPreviewerWindow *window)
{
- ev_view_handle_link (window->view, link);
- gtk_widget_grab_focus (GTK_WIDGET (window->view));
+ ev_view_handle_link (window->view, link);
+ gtk_widget_grab_focus (GTK_WIDGET (window->view));
}
static void
-ev_previewer_window_focus_page_selector (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_focus_page_selector (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
- GtkAction *page_action;
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+ GtkWidget *page_selector;
- page_action = gtk_action_group_get_action (window->action_group,
- "PageSelector");
- ev_page_action_grab_focus (EV_PAGE_ACTION (page_action));
+ page_selector = ev_previewer_toolbar_get_page_selector (EV_PREVIEWER_TOOLBAR (window->toolbar));
+ ev_page_action_widget_grab_focus (EV_PAGE_ACTION_WIDGET (page_selector));
}
#if GTKUNIXPRINT_ENABLED
@@ -222,8 +230,7 @@ ev_previewer_window_enumerate_finished (EvPreviewerWindow *window)
GTK_PRINT_ERROR_GENERAL,
_("The selected printer “%s” could not be found"),
gtk_print_settings_get_printer (window->print_settings));
-
- ev_previewer_window_error_dialog_run (window, error);
+
g_error_free (error);
}
}
@@ -249,9 +256,12 @@ ev_previewer_window_enumerate_printers (GtkPrinter *printer,
}
static void
-ev_previewer_window_print (GtkAction *action,
- EvPreviewerWindow *window)
+ev_previewer_window_print (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (user_data);
+
if (!window->print_settings)
window->print_settings = gtk_print_settings_new ();
if (!window->print_page_setup)
@@ -263,74 +273,26 @@ ev_previewer_window_print (GtkAction *action,
}
#endif
-static const GtkActionEntry action_entries[] = {
- { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
- NULL,
- G_CALLBACK (ev_previewer_window_close) },
- { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
- N_("Go to the previous page"),
- G_CALLBACK (ev_previewer_window_previous_page) },
- { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
- N_("Go to the next page"),
- G_CALLBACK (ev_previewer_window_next_page) },
- { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
- N_("Enlarge the document"),
- G_CALLBACK (ev_previewer_window_zoom_in) },
- { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
- N_("Shrink the document"),
- G_CALLBACK (ev_previewer_window_zoom_out) },
-#if GTKUNIXPRINT_ENABLED
- /* translators: Print document currently shown in the Print Preview window */
- { "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,
- N_("Print this document"),
- G_CALLBACK (ev_previewer_window_print) }
-#endif
-};
-
-static const GtkActionEntry accel_entries[] = {
- { "p", GTK_STOCK_GO_UP, "", "p", NULL,
- G_CALLBACK (ev_previewer_window_previous_page) },
- { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
- G_CALLBACK (ev_previewer_window_next_page) },
- { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
- G_CALLBACK (ev_previewer_window_zoom_in) },
- { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
- G_CALLBACK (ev_previewer_window_zoom_in) },
- { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
- G_CALLBACK (ev_previewer_window_zoom_in) },
- { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
- G_CALLBACK (ev_previewer_window_zoom_out) },
- { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
- G_CALLBACK (ev_previewer_window_zoom_in) },
- { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
- G_CALLBACK (ev_previewer_window_zoom_out) },
- { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
- G_CALLBACK (ev_previewer_window_zoom_in) },
- { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
- G_CALLBACK (ev_previewer_window_zoom_out) },
- { "FocusPageSelector", NULL, "", "<control>l", NULL,
- G_CALLBACK (ev_previewer_window_focus_page_selector) }
-
+static const GActionEntry actions[] = {
+ { "print", ev_previewer_window_print },
+ { "go-previous-page", ev_previewer_window_previous_page },
+ { "go-next-page", ev_previewer_window_next_page },
+ { "select-page", ev_previewer_window_focus_page_selector },
+ { "zoom-in", ev_previewer_window_zoom_in },
+ { "zoom-out", ev_previewer_window_zoom_out },
+ { "close", ev_previewer_window_close },
+ { "zoom-default", ev_previewer_window_zoom_default },
};
-static const GtkToggleActionEntry toggle_action_entries[] = {
- { "ViewFitPage", EV_STOCK_ZOOM_PAGE, N_("Fit Pa_ge"), NULL,
- N_("Make the current document fill the window"),
- G_CALLBACK (ev_previewer_window_zoom_fit_page) },
- { "ViewFitWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit _Width"), NULL,
- N_("Make the current document fill the window width"),
- G_CALLBACK (ev_previewer_window_zoom_fit_width) }
-};
-
-static gboolean
-view_focus_changed (GtkWidget *widget,
- GdkEventFocus *event,
- EvPreviewerWindow *window)
+static void
+ev_previewer_window_set_action_enabled (EvPreviewerWindow *window,
+ const char *name,
+ gboolean enabled)
{
- if (window->accels_group)
- gtk_action_group_set_sensitive (window->accels_group, event->in);
+ GAction *action;
- return FALSE;
+ action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group), name);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
}
static void
@@ -339,14 +301,14 @@ model_page_changed (EvDocumentModel* model,
gint new_page,
EvPreviewerWindow *window)
{
- GtkAction *action;
- gint n_pages = ev_document_get_n_pages (ev_document_model_get_document (window->model));
-
- action = gtk_action_group_get_action (window->action_group, "GoPreviousPage");
- gtk_action_set_sensitive (GTK_ACTION (action), new_page > 0 );
-
- action = gtk_action_group_get_action (window->action_group, "GoNextPage");
- gtk_action_set_sensitive (GTK_ACTION (action), new_page < n_pages - 1);
+ gint n_pages = ev_document_get_n_pages (ev_document_model_get_document (window->model));
+
+ ev_previewer_window_set_action_enabled (window,
+ "go-previous-page",
+ new_page > 0);
+ ev_previewer_window_set_action_enabled (window,
+ "go-next-page",
+ new_page < n_pages - 1);
}
static void
@@ -355,27 +317,10 @@ view_sizing_mode_changed (EvDocumentModel *model,
EvPreviewerWindow *window)
{
EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
- GtkAction *action;
- action = gtk_action_group_get_action (window->action_group, "ViewFitPage");
- g_signal_handlers_block_by_func (action,
- G_CALLBACK (ev_previewer_window_zoom_fit_page),
- window);
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- sizing_mode == EV_SIZING_FIT_PAGE);
- g_signal_handlers_unblock_by_func (action,
- G_CALLBACK (ev_previewer_window_zoom_fit_page),
- window);
-
- action = gtk_action_group_get_action (window->action_group, "ViewFitWidth");
- g_signal_handlers_block_by_func (action,
- G_CALLBACK (ev_previewer_window_zoom_fit_width),
- window);
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- sizing_mode == EV_SIZING_FIT_WIDTH);
- g_signal_handlers_unblock_by_func (action,
- G_CALLBACK (ev_previewer_window_zoom_fit_width),
- window);
+ ev_previewer_window_set_action_enabled (window,
+ "zoom-default",
+ sizing_mode != EV_SIZING_AUTOMATIC);
}
static void
@@ -390,20 +335,6 @@ ev_previewer_window_set_document (EvPreviewerWindow *window,
g_signal_connect (model, "notify::sizing-mode",
G_CALLBACK (view_sizing_mode_changed),
window);
- gtk_action_group_set_sensitive (window->action_group, TRUE);
- gtk_action_group_set_sensitive (window->accels_group, TRUE);
-}
-
-static void
-ev_previewer_window_connect_action_accelerators (EvPreviewerWindow *window)
-{
- GList *actions;
-
- gtk_ui_manager_ensure_update (window->ui_manager);
-
- actions = gtk_action_group_list_actions (window->action_group);
- g_list_foreach (actions, (GFunc)gtk_action_connect_accelerator, NULL);
- g_list_free (actions);
}
static void
@@ -426,16 +357,6 @@ ev_previewer_window_dispose (GObject *object)
window->action_group = NULL;
}
- if (window->accels_group) {
- g_object_unref (window->accels_group);
- window->accels_group = NULL;
- }
-
- if (window->ui_manager) {
- g_object_unref (window->ui_manager);
- window->ui_manager = NULL;
- }
-
if (window->print_settings) {
g_object_unref (window->print_settings);
window->print_settings = NULL;
@@ -470,6 +391,13 @@ static void
ev_previewer_window_init (EvPreviewerWindow *window)
{
gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
+
+ window->action_group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (window->action_group),
+ actions, G_N_ELEMENTS (actions),
+ window);
+ gtk_widget_insert_action_group (GTK_WIDGET (window), "win",
+ G_ACTION_GROUP (window->action_group));
}
static void
@@ -518,8 +446,7 @@ ev_previewer_window_constructor (GType type,
GObject *object;
EvPreviewerWindow *window;
GtkWidget *vbox;
- GtkWidget *toolbar;
- GtkAction *action;
+ GtkWidget *swindow;
GError *error = NULL;
gdouble dpi;
GtkCssProvider *css_provider;
@@ -532,41 +459,11 @@ ev_previewer_window_constructor (GType type,
dpi = get_screen_dpi (window);
ev_document_model_set_min_scale (window->model, MIN_SCALE * dpi / 72.0);
ev_document_model_set_max_scale (window->model, MAX_SCALE * dpi / 72.0);
- ev_document_model_set_sizing_mode (window->model, EV_SIZING_FIT_WIDTH);
+ ev_document_model_set_sizing_mode (window->model, EV_SIZING_AUTOMATIC);
g_signal_connect_swapped (window->model, "notify::document",
G_CALLBACK (ev_previewer_window_set_document),
window);
- window->action_group = gtk_action_group_new ("PreviewerActions");
- gtk_action_group_set_translation_domain (window->action_group, NULL);
- gtk_action_group_add_actions (window->action_group, action_entries,
- G_N_ELEMENTS (action_entries),
- window);
- gtk_action_group_add_toggle_actions (window->action_group, toggle_action_entries,
- G_N_ELEMENTS (toggle_action_entries),
- window);
- gtk_action_group_set_sensitive (window->action_group, FALSE);
-
- action = g_object_new (EV_TYPE_PAGE_ACTION,
- "name", "PageSelector",
- "label", _("Page"),
- "tooltip", _("Select Page"),
- "icon_name", "text-x-generic",
- "visible_overflown", FALSE,
- NULL);
- ev_page_action_set_model (EV_PAGE_ACTION (action), window->model);
- g_signal_connect (action, "activate_link",
- G_CALLBACK (ev_previewer_window_action_page_activated),
- window);
- gtk_action_group_add_action (window->action_group, action);
- g_object_unref (action);
-
- window->accels_group = gtk_action_group_new ("PreviewerAccelerators");
- gtk_action_group_add_actions (window->accels_group, accel_entries,
- G_N_ELEMENTS (accel_entries),
- window);
- gtk_action_group_set_sensitive (window->accels_group, FALSE);
-
css_provider = gtk_css_provider_new ();
_gtk_css_provider_load_from_resource (css_provider,
"/org/gnome/evince/previewer/ui/evince-previewer.css",
@@ -577,41 +474,25 @@ ev_previewer_window_constructor (GType type,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (css_provider);
- window->ui_manager = gtk_ui_manager_new ();
- gtk_ui_manager_insert_action_group (window->ui_manager,
- window->action_group, 0);
- gtk_ui_manager_insert_action_group (window->ui_manager,
- window->accels_group, 1);
- gtk_window_add_accel_group (GTK_WINDOW (window),
- gtk_ui_manager_get_accel_group (window->ui_manager));
-
- gtk_ui_manager_add_ui_from_resource (window->ui_manager,
"/org/gnome/evince/previewer/ui/previewer.xml", &error);
- g_assert_no_error (error);
-
- /* GTKUIManager connects actions accels only for menu items,
- * but not for tool items. See bug #612972.
- */
- ev_previewer_window_connect_action_accelerators (window);
-
view_sizing_mode_changed (window->model, NULL, window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/PreviewToolbar");
- gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
- GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
- gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
- gtk_widget_show (toolbar);
+ window->toolbar = ev_previewer_toolbar_new (window);
+ gtk_widget_set_no_show_all (window->toolbar, TRUE);
+ gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (window->toolbar),
+ TRUE);
+ gtk_window_set_titlebar (GTK_WINDOW (window), window->toolbar);
+ gtk_widget_show (window->toolbar);
+
+ g_signal_connect (ev_previewer_toolbar_get_page_selector (EV_PREVIEWER_TOOLBAR (window->toolbar)),
+ "activate-link",
+ G_CALLBACK (ev_previewer_window_action_page_activated),
+ window);
- window->swindow = gtk_scrolled_window_new (NULL, NULL);
+ swindow = gtk_scrolled_window_new (NULL, NULL);
window->view = EV_VIEW (ev_view_new ());
- g_signal_connect_object (window->view, "focus_in_event",
- G_CALLBACK (view_focus_changed),
- window, 0);
- g_signal_connect_object (window->view, "focus_out_event",
- G_CALLBACK (view_focus_changed),
- window, 0);
ev_view_set_model (window->view, window->model);
ev_document_model_set_continuous (window->model, FALSE);
@@ -619,11 +500,11 @@ ev_previewer_window_constructor (GType type,
G_CALLBACK (model_page_changed),
window, 0);
- gtk_container_add (GTK_CONTAINER (window->swindow), GTK_WIDGET (window->view));
+ gtk_container_add (GTK_CONTAINER (swindow), GTK_WIDGET (window->view));
gtk_widget_show (GTK_WIDGET (window->view));
- gtk_box_pack_start (GTK_BOX (vbox), window->swindow, TRUE, TRUE, 0);
- gtk_widget_show (window->swindow);
+ gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
+ gtk_widget_show (swindow);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
@@ -725,3 +606,11 @@ ev_previewer_window_set_source_file (EvPreviewerWindow *window,
g_free (window->source_file);
window->source_file = g_strdup (source_file);
}
+
+EvDocumentModel *
+ev_previewer_window_get_document_model (EvPreviewerWindow *window)
+{
+ g_return_val_if_fail (EV_PREVIEWER_WINDOW (window), NULL);
+
+ return window->model;
+}
diff --git a/previewer/ev-previewer-window.h b/previewer/ev-previewer-window.h
index 61f86320..7449e8f5 100644
--- a/previewer/ev-previewer-window.h
+++ b/previewer/ev-previewer-window.h
@@ -41,6 +41,8 @@ typedef struct _EvPreviewerWindowClass EvPreviewerWindowClass;
GType ev_previewer_window_get_type (void) G_GNUC_CONST;
EvPreviewerWindow *ev_previewer_window_new (EvDocumentModel *model);
+EvDocumentModel *ev_previewer_window_get_document_model (EvPreviewerWindow *window);
+
void ev_previewer_window_set_print_settings (EvPreviewerWindow *window,
const gchar *print_settings);
void ev_previewer_window_set_source_file (EvPreviewerWindow *window,
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index 343bc5de..9b54fd2f 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -142,6 +142,18 @@ main (gint argc, gchar **argv)
gchar *path;
int status = 1;
+ const gchar *action_accels[] = {
+ "win.select-page", "<Ctrl>L", NULL,
+ "win.go-previous-page", "p", "<Ctrl>Page_Up", NULL,
+ "win.go-next-page", "n", "<Ctrl>Page_Down", NULL,
+ "win.print", "<Ctrl>P", NULL,
+ "win.zoom-in", "plus", "<Ctrl>plus", "KP_Add", "<Ctrl>KP_Add", "equal",
"<Ctrl>equal", NULL,
+ "win.zoom-out", "minus", "<Ctrl>minus", "KP_Subtract", "<Ctrl>KP_Subtract", NULL,
+ "win.zoom-default", "a", NULL,
+ NULL,
+ };
+ const char **it;
+
#ifdef G_OS_WIN32
if (fileno (stdout) != -1 &&
_get_osfhandle (fileno (stdout)) != -1)
@@ -216,6 +228,9 @@ main (gint argc, gchar **argv)
g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
g_signal_connect (application, "open", G_CALLBACK (open_cb), NULL);
+ for (it = action_accels; it[0]; it += g_strv_length ((gchar **)it) + 1)
+ gtk_application_set_accels_for_action (GTK_APPLICATION (application), it[0], &it[1]);
+
status = g_application_run (G_APPLICATION (application), argc, argv);
if (unlink_temp_file)
diff --git a/previewer/meson.build b/previewer/meson.build
index c2f87fbc..38ae6680 100644
--- a/previewer/meson.build
+++ b/previewer/meson.build
@@ -1,12 +1,13 @@
sources = files(
'ev-previewer.c',
+ 'ev-previewer-toolbar.c',
'ev-previewer-window.c',
)
resource_data = files(
'../data/thumbnail-frame.png',
'evince-previewer.css',
- 'previewer-ui.xml',
+ 'previewer.ui',
)
sources += gnome.compile_resources(
diff --git a/previewer/previewer.gresource.xml b/previewer/previewer.gresource.xml
index 2d8e7fa2..26872ad2 100644
--- a/previewer/previewer.gresource.xml
+++ b/previewer/previewer.gresource.xml
@@ -17,7 +17,7 @@
-->
<gresources>
<gresource prefix="/org/gnome/evince/previewer">
- <file alias="ui/previewer.xml" compressed="true" preprocess="xml-stripblanks">previewer-ui.xml</file>
+ <file alias="ui/previewer.ui" compressed="true" preprocess="xml-stripblanks">previewer.ui</file>
<file alias="ui/evince-previewer.css" compressed="true">evince-previewer.css</file>
<file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
</gresource>
diff --git a/previewer/previewer.ui b/previewer/previewer.ui
new file mode 100644
index 00000000..0f1f3446
--- /dev/null
+++ b/previewer/previewer.ui
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<!--*- mode: xml -*-->
+<interface>
+ <requires lib="gtk+" version="3.22"/>
+ <object class="GtkButton" id="print">
+ <property name="label" translatable="yes">_Print</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Print this document</property>
+ <property name="action_name">win.print</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <object class="GtkButton" id="go-previous-page">
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Previous Page</property>
+ <property name="action_name">win.go-previous-page</property>
+ <property name="image">go-previous-symbolic</property>
+ </object>
+ <object class="GtkButton" id="go-next-page">
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Next Page</property>
+ <property name="action_name">win.go-next-page</property>
+ <property name="image">go-next-symbolic</property>
+ </object>
+ <object class="GtkButton" id="zoom-in">
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Enlarge the document</property>
+ <property name="action_name">win.zoom-in</property>
+ <property name="image">zoom-in-symbolic</property>
+ <property name="always_show_image">True</property>
+ </object>
+ <object class="GtkButton" id="zoom-out">
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Shrink the document</property>
+ <property name="action_name">win.zoom-out</property>
+ <property name="image">zoom-out-symbolic</property>
+ </object>
+ <object class="GtkButton" id="zoom-default">
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Reset zoom and make the page fit in the
window</property>
+ <property name="action_name">win.zoom-default</property>
+ <property name="image">zoom-default-symbolic</property>
+ </object>
+ <object class="GtkImage" id="go-previous-symbolic">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">go-previous-symbolic</property>
+ </object>
+ <object class="GtkImage" id="go-next-symbolic">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">go-next-symbolic</property>
+ </object>
+ <object class="GtkImage" id="zoom-in-symbolic">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">zoom-in-symbolic</property>
+ </object>
+ <object class="GtkImage" id="zoom-default-symbolic">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">zoom-fit-best-symbolic</property>
+ </object>
+ <object class="GtkImage" id="zoom-out-symbolic">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">zoom-out-symbolic</property>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]