From 8b2440b23466b2b9e30a92122b4ed9496484ae54 Mon Sep 17 00:00:00 2001
From: Lars Uebernickel <lars.uebernickel@canonical.com>
Date: Thu, 30 Jan 2014 15:13:38 +0100
Subject: Add traditional menu bar

This menu bar will only be shown when the desktop requests this through
the gtk-shell-shows-app-menu and gtk-shell-shows-menubar settings.

The view and action menus are hidden when the menubar is shown.

diff -Nur evince-3.13.91.orig/shell/ev-application.c evince-3.13.91/shell/ev-application.c
--- evince-3.13.91.orig/shell/ev-application.c	2014-09-09 19:29:27.708284422 +0200
+++ evince-3.13.91/shell/ev-application.c	2014-09-09 21:29:56.376525156 +0200
@@ -50,7 +50,8 @@
 	gchar *uri;
 
 	gchar *dot_dir;
-
+    GMenu *bookmarks_menu;
+    
 #ifdef ENABLE_DBUS
         EvEvinceApplication *skeleton;
 	EvMediaPlayerKeys *keys;
@@ -1055,6 +1056,26 @@
 }
 
 static void
+ev_application_update_bookmarks_menu (EvApplication *application)
+{
+        GtkWindow *window;
+
+        /* The bookmarks menu has two sections: the first one contains
+         * the "Add Bookmark" menu item and the second one is filled
+         * with the active window's bookmarks.
+         */
+
+        if (g_menu_model_get_n_items (G_MENU_MODEL (application->bookmarks_menu)) == 2)
+                g_menu_remove (application->bookmarks_menu, 1);
+
+        window = gtk_application_get_active_window (GTK_APPLICATION (application));
+        if (window) {
+                g_menu_append_section (application->bookmarks_menu, NULL,
+                                       ev_window_get_bookmarks_menu (EV_WINDOW (window)));
+        }
+}
+
+static void
 ev_application_startup (GApplication *gapplication)
 {
         const GActionEntry app_menu_actions[] = {
@@ -1112,11 +1133,29 @@
                                          application);
 
         builder = gtk_builder_new ();
-        gtk_builder_add_from_resource (builder, "/org/gnome/evince/shell/ui/menus.ui", &error);
-        g_assert_no_error (error);
 
-        gtk_application_set_app_menu (GTK_APPLICATION (application),
+        if (ev_application_has_traditional_menus (application))
+          {
+            gtk_builder_add_from_resource (builder, "/org/gnome/evince/shell/ui/traditional-menus.ui", &error);
+            g_assert_no_error (error);
+
+            gtk_application_set_menubar (GTK_APPLICATION (application),
+                                         G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+
+            application->bookmarks_menu = G_MENU (gtk_builder_get_object (builder, "bookmarks"));
+            g_signal_connect_swapped (application, "notify::active-window",
+                                      G_CALLBACK (ev_application_update_bookmarks_menu), application);
+            ev_application_update_bookmarks_menu (application);
+          }
+        else
+        {
+           gtk_builder_add_from_resource (builder, "/org/gnome/evince/shell/ui/menus.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);
 
         for (it = action_accels; it[0]; it += g_strv_length ((gchar **)it) + 1)
@@ -1342,3 +1381,25 @@
         gtk_show_uri (screen, uri, gtk_get_current_event_time (), NULL);
         g_free (uri);
 }
+
+gboolean
+ev_application_has_traditional_menus (EvApplication *application)
+{
+   GdkDisplay *display;
+   GdkScreen *screen;
+   GtkSettings *settings;
+   gboolean show_app_menu;
+   gboolean show_menubar;
+
+   g_return_val_if_fail (EV_IS_APPLICATION (application), FALSE);
+
+   display = gdk_display_get_default ();
+   screen = gdk_display_get_default_screen (display);
+   settings = gtk_settings_get_for_screen (screen);
+   g_object_get (G_OBJECT (settings),
+             "gtk-shell-shows-app-menu", &show_app_menu,
+             "gtk-shell-shows-menubar", &show_menubar,
+             NULL);
+
+   return !show_app_menu || show_menubar;
+}
diff -Nur evince-3.13.91.orig/shell/ev-application.h evince-3.13.91/shell/ev-application.h
--- evince-3.13.91.orig/shell/ev-application.h	2014-09-09 19:29:27.708284422 +0200
+++ evince-3.13.91/shell/ev-application.h	2014-09-09 19:50:20.304326137 +0200
@@ -80,6 +80,8 @@
                                                       GdkScreen       *screen,
                                                       const char      *topic);
 
+gboolean          ev_application_has_traditional_menus (EvApplication *application);
+
 G_END_DECLS
 
 #endif /* !EV_APPLICATION_H */
diff -Nur evince-3.13.91.orig/shell/evince.gresource.xml evince-3.13.91/shell/evince.gresource.xml
--- evince-3.13.91.orig/shell/evince.gresource.xml	2014-09-09 19:29:27.704284422 +0200
+++ evince-3.13.91/shell/evince.gresource.xml	2014-09-09 19:44:19.232314112 +0200
@@ -20,5 +20,6 @@
     <file alias="ui/evince.css" compressed="true">evince.css</file>
     <file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
     <file alias="ui/menus.ui" compressed="true" preprocess="xml-stripblanks">evince-menus.ui</file>
+    <file alias="ui/traditional-menus.ui" compressed="true" preprocess="xml-stripblanks">traditional-menus.ui</file>
   </gresource>
 </gresources>
diff -Nur evince-3.13.91.orig/shell/ev-toolbar.c evince-3.13.91/shell/ev-toolbar.c
--- evince-3.13.91.orig/shell/ev-toolbar.c	2014-09-09 19:29:27.704284422 +0200
+++ evince-3.13.91/shell/ev-toolbar.c	2014-09-09 21:31:11.592527661 +0200
@@ -190,8 +190,6 @@
         GtkWidget      *hbox, *vbox;
         GtkWidget      *button;
         gboolean        rtl;
-        GMenuModel     *menu;
-        GMenuModel     *bookmarks_submenu_model;
 
         G_OBJECT_CLASS (ev_toolbar_parent_class)->constructed (object);
 
@@ -240,25 +238,36 @@
                 gtk_widget_set_margin_right (button, 6);
         gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), button);
 
-        /* Action Menu */
-        menu = G_MENU_MODEL (gtk_builder_get_object (builder, "action-menu"));
-        button = ev_toolbar_create_menu_button (ev_toolbar, "open-menu-symbolic",
-                                                menu, GTK_ALIGN_END);
-        gtk_widget_set_tooltip_text (button, _("File options"));
-        atk_object_set_name (gtk_widget_get_accessible (button), _("File options"));
-
-        ev_toolbar->priv->action_menu_button = button;
-        gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), button);
-
-        /* View Menu */
-        menu = G_MENU_MODEL (gtk_builder_get_object (builder, "view-menu"));
-        button = ev_toolbar_create_menu_button (ev_toolbar, "document-properties-symbolic",
-                                                menu, GTK_ALIGN_END);
-        gtk_widget_set_tooltip_text (button, _("View options"));
-        atk_object_set_name (gtk_widget_get_accessible (button), _("View options"));
-        ev_toolbar->priv->view_menu_button = button;
-        gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), button);
-
+        if (!ev_application_has_traditional_menus (EV_APP)) {
+            GMenuModel     *bookmarks_submenu_model;
+            GMenuModel     *menu;               
+
+            /* Action Menu */
+            menu = G_MENU_MODEL (gtk_builder_get_object (builder, "action-menu"));
+            button = ev_toolbar_create_menu_button (ev_toolbar, "open-menu-symbolic",
+                                                    menu, GTK_ALIGN_END);
+            gtk_widget_set_tooltip_text (button, _("File options"));
+            atk_object_set_name (gtk_widget_get_accessible (button), _("File options"));
+
+            ev_toolbar->priv->action_menu_button = button;
+            gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), button);
+
+            /* View Menu */
+            menu = G_MENU_MODEL (gtk_builder_get_object (builder, "view-menu"));
+            button = ev_toolbar_create_menu_button (ev_toolbar, "document-properties-symbolic",
+                                                    menu, GTK_ALIGN_END);
+            gtk_widget_set_tooltip_text (button, _("View options"));
+            atk_object_set_name (gtk_widget_get_accessible (button), _("View options"));
+            ev_toolbar->priv->view_menu_button = button;
+            gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), button);
+
+            ev_toolbar->priv->bookmarks_section = G_MENU (gtk_builder_get_object (builder, "bookmarks"));
+            bookmarks_submenu_model = ev_window_get_bookmarks_menu (ev_toolbar->priv->window);
+            g_signal_connect (bookmarks_submenu_model, "items-changed",
+                              G_CALLBACK (ev_toolbar_bookmarks_menu_model_changed),
+                              ev_toolbar);
+            ev_toolbar_setup_bookmarks_menu (ev_toolbar, bookmarks_submenu_model);
+        }
         /* Zoom selector */
         vbox = ev_zoom_action_new (ev_window_get_document_model (ev_toolbar->priv->window),
                                    G_MENU (gtk_builder_get_object (builder, "zoom-menu")));
