[evince/wip/gmenu: 4/4] Add traditional menu bar



commit d6badff64f82fda17b6d40b6b52f9d9de5ed8072
Author: Lars Uebernickel <lars uebernickel canonical com>
Date:   Thu Jan 30 15:13:38 2014 +0100

    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.

 shell/Makefile.am          |    3 +-
 shell/ev-application.c     |   82 +++++++++++++++-
 shell/ev-application.h     |    2 +
 shell/ev-toolbar.c         |   96 ++++++++++---------
 shell/evince.gresource.xml |    1 +
 shell/traditional-menus.ui |  229 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 362 insertions(+), 51 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 25773f4..53f8465 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -179,7 +179,8 @@ EXTRA_DIST = \
        evince.gresource.xml \
        ev-gdbus.xml \
        ev-daemon-gdbus.xml \
-       menus.ui
+       menus.ui \
+       traditional-menus.ui
 
 ev-resources.c: evince.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies 
--sourcedir $(srcdir) $(srcdir)/evince.gresource.xml)
        $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) 
--generate-source --c-name ev $<
diff --git a/shell/ev-application.c b/shell/ev-application.c
index b808385..e2d87af 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -44,6 +44,7 @@
 #include "ev-stock-icons.h"
 #include "ev-utils.h"
 #include "ev-document-factory.h"
+#include "ev-recent-menu-model.h"
 
 #ifdef ENABLE_DBUS
 #include "ev-gdbus-generated.h"
@@ -57,6 +58,7 @@ struct _EvApplication {
 
        gchar *dot_dir;
        GSettings *settings;
+       GMenu *bookmarks_menu;
 
 #ifdef ENABLE_DBUS
         EvEvinceApplication *skeleton;
@@ -1056,6 +1058,26 @@ ev_application_dispose (GObject *object)
 }
 
 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[] = {
@@ -1114,11 +1136,41 @@ ev_application_startup (GApplication *gapplication)
                                          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),
-                                      G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu")));
+        if (ev_application_has_traditional_menus (application))
+          {
+            GMenu *recent_section;
+            GMenuModel *recent_menu_model;
+
+            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")));
+
+            recent_menu_model = ev_recent_menu_model_new (gtk_recent_manager_get_default (),
+                                                          "app.open-file",
+                                                          g_get_application_name ());
+
+            recent_section = G_MENU (gtk_builder_get_object (builder, "recent"));
+            g_menu_append_section (recent_section, NULL, recent_menu_model);
+
+            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);
+
+            g_object_unref (recent_menu_model);
+          }
+        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);
 
         it = action_accels;
@@ -1500,3 +1552,25 @@ ev_application_get_settings (EvApplication *application)
 
        return application->settings;
 }
