[evince/wip/app: 4/6] shell: Add app menu
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/app: 4/6] shell: Add app menu
- Date: Wed, 5 Sep 2012 15:32:14 +0000 (UTC)
commit 17b9b2a01dc6f3397bb33c0ac082533d43e4a973
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 | 71 ++++++++++++++++++++++++++++++++++++++++++++
shell/ev-application.h | 4 ++
shell/ev-window.c | 40 ++++--------------------
shell/evince-appmenu.ui | 53 ++++++++++++++++++++++++++++++++
shell/evince.gresource.xml | 1 +
6 files changed, 137 insertions(+), 34 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0be2c8c..f03a2f5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -58,4 +58,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 118960c..9ab84c3 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -924,6 +924,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);
@@ -1027,6 +1069,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;
@@ -1113,3 +1156,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 607859b..cbc1fd4 100644
--- a/shell/ev-application.h
+++ b/shell/ev-application.h
@@ -71,6 +71,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 d21c4dd..208b7cc 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -271,14 +271,6 @@ struct _EvWindowPrivate {
#define MAX_RECENT_ITEM_LEN (40)
-#if OFFLINE_HELP_ENABLED
-#define EV_HELP "help:evince"
-#define EV_HELP_TOOLBAR "help:evince/toolbar"
-#else
-#define EV_HELP "http://library.gnome.org/users/evince/stable/"
-#define EV_HELP_TOOLBAR "http://library.gnome.org/users/evince/stable/toolbar.html"
-#endif
-
#define TOOLBAR_RESOURCE_PATH "/org/gnome/evince/shell/ui/toolbar.xml"
static const gchar *document_print_settings[] = {
@@ -4469,20 +4461,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);
@@ -4756,17 +4738,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..f9c88be
--- /dev/null
+++ b/shell/evince-appmenu.ui
@@ -0,0 +1,53 @@
+<?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]