Commit 755d1fb4 authored by Debarshi Ray's avatar Debarshi Ray

application: Use a GResource for the application menu

Editing an XML file is way easier than writing code manually for the
menu.

Original patch from Cosimo Cecchi for gnome-documents.
parent 98fe4d3e
......@@ -103,6 +103,9 @@ LIBGD_INIT([
static
])
GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
AC_SUBST(GLIB_COMPILE_RESOURCES)
AC_CONFIG_FILES([
Makefile
data/Makefile
......
......@@ -7,6 +7,8 @@ gnome_photos_built_sources = \
photos-enums.h \
photos-marshalers.c \
photos-marshalers.h \
photos-resources.c \
photos-resources.h \
photos-tracker-resources.c \
photos-tracker-resources.h \
$(NULL)
......@@ -126,6 +128,8 @@ EXTRA_DIST = \
photos-enums.c.template \
photos-enums.h.template \
photos-generate-about \
photos.gresource.xml \
photos-app-menu.ui \
photos-marshalers.list \
photos-tracker-resources.xml \
$(null)
......@@ -264,6 +268,18 @@ photos-marshalers.c: photos-marshalers.list photos-marshalers.h Makefile
&& rm -f xgen-tmc \
)
photos-resources.c: photos.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/photos.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ \
--sourcedir=$(srcdir) \
--generate-source \
$<
photos-resources.h: photos.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/photos.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ \
--sourcedir=$(srcdir) \
--generate-header \
$<
photos-tracker-resources.h photos-tracker-resources.c: photos-tracker-resources.xml
gdbus-codegen \
--c-namespace Tracker \
......
<interface>
<menu id="app-menu">
<section>
<item>
<attribute name="action">app.fullscreen</attribute>
<attribute name="label" translatable="yes">Fullscreen</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">About Documents</attribute>
</item>
<item>
<attribute name="action">app.quit</attribute>
<attribute name="label" translatable="yes">Quit</attribute>
</item>
</section>
</menu>
</interface>
......@@ -34,10 +34,12 @@
#include "photos-application.h"
#include "photos-main-window.h"
#include "photos-mode-controller.h"
#include "photos-resources.h"
struct _PhotosApplicationPrivate
{
GResource *resource;
GSimpleAction *fs_action;
GtkWidget *main_window;
PhotosModeController *mode_cntrlr;
......@@ -94,9 +96,9 @@ photos_application_startup (GApplication *application)
{
PhotosApplication *self = PHOTOS_APPLICATION (application);
PhotosApplicationPrivate *priv = self->priv;
GMenu *doc_actions;
GMenu *menu;
GSimpleAction *action;
GtkBuilder *builder;
GtkSettings *settings;
G_APPLICATION_CLASS (photos_application_parent_class)
......@@ -108,6 +110,9 @@ photos_application_startup (GApplication *application)
return;
}
priv->resource = photos_get_resource ();
g_resources_register (priv->resource);
settings = gtk_settings_get_default ();
g_object_set (settings, "gtk-application-prefer-dark-theme", TRUE, NULL);
......@@ -133,16 +138,13 @@ photos_application_startup (GApplication *application)
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
g_object_unref (action);
menu = g_menu_new ();
doc_actions = g_menu_new ();
g_menu_append (doc_actions, _("Fullscreen"), "app.fullscreen");
g_menu_append_section (menu, NULL, G_MENU_MODEL (doc_actions));
g_menu_append (menu, _("About Photos"), "app.about");
g_menu_append (menu, _("Quit"), "app.quit");
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/org/gnome/photos/app-menu.ui", NULL);
menu = G_MENU (gtk_builder_get_object (builder, "app-menu"));
gtk_application_set_app_menu (GTK_APPLICATION (self), G_MENU_MODEL (menu));
g_object_unref (builder);
gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>q", "app.quit", NULL);
gtk_application_add_accelerator (GTK_APPLICATION (self), "F11", "app.fullscreen", NULL);
......@@ -174,6 +176,13 @@ photos_application_dispose (GObject *object)
PhotosApplication *self = PHOTOS_APPLICATION (object);
PhotosApplicationPrivate *priv = self->priv;
if (priv->resource != NULL)
{
g_resources_unregister (priv->resource);
g_resource_unref (priv->resource);
priv->resource = NULL;
}
if (priv->fs_action != NULL)
{
g_object_unref (priv->fs_action);
......
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/photos">
<file alias="app-menu.ui" preprocess="xml-stripblanks">photos-app-menu.ui</file>
</gresource>
</gresources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment