[epiphany] shell: add simple app menu in web app mode



commit 37736ac2daca6ad6dc959840facf9fa9ca74d219
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Sep 17 16:18:25 2016 -0500

    shell: add simple app menu in web app mode
    
    A side effect of this commit is that Ctrl+Q now works in app mode.
    That's nice!

 src/ephy-shell.c                           |   28 ++++++++++++++++++++--------
 src/resources/epiphany-application-menu.ui |   13 +++++++++++++
 2 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 9cf3ff5..2063339 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -251,6 +251,11 @@ static GActionEntry app_entries[] = {
   { "quit", quit_application, NULL, NULL, NULL },
 };
 
+static GActionEntry app_mode_app_entries[] = {
+  { "about", show_about, NULL, NULL, NULL },
+  { "quit", quit_application, NULL, NULL, NULL },
+};
+
 static GActionEntry app_normal_mode_entries[] = {
   { "reopen-closed-tab", reopen_closed_tab, NULL, NULL, NULL },
 };
@@ -290,6 +295,7 @@ ephy_shell_startup (GApplication *application)
 {
   EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (application);
   EphyEmbedShellMode mode;
+  GtkBuilder *builder;
 
   G_APPLICATION_CLASS (ephy_shell_parent_class)->startup (application);
 
@@ -299,11 +305,13 @@ ephy_shell_startup (GApplication *application)
                     G_CALLBACK (download_started_cb),
                     application);
 
-  mode = ephy_embed_shell_get_mode (embed_shell);
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_resource (builder,
+                                 "/org/gnome/epiphany/epiphany-application-menu.ui",
+                                 NULL);
 
+  mode = ephy_embed_shell_get_mode (embed_shell);
   if (mode != EPHY_EMBED_SHELL_MODE_APPLICATION) {
-    GtkBuilder *builder;
-
     g_action_map_add_action_entries (G_ACTION_MAP (application),
                                      app_entries, G_N_ELEMENTS (app_entries),
                                      application);
@@ -320,14 +328,18 @@ ephy_shell_startup (GApplication *application)
                               G_BINDING_SYNC_CREATE);
     }
 
-    builder = gtk_builder_new ();
-    gtk_builder_add_from_resource (builder,
-                                   "/org/gnome/epiphany/epiphany-application-menu.ui",
-                                   NULL);
+
     gtk_application_set_app_menu (GTK_APPLICATION (application),
                                   G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-    g_object_unref (builder);
+  } else {
+    g_action_map_add_action_entries (G_ACTION_MAP (application),
+                                     app_mode_app_entries, G_N_ELEMENTS (app_mode_app_entries),
+                                     application);
+    gtk_application_set_app_menu (GTK_APPLICATION (application),
+                                  G_MENU_MODEL (gtk_builder_get_object (builder, "app-mode-app-menu")));
   }
+
+  g_object_unref (builder);
 }
 
 static void
diff --git a/src/resources/epiphany-application-menu.ui b/src/resources/epiphany-application-menu.ui
index bb0da59..80840e1 100644
--- a/src/resources/epiphany-application-menu.ui
+++ b/src/resources/epiphany-application-menu.ui
@@ -39,6 +39,19 @@
     </section>
     <section>
       <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+        <attribute name="accel">&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
+  <menu id="app-mode-app-menu">
+    <section>
+      <item>
         <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
         <attribute name="action">app.shortcuts</attribute>
         <attribute name="accel">&lt;Primary&gt;F1</attribute>


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