[evince/wip/app: 23/23] shell: Add app menu
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/app: 23/23] shell: Add app menu
- Date: Tue, 12 Jun 2012 20:12:46 +0000 (UTC)
commit 46bd743fc3d07690271ed47ee47e4ad6d0cb8c16
Author: Christian Persch <chpe gnome org>
Date: Tue Jun 12 22:06:13 2012 +0200
shell: Add app menu
https://bugzilla.gnome.org/show_bug.cgi?id=674937
po/POTFILES.in | 2 +-
shell/ev-application.c | 44 +++++++++++++++++++++++++++++++++++++++++
shell/ev-window.c | 29 +++++++++++++++++++++++++++
shell/evince-appmenu.ui | 47 ++++++++++++++++++++++++++++++++++++++++++++
shell/evince.gresource.xml | 1 +
5 files changed, 122 insertions(+), 1 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dc227e5..422c3c1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -59,4 +59,4 @@ shell/ev-window.c
shell/ev-window-title.c
shell/ev-utils.c
shell/main.c
-
+[type: gettext/glade]shell/evince-appmenu.ui
diff --git a/shell/ev-application.c b/shell/ev-application.c
index e8bdbb8..f9c1f94 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -44,6 +44,7 @@
#include "ev-application.h"
#include "ev-file-helpers.h"
#include "ev-stock-icons.h"
+#include "ev-application-adapter.h"
#ifdef ENABLE_DBUS
#include "ev-gdbus.h"
@@ -906,6 +907,48 @@ ev_application_migrate_config_dir (EvApplication *application)
}
static void
+ev_application_startup (GApplication *gapplication)
+{
+ const GActionEntry app_menu_actions[] = {
+ { "print", NULL, NULL, NULL, NULL },
+ { "help", NULL, NULL, NULL, NULL },
+ { "about", NULL, NULL, NULL, NULL },
+ { "close", NULL, NULL, NULL, NULL }
+ };
+
+ EvApplication *application = EV_APPLICATION (gapplication);
+ GtkBuilder *builder;
+ GError *error = NULL;
+ gboolean shell_shows_app_menu;
+
+ G_APPLICATION_CLASS (ev_application_parent_class)->startup (gapplication);
+
+ /* 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/shell/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", "/MainMenu/FileMenu/FilePrintMenu",
+ "help", "/MainMenu/HelpMenu/HelpContentsMenu",
+ "about", "/MainMenu/HelpMenu/HelpAboutMenu",
+ "close", "/MainMenu/FileMenu/FileCloseWindowMenu",
+ NULL);
+}
+
+static void
ev_application_shutdown (GApplication *gapplication)
{
EvApplication *application = EV_APPLICATION (gapplication);
@@ -1007,6 +1050,7 @@ ev_application_class_init (EvApplicationClass *ev_application_class)
{
GApplicationClass *g_application_class = G_APPLICATION_CLASS (ev_application_class);
+ g_application_class->startup = ev_application_startup;
g_application_class->activate = ev_application_activate;
g_application_class->shutdown = ev_application_shutdown;
diff --git a/shell/ev-window.c b/shell/ev-window.c
index f67b5a2..56f8e24 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -289,6 +289,11 @@ static const gchar *document_print_settings[] = {
GTK_PRINT_SETTINGS_OUTPUT_URI
};
+enum {
+ PROP_0,
+ PROP_UI_MANAGER
+};
+
static void ev_window_update_actions (EvWindow *ev_window);
static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar,
GParamSpec *pspec,
@@ -5754,12 +5759,30 @@ ev_window_delete_event (GtkWidget *widget,
}
static void
+ev_window_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EvWindow *window = EV_WINDOW (object);
+
+ switch (prop_id) {
+ case PROP_UI_MANAGER:
+ g_value_set_object (value, window->priv->ui_manager);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
ev_window_class_init (EvWindowClass *ev_window_class)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (ev_window_class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (ev_window_class);
g_object_class->dispose = ev_window_dispose;
+ g_object_class->get_property = ev_window_get_property;
widget_class->delete_event = ev_window_delete_event;
widget_class->key_press_event = ev_window_key_press_event;
@@ -5769,6 +5792,12 @@ ev_window_class_init (EvWindowClass *ev_window_class)
nautilus_sendto = g_find_program_in_path ("nautilus-sendto");
+ g_object_class_install_property (g_object_class,
+ PROP_UI_MANAGER,
+ g_param_spec_object ("ui-manager", NULL, NULL,
+ GTK_TYPE_UI_MANAGER,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
g_type_class_add_private (g_object_class, sizeof (EvWindowPrivate));
}
diff --git a/shell/evince-appmenu.ui b/shell/evince-appmenu.ui
new file mode 100644
index 0000000..663d6df
--- /dev/null
+++ b/shell/evince-appmenu.ui
@@ -0,0 +1,47 @@
+<?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">_Help</attribute>
+ <attribute name="action">app.help</attribute>
+ <attribute name="accel">F1</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">app.about</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/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 2fac911..24b07be 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -19,5 +19,6 @@
<gresource prefix="/org/gnome/evince/shell">
<file alias="ui/evince.xml" compressed="true" preprocess="xml-stripblanks">evince-ui.xml</file>
<file alias="ui/toolbar.xml" compressed="true" preprocess="xml-stripblanks">evince-toolbar.xml</file>
+ <file alias="ui/appmenu.ui" compressed="true" preprocess="xml-stripblanks">evince-appmenu.ui</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]