+
+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 --git a/shell/ev-application.h b/shell/ev-application.h
index fd9b886..b3e09ba 100644
--- a/shell/ev-application.h
+++ b/shell/ev-application.h
@@ -82,6 +82,8 @@ void              ev_application_open                (EvApplication   *applicati
 
 GSettings *       ev_application_get_settings        (EvApplication   *application);
 
+gboolean          ev_application_has_traditional_menus (EvApplication *application);
+
 G_END_DECLS
 
 #endif /* !EV_APPLICATION_H */
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
index 1383d69..a628054 100644
--- a/shell/ev-toolbar.c
+++ b/shell/ev-toolbar.c
@@ -179,7 +179,6 @@ static void
 ev_toolbar_constructed (GObject *object)
 {
         EvToolbar      *ev_toolbar = EV_TOOLBAR (object);
-        GtkBuilder     *builder;
         GtkActionGroup *action_group;
         GtkWidget      *tool_item;
         GtkWidget      *hbox;
@@ -187,8 +186,6 @@ ev_toolbar_constructed (GObject *object)
         GtkWidget      *button;
         gboolean        rtl;
         GMenuModel     *menu;
-        GMenu          *recent_submenu;
-        GMenuModel     *recent_menu_model;
 
         G_OBJECT_CLASS (ev_toolbar_parent_class)->constructed (object);
 
@@ -200,7 +197,6 @@ ev_toolbar_constructed (GObject *object)
                                      GTK_STYLE_CLASS_MENUBAR);
 
         action_group = ev_window_get_main_action_group (ev_toolbar->priv->window);
-        builder = gtk_builder_new_from_resource ("/org/gnome/evince/shell/ui/menus.ui");
 
         /* Navigation */
         hbox = ev_toolbar_create_button_group (ev_toolbar);
@@ -275,50 +271,58 @@ ev_toolbar_constructed (GObject *object)
         gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
         gtk_widget_show (tool_item);
 
-        /* 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"));
-        ev_toolbar->priv->view_menu_button = button;
-        tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        gtk_container_add (GTK_CONTAINER (tool_item), button);
-        gtk_widget_show (button);
-        if (rtl)
-                gtk_widget_set_margin_left (tool_item, 6);
-        else
-                gtk_widget_set_margin_right (tool_item, 6);
+        if (!ev_application_has_traditional_menus (EV_APP)) {
+                GtkBuilder *builder;
+                GMenu *recent_submenu;
+                GMenuModel *recent_menu_model;
 
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
-        gtk_widget_show (tool_item);
+                builder = gtk_builder_new_from_resource ("/org/gnome/evince/shell/ui/menus.ui");
 
-        /* Action Menu */
-        menu = G_MENU_MODEL (gtk_builder_get_object (builder, "action-menu"));
-        button = ev_toolbar_create_menu_button (ev_toolbar, "emblem-system-symbolic",
-                                                menu, GTK_ALIGN_END);
-        gtk_widget_set_tooltip_text (button, _("File options"));
-        ev_toolbar->priv->action_menu_button = button;
-        tool_item = GTK_WIDGET (gtk_tool_item_new ());
-        gtk_container_add (GTK_CONTAINER (tool_item), button);
-        gtk_widget_show (button);
-
-        gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
-        gtk_widget_show (tool_item);
-
-        recent_menu_model = ev_recent_menu_model_new (gtk_recent_manager_get_default (),
-                                                      "app.open-file",
-                                                      g_get_application_name ());
-
-        recent_submenu = G_MENU (gtk_builder_get_object (builder, "recent"));
-        g_menu_append_section (recent_submenu, NULL, recent_menu_model);
-
-        ev_toolbar->priv->bookmarks_section = G_MENU (gtk_builder_get_object (builder, "bookmarks"));
-        g_signal_connect_swapped (ev_window_get_bookmarks_menu (ev_toolbar->priv->window), "items-changed",
-                                  G_CALLBACK (ev_toolbar_update_bookmarks), ev_toolbar);
-        ev_toolbar_update_bookmarks (ev_toolbar);
-
-        g_object_unref (recent_menu_model);
-        g_object_unref (builder);
+                /* 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);
+                ev_toolbar->priv->view_menu_button = button;
+                tool_item = GTK_WIDGET (gtk_tool_item_new ());
+                gtk_widget_set_margin_left (tool_item, 12);
+                gtk_container_add (GTK_CONTAINER (tool_item), button);
+                gtk_widget_show (button);
+                if (rtl)
+                        gtk_widget_set_margin_left (tool_item, 6);
+                else
+                        gtk_widget_set_margin_right (tool_item, 6);
+
+                gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+                gtk_widget_show (tool_item);
+
+                /* Action Menu */
+                menu = G_MENU_MODEL (gtk_builder_get_object (builder, "action-menu"));
+                button = ev_toolbar_create_menu_button (ev_toolbar, "emblem-system-symbolic",
+                                                        menu, GTK_ALIGN_END);
+                ev_toolbar->priv->action_menu_button = button;
+                tool_item = GTK_WIDGET (gtk_tool_item_new ());
+                gtk_container_add (GTK_CONTAINER (tool_item), button);
+                gtk_widget_show (button);
+
+                gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+                gtk_widget_show (tool_item);
+
+                /* insert dynamic recent files submenu */
+                recent_menu_model = ev_recent_menu_model_new (gtk_recent_manager_get_default (),
+                                                              "app.open-file",
+                                                              g_get_application_name ());
+                recent_submenu = G_MENU (gtk_builder_get_object (builder, "recent"));
+                g_menu_append_section (recent_submenu, NULL, recent_menu_model);
+
+                /* insert bookmarks section */
+                ev_toolbar->priv->bookmarks_section = G_MENU (gtk_builder_get_object (builder, "bookmarks"));
+                g_signal_connect_swapped (ev_window_get_bookmarks_menu (ev_toolbar->priv->window), 
"items-changed",
+                                          G_CALLBACK (ev_toolbar_update_bookmarks), ev_toolbar);
+                ev_toolbar_update_bookmarks (ev_toolbar);
+
+                g_object_unref (recent_menu_model);
+                g_object_unref (builder);
+        }
 }
 
 static void
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index b432962..1017be0 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/evince.css" compressed="true">evince.css</file>
     <file alias="ui/menus.ui" compressed="true" preprocess="xml-stripblanks">menus.ui</file>
+    <file alias="ui/traditional-menus.ui" compressed="true" 
preprocess="xml-stripblanks">traditional-menus.ui</file>
   </gresource>
 </gresources>
diff --git a/shell/traditional-menus.ui b/shell/traditional-menus.ui
new file mode 100644
index 0000000..5e9b057
--- /dev/null
+++ b/shell/traditional-menus.ui
@@ -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">app.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>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]