[evince/wip/app: 6/6] previewer: Add app menu



commit f0e03ba29fc2064f413738124d67c7fe593ef2c0
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              |   70 +++++++++++++++++++++++++++++++++++++
 previewer/ev-previewer-window.c   |   17 ++++++---
 previewer/ev-previewer-window.h   |    1 +
 previewer/ev-previewer.c          |   54 ++++++++++++++++++++++++++++
 previewer/previewer-ui.xml        |    2 +-
 previewer/previewer.gresource.xml |    1 +
 7 files changed, 140 insertions(+), 6 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f03a2f5..422c3c1 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..bf8b967
--- /dev/null
+++ b/previewer/appmenu.ui
@@ -0,0 +1,70 @@
+<?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">&lt;Primary&gt;p</attribute>
+      </item>
+    </section>
+    <!--
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Previous Page</attribute>
+        <attribute name="action">app.page-previous</attribute>
+        <attribute name="accel">&lt;Primary&gt;Page_Up</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Next Page</attribute>
+        <attribute name="action">app.page-next</attribute>
+        <attribute name="accel">&lt;Primary&gt;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">&lt;Primary&gt;plus</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Zoom _Out</attribute>
+        <attribute name="action">app.zoom-out</attribute>
+        <attribute name="accel">&lt;Primary&gt;minus</attribute>
+      </item>
+    </section>
+    -->
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Close</attribute>
+        <attribute name="action">app.close</attribute>
+        <attribute name="accel">&lt;Primary&gt;w</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/previewer/ev-previewer-window.c b/previewer/ev-previewer-window.c
index c16f2dc..8ff7df4 100644
--- a/previewer/ev-previewer-window.c
+++ b/previewer/ev-previewer-window.c
@@ -263,8 +263,14 @@ ev_previewer_window_enumerate_printers (GtkPrinter        *printer,
 }
 
 static void
-ev_previewer_window_print (GtkAction         *action,
-			   EvPreviewerWindow *window)
+ev_previewer_window_print_cb (GtkAction         *action,
+                              EvPreviewerWindow *window)
+{
+        ev_previewer_window_print (window);
+}
+
+void
+ev_previewer_window_print (EvPreviewerWindow *window)
 {
 	if (!window->print_settings)
 		window->print_settings = gtk_print_settings_new ();
@@ -296,7 +302,7 @@ static const GtkActionEntry action_entries[] = {
 #if GTKUNIXPRINT_ENABLED
 	{ "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,
 	  N_("Print this document"),
-	  G_CALLBACK (ev_previewer_window_print) }
+	  G_CALLBACK (ev_previewer_window_print_cb) }
 #endif
 };
 
@@ -575,7 +581,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);
@@ -623,7 +629,8 @@ 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));
 }
 
 /* Public methods */
diff --git a/previewer/ev-previewer-window.h b/previewer/ev-previewer-window.h
index 61f8632..afe3f68 100644
--- a/previewer/ev-previewer-window.h
+++ b/previewer/ev-previewer-window.h
@@ -45,6 +45,7 @@ void       ev_previewer_window_set_print_settings (EvPreviewerWindow *window,
 						   const gchar       *print_settings);
 void       ev_previewer_window_set_source_file    (EvPreviewerWindow *window,
 						   const gchar       *source_file);
+void       ev_previewer_window_print             (EvPreviewerWindow *window);
 
 G_END_DECLS
 
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
index 71fa0fa..1585a2c 100644
--- a/previewer/ev-previewer.c
+++ b/previewer/ev-previewer.c
@@ -93,6 +93,59 @@ ev_previewer_load_document (GFile           *file,
 	g_free (uri);
 }
 
+#if GTKUNIXPRINT_ENABLED
+static void
+app_print_cb (GSimpleAction *action,
+              GVariant      *parameter,
+              gpointer       data)
+{
+        if (window)
+                ev_previewer_window_print (window);
+}
+#endif
+
+static void
+app_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[] = {
+#if GTKUNIXPRINT_ENABLED
+                { "print", app_print_cb, NULL, NULL, NULL },
+#endif
+                { "close", app_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);
+}
+
 static void
 activate_cb (GApplication *application,
              gpointer user_data)
@@ -213,6 +266,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]