[gnome-calendar] app: update application menu
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] app: update application menu
- Date: Thu, 4 Dec 2014 22:33:01 +0000 (UTC)
commit 333363205c95b282edc45a03b6bbc7db9cd218b4
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Sun Sep 28 20:47:48 2014 -0400
app: update application menu
Use only application wide actions in the menu, as stated in GNOME HIG
Migrated to use GtkBuilder files
configure.ac | 1 +
data/Makefile.am | 1 +
data/calendar.gresource.xml | 1 +
data/ui/menus.ui | 29 ++++++++++++++
src/gcal-application.c | 89 +++++++++++++-----------------------------
5 files changed, 60 insertions(+), 61 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d9e3ea2..4e90c4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ LIBICAL_REQUIRED=0.43
PKG_CHECK_MODULES(CALENDAR,
gmodule-export-2.0
+ gio-2.0 >= $GLIB_MIN_VERSION
glib-2.0 >= $GLIB_MIN_VERSION
gtk+-3.0 >= $GTK_MIN_VERSION
libecal-1.2 >= $ECAL_REQUIRED
diff --git a/data/Makefile.am b/data/Makefile.am
index 5b22b88..161ff25 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -18,6 +18,7 @@ gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml)
EXTRA_DIST= \
gnome-calendar.desktop \
calendar.gresource.xml \
+ ui/menus.ui \
ui/nav_bar.ui \
ui/new-event.ui \
ui/viewport.ui \
diff --git a/data/calendar.gresource.xml b/data/calendar.gresource.xml
index 6c9a04e..5eb9d54 100644
--- a/data/calendar.gresource.xml
+++ b/data/calendar.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/calendar">
+ <file alias="menus.ui" compressed="true" preprocess="xml-stripblanks">ui/menus.ui</file>
<file alias="nav_bar.ui" compressed="true" preprocess="xml-stripblanks">ui/nav_bar.ui</file>
<file alias="viewport.ui" compressed="true" preprocess="xml-stripblanks">ui/viewport.ui</file>
<file alias="new-event.ui" compressed="true" preprocess="xml-stripblanks">ui/new-event.ui</file>
diff --git a/data/ui/menus.ui b/data/ui/menus.ui
new file mode 100644
index 0000000..bda2e82
--- /dev/null
+++ b/data/ui/menus.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<interface>
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_New</attribute>
+ <attribute name="action">app.new</attribute>
+ <attribute name="accel"><Primary>n</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Search...</attribute>
+ <attribute name="action">app.search</attribute>
+ <attribute name="accel"><Primary>f</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">app.about</attribute>
+ <attribute name="accel"><Primary>a</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="accel"><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 2303669..10ce508 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -24,6 +24,9 @@
#include "gcal-application.h"
#include "gcal-window.h"
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
#include <glib/gi18n.h>
#define CSS_FILE "resource:///org/gnome/calendar/gtk-styles.css"
@@ -52,11 +55,11 @@ static void gcal_application_set_app_menu (GApplication *
static void gcal_application_create_new_event (GSimpleAction *new_event,
GVariant *parameter,
- gpointer *app);
+ gpointer app);
static void gcal_application_launch_search (GSimpleAction *search,
GVariant *parameter,
- gpointer *app);
+ gpointer app);
static void gcal_application_change_view (GSimpleAction *simple,
GVariant *parameter,
@@ -87,6 +90,14 @@ static GOptionEntry gcal_application_goptions[] = {
{ NULL }
};
+static const GActionEntry gcal_app_entries[] = {
+ { "new", gcal_application_create_new_event },
+ { "search", gcal_application_launch_search },
+ { "view", gcal_application_change_view, "s" },
+ { "about", gcal_application_show_about },
+ { "quit", gcal_application_quit },
+};
+
static void
gcal_application_class_init (GcalApplicationClass *klass)
{
@@ -234,72 +245,28 @@ gcal_application_command_line (GApplication *app,
static void
gcal_application_set_app_menu (GApplication *app)
{
- GcalApplicationPrivate *priv;
+ GtkBuilder *builder;
+ GMenuModel *appmenu;
- GMenu *app_menu;
- GMenu *view_as;
- GSimpleAction *new_event;
- GSimpleAction *search;
- GSimpleAction *about;
- GSimpleAction *quit;
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_resource (builder, "/org/gnome/calendar/menus.ui", NULL);
- priv = gcal_application_get_instance_private (GCAL_APPLICATION (app));
+ appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ gcal_app_entries,
+ G_N_ELEMENTS (gcal_app_entries),
+ app);
+
+ gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
- app_menu = g_menu_new ();
-
- new_event = g_simple_action_new ("new_event", NULL);
- g_signal_connect (new_event, "activate",
- G_CALLBACK (gcal_application_create_new_event), app);
- g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (new_event));
- g_menu_append (app_menu, _("New Event"), "app.new_event");
-
- search = g_simple_action_new ("search", NULL);
- g_signal_connect (search, "activate",
- G_CALLBACK (gcal_application_launch_search), app);
- g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (search));
- g_menu_append (app_menu, _("Search"), "app.search");
-
- priv->view_action = g_simple_action_new_stateful (
- "view",
- G_VARIANT_TYPE_STRING,
- g_settings_get_value (priv->settings, "active-view"));
-
- g_signal_connect (priv->view_action, "activate",
- G_CALLBACK (gcal_application_change_view), app);
- g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (priv->view_action));
-
- view_as = g_menu_new ();
- g_menu_append (view_as, _("Day"), "app.view::day");
- g_menu_append (view_as, _("Week"), "app.view::week");
- g_menu_append (view_as, _("Month"), "app.view::month");
- g_menu_append (view_as, _("Year"), "app.view::year");
-
- g_menu_append_section (app_menu, _("View as"), G_MENU_MODEL (view_as));
-
- about = g_simple_action_new ("about", NULL);
- g_signal_connect (about, "activate",
- G_CALLBACK (gcal_application_show_about), app);
- g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (about));
- g_menu_append (app_menu, _("About"), "app.about");
-
- quit = g_simple_action_new ("quit", NULL);
- g_signal_connect (quit, "activate",
- G_CALLBACK (gcal_application_quit), app);
- g_action_map_add_action ( G_ACTION_MAP (app), G_ACTION (quit));
- g_menu_append (app_menu, _("Quit"), "app.quit");
-
- gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (app_menu));
-
- /* Accelerators */
- gtk_application_add_accelerator (GTK_APPLICATION (app), "<Primary>n", "app.new_event", NULL);
- gtk_application_add_accelerator (GTK_APPLICATION (app), "<Primary>f", "app.search", NULL);
- gtk_application_add_accelerator (GTK_APPLICATION (app), "<Primary>q", "app.quit", NULL);
+ g_object_unref (builder);
}
static void
gcal_application_create_new_event (GSimpleAction *new_event,
GVariant *parameter,
- gpointer *app)
+ gpointer app)
{
GcalApplicationPrivate *priv;
@@ -311,7 +278,7 @@ gcal_application_create_new_event (GSimpleAction *new_event,
static void
gcal_application_launch_search (GSimpleAction *search,
GVariant *parameter,
- gpointer *app)
+ gpointer app)
{
GcalApplicationPrivate *priv;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]