[evince/wip/app: 11/19] previewer: Add app menu
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/app: 11/19] previewer: Add app menu
- Date: Fri, 29 Jun 2012 10:08:54 +0000 (UTC)
commit e430a4c1d8d2954ac2134a6c00c8ac5cf57cb584
Author: Christian Persch <chpe gnome org>
Date: Tue Jun 12 20:40:40 2012 +0200
previewer: Add app menu
https://bugzilla.gnome.org/show_bug.cgi?id=674937
po/POTFILES.in | 1 +
previewer/appmenu.ui | 68 +++++++++++++++++++++++++++++++++++++
previewer/ev-previewer-window.c | 34 +++++++++++++++++--
previewer/ev-previewer.c | 59 ++++++++++++++++++++++++++++++++
previewer/previewer-ui.xml | 2 +-
previewer/previewer.gresource.xml | 1 +
6 files changed, 161 insertions(+), 4 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0be2c8c..dc227e5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -26,6 +26,7 @@ data/evince.desktop.in.in
data/org.gnome.Evince.gschema.xml.in
previewer/ev-previewer.c
previewer/ev-previewer-window.c
+[type: gettext/glade]previewer/appmenu.ui
properties/ev-properties-main.c
properties/ev-properties-view.c
libmisc/ev-page-action.c
diff --git a/previewer/appmenu.ui b/previewer/appmenu.ui
new file mode 100644
index 0000000..ba40398
--- /dev/null
+++ b/previewer/appmenu.ui
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright  2012 Christian Persch
+
+ This program 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, or (at your option)
+ any later version.
+
+ This program is distributed in the hope conf 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-->
+<interface>
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Print</attribute>
+ <attribute name="action">app.print</attribute>
+ <attribute name="accel"><Primary>p</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Previous Page</attribute>
+ <attribute name="action">app.page-previous</attribute>
+ <attribute name="accel"><Primary>Page_Up</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Next Page</attribute>
+ <attribute name="action">app.page-next</attribute>
+ <attribute name="accel"><Primary>Page_Down</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Best Fit</attribute>
+ <attribute name="action">app.zoom-best-fit</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Fit Page _Width</attribute>
+ <attribute name="action">app.zoom-page-width</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Zoom I_n</attribute>
+ <attribute name="action">app.zoom-in</attribute>
+ <attribute name="accel"><Primary>plus</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Zoom _Out</attribute>
+ <attribute name="action">app.zoom-out</attribute>
+ <attribute name="accel"><Primary>minus</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Close</attribute>
+ <attribute name="action">app.close</attribute>
+ <attribute name="accel"><Primary>w</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/previewer/ev-previewer-window.c b/previewer/ev-previewer-window.c
index 615cf32..140d4f0 100644
--- a/previewer/ev-previewer-window.c
+++ b/previewer/ev-previewer-window.c
@@ -61,7 +61,8 @@ struct _EvPreviewerWindowClass {
enum {
PROP_0,
- PROP_MODEL
+ PROP_MODEL,
+ PROP_UI_MANAGER
};
#define MIN_SCALE 0.05409
@@ -505,6 +506,24 @@ ev_previewer_window_init (EvPreviewerWindow *window)
}
static void
+ev_previewer_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (object);
+
+ switch (prop_id) {
+ case PROP_UI_MANAGER:
+ g_value_set_object (value, window->ui_manager);
+ break;
+ case PROP_MODEL:
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
ev_previewer_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -516,6 +535,7 @@ ev_previewer_window_set_property (GObject *object,
case PROP_MODEL:
window->model = g_value_dup_object (value);
break;
+ case PROP_UI_MANAGER:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -597,7 +617,7 @@ ev_previewer_window_constructor (GType type,
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/PreviewToolbar");
+ toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/Toolbar");
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);
@@ -635,6 +655,7 @@ ev_previewer_window_class_init (EvPreviewerWindowClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructor = ev_previewer_window_constructor;
+ gobject_class->get_property = ev_previewer_window_get_property;
gobject_class->set_property = ev_previewer_window_set_property;
gobject_class->dispose = ev_previewer_window_dispose;
@@ -645,7 +666,14 @@ ev_previewer_window_class_init (EvPreviewerWindowClass *klass)
"The document model",
EV_TYPE_DOCUMENT_MODEL,
G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class,
+ PROP_UI_MANAGER,
+ g_param_spec_object ("ui-manager", NULL, NULL,
+ GTK_TYPE_UI_MANAGER,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/* Public methods */
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index 7749775..77505f9 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -29,6 +29,8 @@
#include "ev-previewer-window.h"
+#include "ev-application-adapter.h"
+
#ifdef G_OS_WIN32
#include <io.h>
#include <conio.h>
@@ -78,6 +80,62 @@ ev_previewer_load_document (GFile *file,
}
static void
+close_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ if (window)
+ gtk_widget_destroy (GTK_WIDGET (window));
+}
+
+static void
+startup_cb (GApplication *application,
+ gpointer user_data)
+{
+ const GActionEntry app_menu_actions[] = {
+ { "print", NULL, NULL, NULL, NULL },
+ { "page-previous", NULL, NULL, NULL, NULL },
+ { "page-next", NULL, NULL, NULL, NULL },
+ { "zoom-page-width", NULL, NULL, "false", NULL },
+ { "zoom-best-fit", NULL, NULL, "false", NULL },
+ { "zoom-in", NULL, NULL, NULL, NULL },
+ { "zoom-out", NULL, NULL, NULL, NULL },
+ { "close", close_cb, NULL, NULL, NULL }
+ };
+
+ GtkBuilder *builder;
+ GError *error = NULL;
+ gboolean shell_shows_app_menu;
+
+ /* We only want to add an application menu when it's actually used! */
+ g_object_get (gtk_settings_get_for_screen (gdk_screen_get_default ()), "gtk-shell-shows-app-menu", &shell_shows_app_menu, NULL);
+ if (!shell_shows_app_menu)
+ return;
+
+ g_action_map_add_action_entries (G_ACTION_MAP (application),
+ app_menu_actions, G_N_ELEMENTS (app_menu_actions),
+ application);
+
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_resource (builder, "/org/gnome/evince/previewer/ui/appmenu.ui", &error);
+ g_assert_no_error (error);
+
+ gtk_application_set_app_menu (GTK_APPLICATION (application),
+ G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu")));
+ g_object_unref (builder);
+
+ ev_application_adapter_attach (GTK_APPLICATION (application),
+ "print", "/Toolbar/PreviewPrint",
+ "page-previous", "/Toolbar/GoPreviousPage",
+ "page-next", "/Toolbar/GoNextPage",
+ "zoom-page-width", "/Toolbar/ViewPageWidth",
+ "zoom-best-fit", "/Toolbar/ViewBestFit",
+ "zoom-in", "/Toolbar/ViewZoomIn",
+ "zoom-out", "/Toolbar/ViewZoomOut",
+ NULL);
+}
+
+static void
activate_cb (GApplication *application,
gpointer user_data)
{
@@ -199,6 +257,7 @@ main (gint argc, gchar **argv)
application = gtk_application_new (NULL,
G_APPLICATION_NON_UNIQUE |
G_APPLICATION_HANDLES_OPEN);
+ g_signal_connect (application, "startup", G_CALLBACK (startup_cb), NULL);
g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
g_signal_connect (application, "open", G_CALLBACK (open_cb), NULL);
diff --git a/previewer/previewer-ui.xml b/previewer/previewer-ui.xml
index 896b472..a641d6a 100644
--- a/previewer/previewer-ui.xml
+++ b/previewer/previewer-ui.xml
@@ -1,5 +1,5 @@
<ui>
- <toolbar name="PreviewToolbar">
+ <toolbar name="Toolbar">
<toolitem name="GoPreviousPage" action="GoPreviousPage"/>
<toolitem name="GoNextPage" action="GoNextPage"/>
<separator/>
diff --git a/previewer/previewer.gresource.xml b/previewer/previewer.gresource.xml
index 010c6bf..9cd040c 100644
--- a/previewer/previewer.gresource.xml
+++ b/previewer/previewer.gresource.xml
@@ -18,5 +18,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/appmenu.ui" compressed="true" preprocess="xml-stripblanks">appmenu.ui</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]