[evince/wip/gpoo/print-preview-ui] previewer: Use GtkHeaderBar in print preview



commit dc24a0143ebc0521b4e40010fa11540be8a2e599
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Wed Oct 31 17:19:57 2018 -0300

    previewer: Use GtkHeaderBar in print preview
    
    * Makes the UI looks like the main application
    * Replace and remove deprecated widgets
    
    Fixes #405

 previewer/Makefile.am             |   3 +-
 previewer/ev-previewer-toolbar.c  | 308 ++++++++++++++++++++++++++++++++++++++
 previewer/ev-previewer-toolbar.h  |  57 +++++++
 previewer/ev-previewer-window.c   | 294 +++++++++++++-----------------------
 previewer/ev-previewer-window.h   |   2 +
 previewer/meson.build             |   2 +-
 previewer/previewer-ui.xml        |  28 ----
 previewer/previewer.gresource.xml |   1 -
 8 files changed, 473 insertions(+), 222 deletions(-)
---
diff --git a/previewer/Makefile.am b/previewer/Makefile.am
index 6d12709b..82ea14ae 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,6 @@ ev-previewer-resources.c: previewer.gresource.xml Makefile $(shell $(GLIB_COMPIL
 EXTRA_DIST = \
        previewer.gresource.xml \
        evince-previewer.css \
-       previewer-ui.xml \
        $(NULL)
 
 CLEANFILES = \
diff --git a/previewer/ev-previewer-toolbar.c b/previewer/ev-previewer-toolbar.c
new file mode 100644
index 00000000..6bd862c7
--- /dev/null
+++ b/previewer/ev-previewer-toolbar.c
@@ -0,0 +1,308 @@
+/* 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_set_button_action (EvPreviewerToolbar   *ev_previewer_toolbar,
+                              GtkButton   *button,
+                              const gchar *action_name,
+                              const gchar *tooltip)
+{
+        gtk_actionable_set_action_name (GTK_ACTIONABLE (button), action_name);
+        gtk_button_set_label (button, NULL);
+        gtk_widget_set_focus_on_click (GTK_WIDGET (button), FALSE);
+        if (tooltip)
+                gtk_widget_set_tooltip_text (GTK_WIDGET (button), tooltip);
+}
+
+static GtkWidget *
+ev_previewer_toolbar_create_button (EvPreviewerToolbar   *ev_previewer_toolbar,
+                          const gchar *action_name,
+                          const gchar *icon_name,
+                          const gchar *label,
+                          const gchar *tooltip)
+{
+        GtkWidget *button = gtk_button_new ();
+        GtkWidget *image;
+
+        image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+
+        gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
+        if (icon_name)
+                gtk_button_set_image (GTK_BUTTON (button), image);
+        if (label)
+                gtk_button_set_label (GTK_BUTTON (button), label);
+        ev_previewer_toolbar_set_button_action (ev_previewer_toolbar, GTK_BUTTON (button), action_name, 
tooltip);
+
+        return button;
+}
+
+static void
+ev_previewer_toolbar_constructed (GObject *object)
+{
+        EvPreviewerToolbar *ev_previewer_toolbar = EV_PREVIEWER_TOOLBAR (object);
+        GtkWidget     *tool_item;
+        GtkWidget     *button;
+        GtkWidget     *hbox;
+        GtkAccelGroup *accel_group;
+
+        /* Shortcuts, just for reference.
+       const gchar *action_accels[] = {
+               "preview.select-page",      "<Ctrl>L", NULL,
+               "preview.go-previous-page", "p", "<Ctrl>Page_Up", NULL,
+               "preview.go-next-page",     "n", "<Ctrl>Page_Down", NULL,
+               "preview.print",            "<Ctrl>P", NULL,
+               "preview.zoom-in",          "plus", "<Ctrl>plus", "KP_Add", "<Ctrl>KP_Add", "equal", 
"<Ctrl>equal", NULL,
+               "preview.zoom-out",         "minus", "<Ctrl>minus", "KP_Subtract", "<Ctrl>KP_Subtract", NULL,
+               "preview.zoom-default",     "a", NULL,
+               NULL,
+       };
+         */
+
+        G_OBJECT_CLASS (ev_previewer_toolbar_parent_class)->constructed (object);
+
+        accel_group = gtk_accel_group_new ();
+        gtk_window_add_accel_group (GTK_WINDOW (ev_previewer_toolbar->priv->window),
+                                    accel_group);
+
+        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 = ev_previewer_toolbar_create_button (ev_previewer_toolbar,
+                                                     "preview.go-previous-page",
+                                                     "go-previous-symbolic",
+                                                     NULL,
+                                                     _("Previous Page"));
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_p, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_Page_Up, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        ev_previewer_toolbar->priv->previous_button = button;
+        gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+        gtk_widget_show (button);
+
+        button = ev_previewer_toolbar_create_button (ev_previewer_toolbar,
+                                                     "preview.go-next-page",
+                                                     "go-next-symbolic",
+                                                     NULL,
+                                                     _("Next Page"));
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_n, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_Page_Down, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        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 */
+        /* Use EvPageActionWidget for now, since the page selector action is also used by the previewer */
+        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"));
+        /* FIXME: Add accelerator for grabing the focus in the EvPageActionWidget's entry */
+        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 = ev_previewer_toolbar_create_button (ev_previewer_toolbar,
+                                                     "preview.print",
+                                                     NULL,
+                                                     _("Print"),
+                                                     _("Print this document"));
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_p, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        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 = ev_previewer_toolbar_create_button (ev_previewer_toolbar,
+                                                     "preview.zoom-in",
+                                                     "zoom-in-symbolic",
+                                                     NULL,
+                                                     _("Enlarge the document"));
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_plus, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_plus, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_KP_Add, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_KP_Add, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_equal, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_equal, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_plus, 0, GTK_ACCEL_VISIBLE);
+        ev_previewer_toolbar->priv->zoom_in_button = button;
+        gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+        gtk_widget_show (button);
+
+        button = ev_previewer_toolbar_create_button (ev_previewer_toolbar,
+                                                     "preview.zoom-default",
+                                                     "zoom-fit-best-symbolic",
+                                                     NULL,
+                                                     _("Reset zoom and make the page fit in the window"));
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_a, 0, GTK_ACCEL_VISIBLE);
+        ev_previewer_toolbar->priv->zoom_default_button = button;
+        gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+        gtk_widget_show (button);
+
+        button = ev_previewer_toolbar_create_button (ev_previewer_toolbar,
+                                                     "preview.zoom-out",
+                                                     "zoom-out-symbolic",
+                                                     NULL,
+                                                     _("Shrink the document"));
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_minus, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_minus, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_KP_Subtract, 0, GTK_ACCEL_VISIBLE);
+        gtk_widget_add_accelerator (button, "activate", accel_group,
+                                    GDK_KEY_KP_Subtract, GDK_CONTROL_MASK,
+                                    GTK_ACCEL_VISIBLE);
+        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);
+}
+
+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..ac09b89d 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,9 +37,8 @@ struct _EvPreviewerWindow {
        EvDocumentModel  *model;
        EvDocument       *document;
 
-       GtkActionGroup   *action_group;
+       GSimpleActionGroup *action_group;
        GtkActionGroup   *accels_group;
-       GtkUIManager     *ui_manager;
 
        GtkWidget        *swindow;
        EvView           *view;
@@ -97,78 +98,88 @@ 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);
+       GAction *page_action;
 