@@ -272,13 +281,6 @@
                 gtk_widget_set_margin_right (vbox, 6);
         gtk_header_bar_pack_end (GTK_HEADER_BAR (ev_toolbar), vbox);
 
-        ev_toolbar->priv->bookmarks_section = G_MENU (gtk_builder_get_object (builder, "bookmarks"));
-        bookmarks_submenu_model = ev_window_get_bookmarks_menu (ev_toolbar->priv->window);
-        g_signal_connect (bookmarks_submenu_model, "items-changed",
-                          G_CALLBACK (ev_toolbar_bookmarks_menu_model_changed),
-                          ev_toolbar);
-        ev_toolbar_setup_bookmarks_menu (ev_toolbar, bookmarks_submenu_model);
-
         g_object_unref (builder);
 }
 
diff -Nur evince-3.13.91.orig/shell/ev-window.c evince-3.13.91/shell/ev-window.c
--- evince-3.13.91.orig/shell/ev-window.c	2014-09-09 19:29:27.708284422 +0200
+++ evince-3.13.91/shell/ev-window.c	2014-09-10 10:54:05.849241430 +0200
@@ -637,6 +637,8 @@
 	set_widget_visibility (priv->toolbar, toolbar);
 	set_widget_visibility (priv->find_bar, findbar);
 	set_widget_visibility (priv->sidebar, sidebar);
