[evince] shell: Add app menu
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] shell: Add app menu
- Date: Mon, 1 Oct 2012 12:38:23 +0000 (UTC)
commit 33d969267649b43371bc177e7334d6fdcfa3c25c
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 | 1 +
shell/ev-application.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
shell/ev-application.h | 4 ++
shell/ev-window.c | 35 ++++-----------------
shell/evince-appmenu.ui | 29 ++++++++++++++++++
shell/evince.gresource.xml | 1 +
6 files changed, 113 insertions(+), 28 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4c0fcd4..456a439 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -58,3 +58,4 @@ shell/ev-utils.c
shell/ev-window.c
shell/ev-window-title.c
shell/main.c
+[type: gettext/glade]shell/evince-appmenu.ui
diff --git a/shell/ev-application.c b/shell/ev-application.c
index a92d29c..0272477 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -997,6 +997,48 @@ ev_application_migrate_config_dir (EvApplication *application)
}
static void
+app_help_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ EvApplication *application = user_data;
+
+ ev_application_show_help (application, NULL, NULL);
+}
+
+static void
+ev_application_startup (GApplication *gapplication)
+{
+ const GActionEntry app_menu_actions[] = {
+ { "help", app_help_cb, 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);
+}
+
+static void
ev_application_shutdown (GApplication *gapplication)
{
EvApplication *application = EV_APPLICATION (gapplication);
@@ -1100,6 +1142,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;
@@ -1188,3 +1231,31 @@ ev_application_get_dot_dir (EvApplication *application,
return application->dot_dir;
}
+
+/**
+ * ev_application_show_help:
+ * @application: the #EvApplication
+ * @screen: (allow-none): a #GdkScreen, or %NULL to use the default screen
+ * @topic: (allow-none): the help topic, or %NULL to show the index
+ *
+ * Launches the help viewer on @screen to show the evince help.
+ * If @topic is %NULL, shows the help index; otherwise the topic.
+ */
+void
+ev_application_show_help (EvApplication *application,
+ GdkScreen *screen,
+ const char *topic)
+{
+ char *escaped_topic, *uri;
+
+ if (topic != NULL) {
+ escaped_topic = g_uri_escape_string (topic, NULL, TRUE);
+ uri = g_strdup_printf ("help:evince/%s", escaped_topic);
+ g_free (escaped_topic);
+ } else {
+ uri = g_strdup ("help:evince");
+ }
+
+ gtk_show_uri (screen, uri, gtk_get_current_event_time (), NULL);
+ g_free (uri);
+}
diff --git a/shell/ev-application.h b/shell/ev-application.h
index e3267ef..5ec870e 100644
--- a/shell/ev-application.h
+++ b/shell/ev-application.h
@@ -72,6 +72,10 @@ GObject *ev_application_get_media_keys (EvApplication *application);
const gchar *ev_application_get_dot_dir (EvApplication *application,
gboolean create);
+void ev_application_show_help (EvApplication *application,
+ GdkScreen *screen,
+ const char *topic);
+
G_END_DECLS
#endif /* !EV_APPLICATION_H */
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 7d6df91..2ad0512 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -276,9 +276,6 @@ struct _EvWindowPrivate {
#define MAX_RECENT_ITEM_LEN (40)
-#define EV_HELP "help:evince"
-#define EV_HELP_TOOLBAR "help:evince/toolbar"
-
#define TOOLBAR_RESOURCE_PATH "/org/gnome/evince/shell/ui/toolbar.xml"
static const gchar *document_print_settings[] = {
@@ -4492,20 +4489,10 @@ ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog,
gchar *toolbars_file;
if (response == GTK_RESPONSE_HELP) {
- GError *error = NULL;
-
- gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (dialog)),
- EV_HELP_TOOLBAR,
- gtk_get_current_event_time (),
- &error);
-
- if (error) {
- ev_window_error_message (ev_window, error,
- "%s", _("There was an error displaying help"));
- g_error_free (error);
- }
-
- return;
+ ev_application_show_help (EV_APP,
+ gtk_widget_get_screen (GTK_WIDGET (ev_window)),
+ "toolbar");
+ return;
}
toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar);
@@ -4779,17 +4766,9 @@ ev_window_cmd_view_autoscroll (GtkAction *action, EvWindow *ev_window)
static void
ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
{
- GError *error = NULL;
-
- gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
- EV_HELP,
- gtk_get_current_event_time (),
- &error);
- if (error) {
- ev_window_error_message (ev_window, error,
- "%s", _("There was an error displaying help"));
- g_error_free (error);
- }
+ ev_application_show_help (EV_APP,
+ gtk_widget_get_screen (GTK_WIDGET (ev_window)),
+ NULL);
}
static void
diff --git a/shell/evince-appmenu.ui b/shell/evince-appmenu.ui
new file mode 100644
index 0000000..41074f3
--- /dev/null
+++ b/shell/evince-appmenu.ui
@@ -0,0 +1,29 @@
+<?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">_Help</attribute>
+ <attribute name="action">app.help</attribute>
+ <attribute name="accel">F1</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 6f97114..4970c16 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -20,5 +20,6 @@
<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/evince.css" compressed="true">evince.css</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]