-       page_action = gtk_action_group_get_action (window->action_group,
-                                                  "PageSelector");
-       ev_page_action_grab_focus (EV_PAGE_ACTION (page_action));
+       page_action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group),
+                                                 "page-selector");
+       ev_page_action_widget_grab_focus (EV_PAGE_ACTION_WIDGET (page_action));
 }
 
 #if GTKUNIXPRINT_ENABLED
@@ -222,8 +233,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 +259,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,63 +276,15 @@ 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 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 const GActionEntry action_entries[] = {
+       { "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 gboolean
@@ -327,9 +292,10 @@ view_focus_changed (GtkWidget         *widget,
                    GdkEventFocus     *event,
                    EvPreviewerWindow *window)
 {
+       /* FIXME
        if (window->accels_group)
                gtk_action_group_set_sensitive (window->accels_group, event->in);
-
+       */
        return FALSE;
 }
 
@@ -339,14 +305,17 @@ 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));
+       GAction *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 = g_action_map_lookup_action (G_ACTION_MAP (window->action_group),
+                                            "go-previous-page");
+       g_simple_action_set_enabled (G_SIMPLE_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);
+       action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group),
+                                            "go-next-page");
+       g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+                                    new_page < n_pages - 1);
 }
 
 static void
@@ -355,27 +324,12 @@ view_sizing_mode_changed (EvDocumentModel   *model,
                          EvPreviewerWindow *window)
 {
        EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
-       GtkAction   *action;
+       GAction   *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);
+       action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group),
+                                            "zoom-default");
+       g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+                                    sizing_mode != EV_SIZING_AUTOMATIC);
 }
 
 static void