+
+	gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), !presentation);
 }
 
 static void
@@ -7242,7 +7244,6 @@
 	ev_window = GTK_WIDGET (g_object_new (EV_TYPE_WINDOW,
 					      "type", GTK_WINDOW_TOPLEVEL,
                                               "application", g_application_get_default (),
-					      "show-menubar", FALSE,
 					      NULL));
 
 	return ev_window;
diff -Nur evince-3.13.91.orig/shell/Makefile.am evince-3.13.91/shell/Makefile.am
--- evince-3.13.91.orig/shell/Makefile.am	2014-09-09 19:29:27.700284422 +0200
+++ evince-3.13.91/shell/Makefile.am	2014-09-09 19:45:03.944315601 +0200
@@ -172,7 +172,8 @@
 	evince-icon.rc \
 	evince.gresource.xml \
 	ev-gdbus.xml \
-	ev-daemon-gdbus.xml
+	ev-daemon-gdbus.xml \
+	traditional-menus.ui
 
 ev-resources.c: evince.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(srcdir) --sourcedir=$(top_srcdir)/data $(srcdir)/evince.gresource.xml)
 	$(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir=$(srcdir) --sourcedir=$(top_srcdir)/data --generate-source --c-name ev $<
diff -Nur evince-3.13.91.orig/shell/traditional-menus.ui evince-3.13.91/shell/traditional-menus.ui
--- evince-3.13.91.orig/shell/traditional-menus.ui	1970-01-01 01:00:00.000000000 +0100
+++ evince-3.13.91/shell/traditional-menus.ui	2014-09-09 19:43:59.112313442 +0200
@@ -0,0 +1,229 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright © 2014 Canonical Ltd.
+
+  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.
+
+  Author: Lars Uebernickel <lars.uebernickel@canonical.com>
+-->
+<interface>
+  <menu id="menubar">
+    <submenu>
+      <attribute name="label" translatable="yes">_File</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Open…</attribute>
+          <attribute name="action">win.open</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;O</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Op_en a Copy</attribute>
+          <attribute name="action">win.open-copy</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;N</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Save a Copy…</attribute>
+          <attribute name="action">win.save-copy</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;S</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Send _To…</attribute>
+          <attribute name="action">win.send-to</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Open Containing _Folder</attribute>
+          <attribute name="action">win.open-containing-folder</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Print…</attribute>
+          <attribute name="action">win.print</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;P</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">P_roperties…</attribute>
+          <attribute name="action">win.show-properties</attribute>
+          <attribute name="accel">&lt;Alt&gt;Return</attribute>
+        </item>
+      </section>
+      <item>
+        <link name="section" id="recent">
+        </link>
+      </item>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Close</attribute>
+          <attribute name="action">win.close</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;W</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Edit</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Copy</attribute>
+          <attribute name="action">win.copy</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;C</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Select _All</attribute>
+          <attribute name="action">win.select-all</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;A</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Find</attribute>
+          <attribute name="action">win.find</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;F</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">Rotate _Left</attribute>
+          <attribute name="action">win.rotate-left</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;Left</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Rotate _Right</attribute>
+          <attribute name="action">win.rotate-right</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;Right</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">Save Current Settings as _Default</attribute>
+          <attribute name="action">win.save-settings</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;T</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_View</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Continuous</attribute>
+          <attribute name="action">win.continuous</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Dual</attribute>
+          <attribute name="action">win.dual-page</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">Side _Pane</attribute>
+          <attribute name="action">win.show-side-pane</attribute>
+          <attribute name="accel">F9</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Fullscreen</attribute>
+          <attribute name="action">win.fullscreen</attribute>
+          <attribute name="accel">F11</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Pre_sentation</attribute>
+          <attribute name="action">win.presentation</attribute>
+          <attribute name="accel">F5</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">Zoom _In</attribute>
+          <attribute name="action">win.zoom-in</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;plus</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Zoom _Out</attribute>
+          <attribute name="action">win.zoom-out</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;minus</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Odd Pages Left</attribute>
+          <attribute name="action">win.dual-odd-left</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Inverted Colors</attribute>
+          <attribute name="action">win.inverted-colors</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;I</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Reload</attribute>
+          <attribute name="action">win.reload</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;R</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Go</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Previous Page</attribute>
+          <attribute name="action">win.go-previous-page</attribute>
+          <attribute name="accel">p</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Next Page</attribute>
+          <attribute name="action">win.go-next-page</attribute>
+          <attribute name="accel">n</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_First Page</attribute>
+          <attribute name="action">win.go-first-page</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;Home</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Last Page</attribute>
+          <attribute name="action">win.go-last-page</attribute>
+          <attribute name="accel">&lt;Ctrl&gt;End</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu id="bookmarks">
+        <attribute name="label" translatable="yes">_Bookmarks</attribute>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">_Add Bookmark</attribute>
+            <attribute name="action">win.add-bookmark</attribute>
+          </item>
+        </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Help</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Help</attribute>
+          <attribute name="action">app.help</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_About</attribute>
+          <attribute name="action">app.about</attribute>
+        </item>
+      </section>
+    </submenu>
+  </menu>
+</interface>
