[gnome-mahjongg] Use an .ui file for the appmenu.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mahjongg] Use an .ui file for the appmenu.
- Date: Sun, 18 Aug 2013 17:26:37 +0000 (UTC)
commit a40fd8e1928d4842f34ab7af5ad6e6cee82573eb
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Apr 7 14:36:27 2013 +0200
Use an .ui file for the appmenu.
https://bugzilla.gnome.org/show_bug.cgi?id=697482
configure.ac | 2 +
po/POTFILES.in | 1 +
src/Makefile.am | 12 +++++++++-
src/gnome-mahjongg.gresource.xml | 6 +++++
src/gnome-mahjongg.vala | 30 ++++++++-----------------
src/menu.ui | 43 ++++++++++++++++++++++++++++++++++++++
6 files changed, 73 insertions(+), 21 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 56f6968..77a8afd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,6 +7,8 @@ GNOME_MAINTAINER_MODE_DEFINES
AM_PROG_VALAC([0.16.0])
AM_PROG_CC_C_O
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
GLIB_GSETTINGS
dnl ###########################################################################
diff --git a/po/POTFILES.in b/po/POTFILES.in
index bd5fb11..26d5d14 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,3 +8,4 @@ src/game.vala
src/game-view.vala
src/gnome-mahjongg.vala
src/map.vala
+[type: gettext/glade]src/menu.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index b9aacfb..7e9c972 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,10 @@
bin_PROGRAMS = gnome-mahjongg
+BUILT_SOURCES = resources.c
+
+resources.c: gnome-mahjongg.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies
--sourcedir=$(srcdir) $(srcdir)/gnome-mahjongg.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
+
gnome_mahjongg_SOURCES = \
config.vapi \
fixes.vapi \
@@ -7,7 +12,8 @@ gnome_mahjongg_SOURCES = \
game-view.vala \
gnome-mahjongg.vala \
history.vala \
- map.vala
+ map.vala \
+ $(BUILT_SOURCES)
gnome_mahjongg_VALAFLAGS = \
--pkg posix \
@@ -28,4 +34,8 @@ CLEANFILES = \
$(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
*_vala.stamp
+EXTRA_DIST = \
+ gnome-mahjongg.gresource.xml \
+ menu.ui
+
-include $(top_srcdir)/git.mk
diff --git a/src/gnome-mahjongg.gresource.xml b/src/gnome-mahjongg.gresource.xml
new file mode 100644
index 0000000..0d032e1
--- /dev/null
+++ b/src/gnome-mahjongg.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/mahjongg/ui">
+ <file preprocess="xml-stripblanks">menu.ui</file>
+ </gresource>
+</gresources>
diff --git a/src/gnome-mahjongg.vala b/src/gnome-mahjongg.vala
index a54abf8..36a59ee 100644
--- a/src/gnome-mahjongg.vala
+++ b/src/gnome-mahjongg.vala
@@ -24,13 +24,10 @@ public class Mahjongg : Gtk.Application
Object (application_id: "org.gnome.gnome-mahjongg", flags: ApplicationFlags.FLAGS_NONE);
add_action_entries (action_entries, this);
- add_accelerator ("<Primary>n", "app.new-game", null);
add_accelerator ("Pause", "app.pause", null);
add_accelerator ("<Primary>h", "app.hint", null);
add_accelerator ("<Primary>z", "app.undo", null);
add_accelerator ("<Primary><Shift>z", "app.redo", null);
- add_accelerator ("F1", "app.help", null);
- add_accelerator ("<Primary>q", "app.quit", null);
}
protected override void startup ()
@@ -39,6 +36,16 @@ public class Mahjongg : Gtk.Application
settings = new Settings ("org.gnome.gnome-mahjongg");
+ var builder = new Gtk.Builder ();
+ try {
+ builder.add_from_resource ("/org/gnome/mahjongg/ui/menu.ui");
+ } catch (Error e) {
+ error ("loading menu builder file: %s", e.message);
+ }
+
+ var app_menu = builder.get_object ("appmenu") as MenuModel;
+ set_app_menu (app_menu);
+
load_maps ();
history = new History (Path.build_filename (Environment.get_user_data_dir (), "gnome-mahjongg",
"history"));
@@ -70,23 +77,6 @@ public class Mahjongg : Gtk.Application
var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
- /* Create the menus */
- var menu = new Menu ();
- var section = new Menu ();
- menu.append_section (null, section);
- section.append (_("_New Game"), "app.new-game");
- section.append (_("_Restart Game"), "app.restart-game");
- section.append (_("_Scores"), "app.scores");
- section.append (_("_Preferences"), "app.preferences");
- section = new Menu ();
- menu.append_section (null, section);
- section.append (_("_Help"), "app.help");
- section.append (_("_About"), "app.about");
- section = new Menu ();
- menu.append_section (null, section);
- section.append (_("_Quit"), "app.quit");
- set_app_menu (menu);
-
game_view = new GameView ();
game_view.button_press_event.connect (view_button_press_event);
game_view.set_size_request (600, 400);
diff --git a/src/menu.ui b/src/menu.ui
new file mode 100644
index 0000000..cdf33ae
--- /dev/null
+++ b/src/menu.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_New Game</attribute>
+ <attribute name="action">app.new-game</attribute>
+ <attribute name="accel"><Primary>n</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Restart Game</attribute>
+ <attribute name="action">app.restart-game</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Scores</attribute>
+ <attribute name="action">app.scores</attribute>
+ </item>
+ <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"><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]