[gnome-dictionary] app: Add a minimal application menu



commit 0e9e1cbba7eafed9905c219f7c92f2e67705d41c
Author: Florian MÃllner <fmuellner gnome org>
Date:   Tue May 8 18:09:50 2012 +0200

    app: Add a minimal application menu
    
    While Dictionary is a rather small application which probably could
    do well with only an application menu and no menubar, this would
    require a couple of design changes, as almost all actions currently
    in the menus are window-specific.
    So for now, leave the menubar alone and only add a minimal application
    menu.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674939

 data/gnome-dictionary-menus.ui |   41 ++++++++++----------
 src/gdict-app.c                |   83 ++++++++++++++++++++++++++++++++++++++++
 src/gdict-window.c             |   53 -------------------------
 3 files changed, 104 insertions(+), 73 deletions(-)
---
diff --git a/data/gnome-dictionary-menus.ui b/data/gnome-dictionary-menus.ui
index 5b0fab4..412c751 100644
--- a/data/gnome-dictionary-menus.ui
+++ b/data/gnome-dictionary-menus.ui
@@ -1,5 +1,26 @@
 <interface>
   <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Preferences</attribute>
+        <attribute name="action">app.preferences</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 Dictionary</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+      </item>
+    </section>
   </menu>
 
   <menu id="menubar">
@@ -70,12 +91,6 @@
           <attribute name="accel">&lt;Shift&gt;&lt;Primary&gt;g</attribute>
         </item>
       </section>
-      <section>
-        <item>
-          <attribute name="label" translatable="yes">_Preferences</attribute>
-          <attribute name="action">win.preferences</attribute>
-        </item>
-      </section>
     </submenu>
     <submenu>
       <attribute name="label" translatable="yes">_View</attribute>
@@ -140,19 +155,5 @@
         </item>
       </section>
     </submenu>
-    <submenu>
-      <attribute name="label" translatable="yes">_Help</attribute>
-      <section>
-        <item>
-          <attribute name="label" translatable="yes">_Contents</attribute>
-          <attribute name="action">win.help</attribute>
-          <attribute name="accel">F1</attribute>
-        </item>
-        <item>
-          <attribute name="label" translatable="yes">_About</attribute>
-          <attribute name="action">win.about</attribute>
-        </item>
-      </section>
-    </submenu>
   </menu>
 </interface>
diff --git a/src/gdict-app.c b/src/gdict-app.c
index 2d1459b..a3455b5 100644
--- a/src/gdict-app.c
+++ b/src/gdict-app.c
@@ -94,6 +94,82 @@ static GOptionEntry gdict_app_goptions[] = {
 };
 
 static void