@@ -390,20 +344,10 @@ ev_previewer_window_set_document (EvPreviewerWindow *window,
        g_signal_connect (model, "notify::sizing-mode",
                          G_CALLBACK (view_sizing_mode_changed),
                          window);
+       /* FIXME
        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
@@ -431,11 +375,6 @@ ev_previewer_window_dispose (GObject *object)
                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;
@@ -519,7 +458,6 @@ ev_previewer_window_constructor (GType                  type,
        EvPreviewerWindow *window;
        GtkWidget         *vbox;
        GtkWidget         *toolbar;
-       GtkAction         *action;
        GError            *error = NULL;
        gdouble            dpi;
         GtkCssProvider    *css_provider;
@@ -532,40 +470,17 @@ 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);
+       window->action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (window->action_group),
+                                        action_entries, G_N_ELEMENTS (action_entries),
+                                        window);
+        gtk_widget_insert_action_group (GTK_WIDGET (window), "preview",
+                                       G_ACTION_GROUP (window->action_group));
 
         css_provider = gtk_css_provider_new ();
         _gtk_css_provider_load_from_resource (css_provider,
@@ -577,32 +492,21 @@ 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);
+       toolbar = ev_previewer_toolbar_new (window);
+       gtk_widget_set_no_show_all (toolbar, TRUE);
+       gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (toolbar), TRUE);
+       gtk_window_set_titlebar (GTK_WINDOW (window), toolbar);
        gtk_widget_show (toolbar);
 
+       g_signal_connect (ev_previewer_toolbar_get_page_selector (EV_PREVIEWER_TOOLBAR (toolbar)),
+                         "activate-link",
+                         G_CALLBACK (ev_previewer_window_action_page_activated),
+                         window);
+
        window->swindow = gtk_scrolled_window_new (NULL, NULL);
 
        window->view = EV_VIEW (ev_view_new ());
@@ -725,3 +629,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/meson.build b/previewer/meson.build
index c2f87fbc..8522633a 100644
--- a/previewer/meson.build
+++ b/previewer/meson.build
@@ -1,12 +1,12 @@
 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',
 )
 
 sources += gnome.compile_resources(
diff --git a/previewer/previewer.gresource.xml b/previewer/previewer.gresource.xml
index 2d8e7fa2..d2234eed 100644
--- a/previewer/previewer.gresource.xml
+++ b/previewer/previewer.gresource.xml
@@ -17,7 +17,6 @@
 -->
 <gresources>
   <gresource prefix="/org/gnome/evince/previewer">
-    <file alias="ui/previewer.xml" compressed="true" preprocess="xml-stripblanks">previewer-ui.xml</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>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]