[gnome-documents] application: use a GResource for the application menu
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] application: use a GResource for the application menu
- Date: Tue, 17 Jul 2012 23:39:31 +0000 (UTC)
commit c687244c6e80a267faa961af75ea2ef4ac897b7f
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Jul 17 19:38:07 2012 -0400
application: use a GResource for the application menu
Editing an XML file is way easier than writing code manually for the
menu.
configure.ac | 3 +++
src/Makefile.am | 10 ++++++++++
src/application.js | 20 +++++++-------------
src/gnome-documents.gresource.xml | 6 ++++++
src/path.js.in | 1 +
src/resources/app-menu.ui | 33 +++++++++++++++++++++++++++++++++
6 files changed, 60 insertions(+), 13 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index be4e588..44011fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -86,6 +86,9 @@ PKG_CHECK_MODULES(MINER,
GJS_CONSOLE=`$PKG_CONFIG --variable=gjs_console gjs-1.0`
AC_SUBST(GJS_CONSOLE)
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_COMPILE_RESOURCES)
+
AC_CONFIG_FILES([
Makefile
src/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index ae3d560..8eb733a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,16 @@ include Makefile-lib.am
include Makefile-miner.am
include Makefile-js.am
+gnome-documents.gresource: gnome-documents.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/gnome-documents.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
+EXTRA_DIST += gnome-documents.gresource.xml \
+ resources/app-menu.ui
+
+resourcedir = $(pkgdatadir)
+resource_DATA = gnome-documents.gresource
+
+CLEANFILES += gnome-documents.gresource
+
gir_DATA += $(INTROSPECTION_GIRS)
typelib_DATA += $(gir_DATA:.gir=.typelib)
diff --git a/src/application.js b/src/application.js
index 18ecd44..3d2f9b1 100644
--- a/src/application.js
+++ b/src/application.js
@@ -128,21 +128,12 @@ const Application = new Lang.Class({
}));
this.application.add_action(viewAsAction);
- let menu = new Gio.Menu();
-
- let viewAs = new Gio.Menu();
- viewAs.append(_("Grid"), 'app.view-as::icon');
- viewAs.append(_("List"), 'app.view-as::list');
- menu.append_section(_("View as"), viewAs);
-
- let docActions = new Gio.Menu();
- docActions.append(_("Fullscreen"), 'app.fullscreen');
- menu.append_section(null, docActions);
-
- menu.append(_("About Documents"), 'app.about');
- menu.append(_("Quit"), 'app.quit');
+ let builder = new Gtk.Builder();
+ builder.add_from_resource('/org/gnome/documents/app-menu.ui');
+ let menu = builder.get_object('app-menu');
this.application.set_app_menu(menu);
+
this.application.add_accelerator('<Primary>q', 'app.quit', null);
this.application.add_accelerator('F11', 'app.fullscreen', null);
},
@@ -175,6 +166,9 @@ const Application = new Lang.Class({
EvDoc.init();
Tweener.init();
+ let resource = Gio.Resource.load(Path.RESOURCE_DIR + '/gnome-documents.gresource');
+ resource._register();
+
Global.application = this;
// connect to tracker
diff --git a/src/gnome-documents.gresource.xml b/src/gnome-documents.gresource.xml
new file mode 100644
index 0000000..e5f1b74
--- /dev/null
+++ b/src/gnome-documents.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/documents">
+ <file alias="app-menu.ui" preprocess="xml-stripblanks">resources/app-menu.ui</file>
+ </gresource>
+</gresources>
diff --git a/src/path.js.in b/src/path.js.in
index 9a43427..5b38c41 100644
--- a/src/path.js.in
+++ b/src/path.js.in
@@ -1,3 +1,4 @@
let LOCALE_DIR = "@localedir@";
let STYLE_DIR = "@pkgdatadir@/style/";
let ICONS_DIR = "@pkgdatadir@/icons/";
+let RESOURCE_DIR = "@pkgdatadir@";
diff --git a/src/resources/app-menu.ui b/src/resources/app-menu.ui
new file mode 100644
index 0000000..2425a2f
--- /dev/null
+++ b/src/resources/app-menu.ui
@@ -0,0 +1,33 @@
+<interface>
+ <menu id="app-menu">
+ <section>
+ <attribute name="label" translatable="yes">View as</attribute>
+ <item>
+ <attribute name="action">app.view-as</attribute>
+ <attribute name="target">icon</attribute>
+ <attribute name="label" translatable="yes">Grid</attribute>
+ </item>
+ <item>
+ <attribute name="action">app.view-as</attribute>
+ <attribute name="target">list</attribute>
+ <attribute name="label" translatable="yes">List</attribute>
+ </item>
+ </section>
+ <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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]