[frogr] Added first version of the application menu.



commit 4ac878677ce18eb6affc05b2a3ce9a847f13cebe
Author: Mario Sanchez Prada <msanchez gnome org>
Date:   Sat Nov 17 01:10:05 2012 +0100

    Added first version of the application menu.
    
    Moved "load/save" for projects to the "Actions" menu.

 Makefile.am                         |    4 +-
 data/gtkbuilder/frogr-app-menu.xml  |   36 +++++++
 data/gtkbuilder/frogr-main-view.xml |  118 +-----------------------
 po/POTFILES.skip                    |    1 +
 src/frogr-main-view.c               |  177 +++++++++++++++++++++++------------
 5 files changed, 160 insertions(+), 176 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ef81ee1..966092a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -62,7 +62,9 @@ imagesdir = $(datadir)/frogr/images
 images_DATA = data/images/mpictures.png
 
 gtkbuilderdir = $(datadir)/frogr/gtkbuilder
-gtkbuilder_DATA = data/gtkbuilder/frogr-main-view.xml
+gtkbuilder_DATA = \
+	data/gtkbuilder/frogr-main-view.xml \
+	data/gtkbuilder/frogr-app-menu.xml
 
 desktopentrydir = $(datadir)/applications
 desktopentry_DATA = $(builddir)/data/frogr.desktop
diff --git a/data/gtkbuilder/frogr-app-menu.xml b/data/gtkbuilder/frogr-app-menu.xml
new file mode 100644
index 0000000..6c073cb
--- /dev/null
+++ b/data/gtkbuilder/frogr-app-menu.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>Aut_horize Accountâ</attribute>
+        <attribute name='action'>app.authorize</attribute>
+        <attribute name='accel'>&lt;Primary&gt;&lt;Shift&gt;a</attribute>
+      </item>
+    </section>
+    <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</attribute>
+        <attribute name='action'>app.about</attribute>
+      </item>
+    </section>
+    <section>
+      <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>
+</interface>
diff --git a/data/gtkbuilder/frogr-main-view.xml b/data/gtkbuilder/frogr-main-view.xml
index bdd8be5..6eb9acd 100644
--- a/data/gtkbuilder/frogr-main-view.xml
+++ b/data/gtkbuilder/frogr-main-view.xml
@@ -1,11 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
-  <object class="GtkAction" id="about_action">
-    <property name="label" translatable="yes">_About</property>
-    <property name="stock_id">gtk-about</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
   <object class="GtkAction" id="load_project_action">
     <property name="label" translatable="yes">_Load Projectâ</property>
     <property name="stock_id">gtk-open</property>
@@ -42,10 +37,6 @@
     <property name="label" translatable="yes">Add to _Existing Setâ</property>
     <signal name="activate" handler="_on_action_activated" swapped="no"/>
   </object>
-  <object class="GtkAction" id="auth_action">
-    <property name="label" translatable="yes">Aut_horize Accountâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
   <object class="GtkToggleAction" id="enable_tooltips_action">
     <property name="label" translatable="yes">Enable _Tooltips</property>
     <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
@@ -54,25 +45,10 @@
     <property name="label" translatable="yes">Edit _Detailsâ</property>
     <signal name="activate" handler="_on_action_activated" swapped="no"/>
   </object>
-  <object class="GtkAction" id="help_action">
-    <property name="label" translatable="yes">_Help</property>
-    <property name="stock_id">gtk-help</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
   <object class="GtkAction" id="open_in_external_viewer_action">
     <property name="label" translatable="yes">Open in E_xternal Viewer</property>
     <signal name="activate" handler="_on_action_activated" swapped="no"/>
   </object>
-  <object class="GtkAction" id="preferences_action">
-    <property name="label" translatable="yes">_Preferencesâ</property>
-    <property name="stock_id">gtk-preferences</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="quit_action">
-    <property name="label" translatable="yes">_Quit</property>
-    <property name="stock_id">gtk-quit</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
   <object class="GtkAction" id="remove_pictures_action">
     <property name="label" translatable="yes">_Remove Pictures</property>
     <property name="stock_id">gtk-remove</property>
@@ -330,14 +306,14 @@
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <child>
-      <object class="GtkMenuItem" id="frogr_menu_item">
+      <object class="GtkMenuItem" id="actions_menu_item">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="use_action_appearance">False</property>
-        <property name="label" translatable="yes">_Frogr</property>
+        <property name="label" translatable="yes">A_ctions</property>
         <property name="use_underline">True</property>
         <child type="submenu">
-          <object class="GtkMenu" id="menu1">
+          <object class="GtkMenu" id="menu2">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <child>
@@ -375,94 +351,6 @@
               </object>
             </child>
             <child>
-              <object class="GtkMenuItem" id="authorize_menu_item">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="related_action">auth_action</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem" id="accounts_menu_item">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="use_action_appearance">False</property>
-                <property name="label" translatable="yes">Accou_nts</property>
-                <property name="use_underline">True</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkSeparatorMenuItem" id="separator3">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="use_action_appearance">False</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkImageMenuItem" id="preferences_menu_item">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="related_action">preferences_action</property>
-                <property name="use_underline">True</property>
-                <property name="use_stock">True</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkSeparatorMenuItem" id="separator4">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="use_action_appearance">False</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkImageMenuItem" id="help_menu_item">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="related_action">help_action</property>
-                <property name="use_underline">True</property>
-                <property name="use_stock">True</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkImageMenuItem" id="about_menu_item">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="related_action">about_action</property>
-                <property name="use_underline">True</property>
-                <property name="use_stock">True</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkSeparatorMenuItem" id="separator8">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="use_action_appearance">False</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkImageMenuItem" id="quit_menu_item">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="related_action">quit_action</property>
-                <property name="use_underline">True</property>
-                <property name="use_stock">True</property>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
-    <child>
-      <object class="GtkMenuItem" id="actions_menu_item">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="use_action_appearance">False</property>
-        <property name="label" translatable="yes">A_ctions</property>
-        <property name="use_underline">True</property>
-        <child type="submenu">
-          <object class="GtkMenu" id="menu2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <child>
               <object class="GtkImageMenuItem" id="load_pictures_menu_item">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 2263409..692de41 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,2 +1,3 @@
 data/frogr.desktop.in
 data/gtkbuilder/frogr-main-view.xml
+data/gtkbuilder/frogr-app-menu.xml
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 0fce5d5..6c8f264 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -50,7 +50,8 @@
 #define MINIMUM_WINDOW_HEIGHT 600
 
 /* Path relative to the application data dir */
-#define GTKBUILDER_FILE "/gtkbuilder/frogr-main-view.xml"
+#define UI_MAIN_VIEW_FILE "/gtkbuilder/frogr-main-view.xml"
+#define UI_APP_MENU_FILE "/gtkbuilder/frogr-app-menu.xml"
 
 #define FROGR_MAIN_VIEW_GET_PRIVATE(object)             \
   (G_TYPE_INSTANCE_GET_PRIVATE ((object),               \
@@ -120,10 +121,6 @@ typedef struct _FrogrMainViewPrivate {
   GtkToggleAction *sort_as_loaded_action;
   GtkToggleAction *sort_by_title_action;
   GtkToggleAction *sort_by_date_taken_action;
-
-#ifndef MAC_INTEGRATION
-  GtkAction *quit_action;
-#endif
 } FrogrMainViewPrivate;
 
 
@@ -222,7 +219,6 @@ static void _edit_selected_pictures (FrogrMainView *self);
 static void _remove_selected_pictures (FrogrMainView *self);
 static void _load_pictures (FrogrMainView *self, GSList *fileuris);
 static void _upload_pictures (FrogrMainView *self);
-static void _show_help_contents (FrogrMainView *self);
 static void _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean reversed);
 
 static gint _compare_pictures_by_property (FrogrPicture *p1, FrogrPicture *p2,
@@ -429,30 +425,6 @@ _setup_keyboard_shortcuts (FrogrMainView *self)
   accel = gtk_accel_group_new();
   gtk_window_add_accel_group(priv->window, accel);
 
-  menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "load_project_menu_item"));
-  gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_o,
-                             GDK_PRIMARY_MODIFIER, GTK_ACCEL_VISIBLE);
-
-  menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "save_project_menu_item"));
-  gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_s,
-                             GDK_PRIMARY_MODIFIER, GTK_ACCEL_VISIBLE);
-
-  menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "save_project_as_menu_item"));
-  gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_s,
-                             GDK_PRIMARY_MODIFIER | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
-
-  menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "authorize_menu_item"));
-  gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_a,
-                             GDK_PRIMARY_MODIFIER | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
-
-  menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "help_menu_item"));
-  gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_F1,
-                             0, GTK_ACCEL_VISIBLE);
-
-  menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "quit_menu_item"));
-  gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_q,
-                             GDK_PRIMARY_MODIFIER, GTK_ACCEL_VISIBLE);
-
   menu_item = GTK_WIDGET (gtk_builder_get_object (priv->builder, "load_pictures_menu_item"));
   gtk_widget_add_accelerator(menu_item, "activate", accel, GDK_KEY_l,
                              GDK_PRIMARY_MODIFIER, GTK_ACCEL_VISIBLE);
@@ -612,10 +584,6 @@ _on_action_activated (GtkAction *action, gpointer data)
     _upload_pictures (mainview);
   else if (action == priv->open_in_external_viewer_action)
     _open_pictures_in_external_viewer (mainview);
-  else if (action == priv->auth_action)
-    frogr_controller_show_auth_dialog (priv->controller);
-  else if (action == priv->preferences_action)
-    frogr_controller_show_settings_dialog (priv->controller);
   else if (action == priv->add_tags_action)
     _add_tags_to_pictures (mainview);
   else if (action == priv->edit_details_action)
@@ -626,14 +594,6 @@ _on_action_activated (GtkAction *action, gpointer data)
     _add_pictures_to_existing_set (mainview);
   else if (action == priv->add_to_new_set_action)
     _add_pictures_to_new_set (mainview);
-  else if (action == priv->help_action)
-    _show_help_contents (mainview);
-  else if (action == priv->about_action)
-    frogr_controller_show_about_dialog (priv->controller);
-#ifndef MAC_INTEGRATION
-  else if (action == priv->quit_action)
-    frogr_controller_quit_app (priv->controller);
-#endif
 }
 
 void
@@ -806,13 +766,24 @@ _on_account_menu_item_toggled (GtkWidget *widget, gpointer self)
     }
 }
 
+static void
+_quit_application (FrogrMainView *self)
+{
+  FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
+
+  GApplication *app = G_APPLICATION (g_object_ref (priv->gtk_app));
+  frogr_controller_quit_app (priv->controller);
+
+  g_application_quit (app);
+  g_object_unref (app);
+}
+
 static gboolean
 _on_main_view_delete_event (GtkWidget *widget,
                             GdkEvent *event,
                             gpointer self)
 {
-  FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
-  frogr_controller_quit_app (priv->controller);
+  _quit_application (FROGR_MAIN_VIEW (self));
   return TRUE;
 }
 
@@ -1324,12 +1295,6 @@ _upload_pictures (FrogrMainView *self)
 }
 
 static void