+gdict_app_cmd_preferences (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  GdictWindow *window;
+
+  g_assert (GTK_IS_APPLICATION (app));
+
+  window = GDICT_WINDOW (gtk_application_get_windows (app)->data);
+  gdict_show_pref_dialog (GTK_WIDGET (window),
+                          _("Dictionary Preferences"),
+                          window->loader);
+}
+
+static void
+gdict_app_cmd_help (GSimpleAction *action,
+                    GVariant      *parameter,
+                    gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  GdictWindow *window;
+  GError *err = NULL;
+
+  g_return_if_fail (GTK_IS_APPLICATION (app));
+
+  window = GDICT_WINDOW (gtk_application_get_windows (app)->data);
+  gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (window)),
+                "ghelp:gnome-dictionary",
+                gtk_get_current_event_time (), &err);
+  if (err)
+    {
+      gdict_show_gerror_dialog (GTK_WINDOW (window),
+                                _("There was an error while displaying help"),
+                                err);
+      g_error_free (err);
+    }
+}
+
+static void
+gdict_app_cmd_about (GSimpleAction *action,
+                     GVariant      *parameter,
+                     gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  GdictWindow *window;
+
+  g_assert (GTK_IS_APPLICATION (app));
+
+  window = GDICT_WINDOW (gtk_application_get_windows (app)->data);
+  gdict_show_about_dialog (GTK_WIDGET (window));
+}
+
+static void
+gdict_app_cmd_quit (GSimpleAction *action,
+                    GVariant      *parameter,
+                    gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  GList *windows;
+
+  g_assert (GTK_IS_APPLICATION (app));
+
+  windows = gtk_application_get_windows (app);
+  g_list_foreach (windows, (GFunc)gtk_widget_destroy, NULL);
+}
+
+static const GActionEntry app_entries[] =
+{
+  { "preferences", gdict_app_cmd_preferences, NULL, NULL, NULL },
+  { "help", gdict_app_cmd_help, NULL, NULL, NULL },
+  { "about", gdict_app_cmd_about, NULL, NULL, NULL },
+  { "quit", gdict_app_cmd_quit, NULL, NULL, NULL }
+};
+
+static void
 gdict_app_finalize (GObject *object)
 {
   GdictApp *app = GDICT_APP (object);
@@ -225,6 +301,10 @@ gdict_startup (GApplication *application,
   GtkBuilder *builder = gtk_builder_new ();
   GError * error = NULL;
 
+  g_action_map_add_action_entries (G_ACTION_MAP (application),
+                                   app_entries, G_N_ELEMENTS (app_entries),
+                                   application);
+
   if (!gtk_builder_add_from_file (builder,
                                   PKGDATADIR "/gnome-dictionary-menus.ui",
                                   &error))
@@ -238,6 +318,9 @@ gdict_startup (GApplication *application,
   gtk_application_set_menubar (GTK_APPLICATION (application),
                                G_MENU_MODEL (gtk_builder_get_object (builder,
                                                                      "menubar")));
+  gtk_application_set_app_menu (GTK_APPLICATION (application),
+                                G_MENU_MODEL (gtk_builder_get_object (builder,
+                                                                      "app-menu")));
   gtk_application_add_accelerator (GTK_APPLICATION (application),
                                    "<Primary>l", "win.lookup", NULL);
   gtk_application_add_accelerator (GTK_APPLICATION (application),
diff --git a/src/gdict-window.c b/src/gdict-window.c
index 1f95263..3a40fc9 100644
--- a/src/gdict-window.c
+++ b/src/gdict-window.c
@@ -1063,20 +1063,6 @@ gdict_window_cmd_edit_find_previous (GSimpleAction *action,
 }
 
 static void
-gdict_window_cmd_edit_preferences (GSimpleAction *action,
-                                   GVariant      *parameter,
-                                   gpointer       user_data)
-{
-  GdictWindow *window = user_data;
-
-  g_assert (GDICT_IS_WINDOW (window));
-  
-  gdict_show_pref_dialog (GTK_WIDGET (window),
-  			  _("Dictionary Preferences"),
-  			  window->loader);
-}
-
-static void
 gdict_window_cmd_change_view_sidebar (GSimpleAction *action,
                                       GVariant      *state,
                                       gpointer       user_data)
@@ -1251,40 +1237,6 @@ activate_toggle (GSimpleAction *action,
 }
 
 static void
-gdict_window_cmd_help_contents (GSimpleAction *action,
-                                GVariant      *parameter,
-                                gpointer       user_data)
-{
-  GdictWindow *window = user_data;
-  GError *err = NULL;
-  
-  g_return_if_fail (GDICT_IS_WINDOW (window));
- 
-  gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (window)),
-                "ghelp:gnome-dictionary",
-                gtk_get_current_event_time (), &err); 
-  if (err)
-    {
-      gdict_show_gerror_dialog (GTK_WINDOW (window),
-      		                _("There was an error while displaying help"),
-      			        err);
-      g_error_free (err);
-    }
-}
-
-static void
-gdict_window_cmd_help_about (GSimpleAction *action,
-                             GVariant      *parameter,
-                             gpointer       user_data)
-{
-  GdictWindow *window = user_data;
-
-  g_assert (GDICT_IS_WINDOW (window));
-  
-  gdict_show_about_dialog (GTK_WIDGET (window));
-}
-
-static void
 gdict_window_cmd_lookup (GSimpleAction *action,
                          GVariant      *parameter,
                          gpointer       user_data)
@@ -1323,7 +1275,6 @@ static const GActionEntry entries[] =
   { "find", gdict_window_cmd_edit_find, NULL, NULL, NULL },
   { "find-next", gdict_window_cmd_edit_find_next, NULL, NULL, NULL },
   { "find-previous", gdict_window_cmd_edit_find_previous, NULL, NULL, NULL },
-  { "preferences", gdict_window_cmd_edit_preferences, NULL, NULL, NULL },
 
   /* Go menu */
   { "previous-def", gdict_window_cmd_go_previous_def, NULL, NULL, NULL },
@@ -1340,10 +1291,6 @@ static const GActionEntry entries[] =
   { "view-source", gdict_window_cmd_view_sources, NULL, NULL, NULL },
   { "view-db", gdict_window_cmd_view_databases, NULL, NULL, NULL },
   { "view-strat", gdict_window_cmd_view_strategies, NULL, NULL, NULL },
-
-  /* Help menu */
-  { "help", gdict_window_cmd_help_contents, NULL, NULL, NULL },
-  { "about", gdict_window_cmd_help_about, NULL, NULL, NULL },
   
   /* Accelerators */
   { "lookup", gdict_window_cmd_lookup, NULL, NULL, NULL },



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