[gnome-font-viewer] font-view: use a separate UI file and a GResource for the app menu



commit 29f9b52392a13d9a4cfec5b7c9858d14b9af8697
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 10 16:05:47 2012 -0400

    font-view: use a separate UI file and a GResource for the app menu
    
    So to avoid problems with translations; embedding glade-like XML in C
    files makes it impossible for the translatable strings to be picked up
    by gettext, as reported by Piotr DrÄg <piotrdrag gmail com>.

 po/POTFILES.in                      |    1 +
 src/Makefile.am                     |   15 +++++++++++++++
 src/font-view-app-menu.ui           |   14 ++++++++++++++
 src/font-view.c                     |   19 +------------------
 src/gnome-font-viewer.gresource.xml |    6 ++++++
 5 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5dc14e4..5c1ed67 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,5 +2,6 @@
 # Please keep this file sorted alphabetically.
 src/font-thumbnailer.c
 src/font-view.c
+[type: gettext/glade]src/font-view-app-menu.ui
 src/gd-main-toolbar.c
 src/gnome-font-viewer.desktop.in.in
diff --git a/src/Makefile.am b/src/Makefile.am
index d62e549..c12992f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,20 @@ bin_PROGRAMS = \
 	gnome-thumbnail-font \
 	gnome-font-viewer
 
+UI_FILES = \
+	font-view-app-menu.ui
+
+font-view-resources.c: gnome-font-viewer.gresource.xml $(UI_FILES)
+	$(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name font_view $(srcdir)/gnome-font-viewer.gresource.xml
+
+font-view-resources.h: gnome-font-viewer.gresource.xml $(UI_FILES)
+	$(AM_V_GEN)glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name font_view $(srcdir)/gnome-font-viewer.gresource.xml
+
+BUILT_SOURCES = \
+	font-view-resources.c		\
+	font-view-resources.h		\
+	$(NULL)
+
 font_loader_SOURCES = \
 	sushi-font-loader.h \
 	sushi-font-loader.c
@@ -26,6 +40,7 @@ gnome_font_viewer_LDADD = \
 	$(FONTVIEW_LIBS)
 
 gnome_font_viewer_SOURCES = \
+	$(BUILT_SOURCES) \
 	$(font_loader_SOURCES) \
 	font-model.h \
 	font-model.c \
diff --git a/src/font-view-app-menu.ui b/src/font-view-app-menu.ui
new file mode 100644
index 0000000..915c308
--- /dev/null
+++ b/src/font-view-app-menu.ui
@@ -0,0 +1,14 @@
+<interface>
+  <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="action">app.about</attribute>
+        <attribute name="label" translatable="yes">About Font Viewer</attribute>
+      </item>
+      <item>
+       <attribute name="action">app.quit</attribute>
+       <attribute name="label" translatable="yes">Quit</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/src/font-view.c b/src/font-view.c
index b275095..a3faad2 100644
--- a/src/font-view.c
+++ b/src/font-view.c
@@ -72,23 +72,6 @@ G_DEFINE_TYPE (FontViewApplication, font_view_application, GTK_TYPE_APPLICATION)
 
 static void font_view_application_do_overview (FontViewApplication *self);
 
-static const gchar *app_menu =
-    "<interface>"
-    "  <menu id=\"app-menu\">"
-    "    <section>"
-    "      <item>"
-    "        <attribute name=\"action\">app.about</attribute>"
-    "	     <attribute name=\"label\" translatable=\"yes\">About Font Viewer</attribute>"
-    "      </item>"
-    "      <item>"
-    "       <attribute name=\"action\">app.quit</attribute>"
-    "	    <attribute name=\"label\" translatable=\"yes\">Quit</attribute>"
-    "      </item>"
-    "    </section>"
-    "  <menu>"
-    "</interface>";
-
-
 #define VIEW_ITEM_WIDTH 140
 #define VIEW_ITEM_WRAP_WIDTH 128
 #define VIEW_COLUMN_SPACING 36
@@ -647,7 +630,7 @@ font_view_application_startup (GApplication *application)
     g_action_map_add_action_entries (G_ACTION_MAP (self), action_entries, 
                                      G_N_ELEMENTS (action_entries), self);
     builder = gtk_builder_new ();
-    gtk_builder_add_from_string (builder, app_menu, -1, NULL);
+    gtk_builder_add_from_resource (builder, "/org/gnome/font-viewer/font-view-app-menu.ui", NULL);
     menu = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"));
     gtk_application_set_app_menu (GTK_APPLICATION (self), menu);
 
diff --git a/src/gnome-font-viewer.gresource.xml b/src/gnome-font-viewer.gresource.xml
new file mode 100644
index 0000000..1642d21
--- /dev/null
+++ b/src/gnome-font-viewer.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/font-viewer">
+    <file preprocess="xml-stripblanks">font-view-app-menu.ui</file>
+  </gresource>
+</gresources>



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