-_show_help_contents (FrogrMainView *self)
-{
-  frogr_util_open_uri ("ghelp:frogr");
-}
-
-static void
 _reorder_pictures (FrogrMainView *self, SortingCriteria criteria, gboolean reversed)
 {
   FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
@@ -1851,7 +1816,7 @@ _frogr_main_view_set_property (GObject *object,
   switch (prop_id)
     {
     case PROP_GTK_APPLICATION:
-      priv->gtk_app = GTK_APPLICATION (g_value_dup_object (value));
+      priv->gtk_app = GTK_APPLICATION (g_value_get_object (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1878,6 +1843,87 @@ _frogr_main_view_get_property (GObject *object,
     }
 }
 
+static void
+_load_project_action (GSimpleAction *action,
+                      GVariant *parameter,
+                      gpointer data)
+{
+  _load_project_dialog (FROGR_MAIN_VIEW (data));
+}
+
+static void
+_save_project_action (GSimpleAction *action,
+                       GVariant *parameter,
+                       gpointer data)
+{
+  _save_current_project (FROGR_MAIN_VIEW (data));
+}
+
+static void
+_save_project_as_action (GSimpleAction *action,
+                         GVariant *parameter,
+                         gpointer data)
+{
+  _save_project_as_dialog (FROGR_MAIN_VIEW (data));
+}
+
+static void
+_authorize_action (GSimpleAction *action,
+                   GVariant *parameter,
+                   gpointer data)
+{
+  FrogrMainViewPrivate *priv = NULL;
+  priv = FROGR_MAIN_VIEW_GET_PRIVATE (data);
+  frogr_controller_show_auth_dialog (priv->controller);
+}
+
+static void
+_preferences_action (GSimpleAction *action,
+                     GVariant *parameter,
+                     gpointer data)
+{
+  FrogrMainViewPrivate *priv = NULL;
+  priv = FROGR_MAIN_VIEW_GET_PRIVATE (data);
+  frogr_controller_show_settings_dialog (priv->controller);
+}
+
+static void
+_about_action (GSimpleAction *action,
+               GVariant *parameter,
+               gpointer data)
+{
+  FrogrMainViewPrivate *priv = NULL;
+  priv = FROGR_MAIN_VIEW_GET_PRIVATE (data);
+  frogr_controller_show_about_dialog (priv->controller);
+}
+
+static void
+_help_action (GSimpleAction *action,
+              GVariant *parameter,
+              gpointer data)
+{
+  frogr_util_open_uri ("ghelp:frogr");
+}
+
+static void
+_quit_action (GSimpleAction *action,
+              GVariant *parameter,
+              gpointer data)
+{
+  _quit_application (FROGR_MAIN_VIEW (data));
+}
+
+static GActionEntry app_entries[] = {
+  { "load_project", _load_project_action, NULL, NULL, NULL },
+  { "save_project", _save_project_action, NULL, NULL, NULL },
+  { "save_project_as", _save_project_as_action, NULL, NULL, NULL },
+  { "authorize", _authorize_action, NULL, NULL, NULL },
+  { "preferences", _preferences_action, NULL, NULL, NULL },
+  { "help", _help_action, NULL, NULL, NULL },
+  { "about", _about_action, NULL, NULL, NULL },
+  { "quit", _quit_action, NULL, NULL, NULL },
+};
+
 static GObject *
 _frogr_main_view_constructor (GType type,
                               guint n_construct_properties,
@@ -1909,7 +1955,7 @@ _frogr_main_view_constructor (GType type,
   builder = gtk_builder_new ();
   priv->builder = builder;
 
-  full_path = g_strdup_printf ("%s/" GTKBUILDER_FILE, frogr_util_get_app_data_dir ());
+  full_path = g_strdup_printf ("%s/" UI_MAIN_VIEW_FILE, frogr_util_get_app_data_dir ());
   gtk_builder_add_from_file (builder, full_path, NULL);
   g_free (full_path);
 
@@ -1919,6 +1965,25 @@ _frogr_main_view_constructor (GType type,
   main_vbox = GTK_WIDGET (gtk_builder_get_object (builder, "main_window_vbox"));
   gtk_container_add (GTK_CONTAINER (priv->window), main_vbox);
 
+  /* Menu bar */
+  priv->menu_bar = GTK_WIDGET (gtk_builder_get_object (builder, "menu_bar"));
+  gtk_widget_show_all (priv->menu_bar);
+
+#ifndef MAC_INTEGRATION
+  gtk_box_pack_start (GTK_BOX (main_vbox), priv->menu_bar, FALSE, FALSE, 0);
+  gtk_box_reorder_child (GTK_BOX (main_vbox), priv->menu_bar, 0);
+#endif
+
+  /* App menu */
+  full_path = g_strdup_printf ("%s/" UI_APP_MENU_FILE, frogr_util_get_app_data_dir ());
+  gtk_builder_add_from_file (builder, full_path, NULL);
+  g_free (full_path);
+  g_action_map_add_action_entries (G_ACTION_MAP (priv->gtk_app),
+                                   app_entries, G_N_ELEMENTS (app_entries),
+                                   self);
+  gtk_application_set_app_menu (GTK_APPLICATION (priv->gtk_app),
+                                G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+
   toolbar = GTK_WIDGET (gtk_builder_get_object (builder, "toolbar"));
   gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
                                GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
@@ -1978,11 +2043,6 @@ _frogr_main_view_constructor (GType type,
   priv->reversed_order_action =
     GTK_TOGGLE_ACTION (gtk_builder_get_object (builder,
                                                "reversed_order_action"));
-#ifndef MAC_INTEGRATION
-  priv->quit_action =
-    GTK_ACTION (gtk_builder_get_object (builder, "quit_action"));
-#endif
-
   /* Set Keyboard shortcuts */
   _setup_keyboard_shortcuts (self);
 
@@ -2181,9 +2241,6 @@ _frogr_main_view_finalize (GObject *object)
   g_free (priv->state_description);
   gtk_widget_destroy (GTK_WIDGET (priv->window));
 
-  g_application_quit (G_APPLICATION (priv->gtk_app));
-  g_object_unref (priv->gtk_app);
-
   G_OBJECT_CLASS(frogr_main_view_parent_class)->finalize (object);
 }
 



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