[gucharmap] ui: Use GResource instead of string
- From: Florian MÃllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gucharmap] ui: Use GResource instead of string
- Date: Wed, 16 May 2012 00:17:47 +0000 (UTC)
commit af84d39fa915315e4f4b33916638ca5a46f85514
Author: Florian MÃllner <fmuellner gnome org>
Date: Wed May 9 02:53:38 2012 +0200
ui: Use GResource instead of string
Using resources for UI descriptions shares the advantages of using
embedded strings, with the additional benefit of being translatable.
https://bugzilla.gnome.org/show_bug.cgi?id=674952
configure.ac | 7 +++
gucharmap/Makefile.am | 14 ++++++
gucharmap/gucharmap-ui.xml | 37 ++++++++++++++++
gucharmap/gucharmap-window.c | 80 +++++++++++++--------------------
gucharmap/gucharmap.gresource.xml.in | 22 +++++++++
5 files changed, 112 insertions(+), 48 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a6ef97d..4c5fce1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,12 @@ fi
# Some utilities
AC_PROG_LN_S
+AC_ARG_VAR([GLIB_COMPILE_RESOURCES],[the glib-compile-resources programme])
+AC_PATH_PROG([GLIB_COMPILE_RESOURCES],[glib-compile-resources],[false])
+if test "$GLIB_COMPILE_RESOURCES" = "false"; then
+ AC_MSG_ERROR([glib-compile-resources not found])
+fi
+
# AC_PATH_PROG([GTK_BUILDER_CONVERT],[gtk-builder-convert],[false])
# if test "$GTK_BUILDER_CONVERT" = "false"; then
# AC_MSG_ERROR([gtk-builder-convert not found])
@@ -273,6 +279,7 @@ gucharmap.spec
docs/Makefile
docs/reference/Makefile
gucharmap/Makefile
+gucharmap/gucharmap.gresource.xml
gucharmap/gucharmap.h
help/Makefile
help/it/Makefile
diff --git a/gucharmap/Makefile.am b/gucharmap/Makefile.am
index 8698fb7..e3ccb97 100644
--- a/gucharmap/Makefile.am
+++ b/gucharmap/Makefile.am
@@ -23,6 +23,8 @@ lib_LTLIBRARIES = libgucharmap GUCHARMAP_LIBRARY_SUFFIX_U@.la
BUILT_SOURCES = \
gucharmap-marshal.c \
gucharmap-marshal.h \
+ gucharmap-resources.c \
+ gucharmap-resources.h \
gucharmap-type-builtins.c \
gucharmap-type-builtins.h \
$(NULL)
@@ -132,6 +134,11 @@ gucharmap_SOURCES = \
main.c \
$(NULL)
+nodist_gucharmap_SOURCES = \
+ gucharmap-resources.c \
+ gucharmap-resources.h \
+ $(NULL)
+
gucharmap_CPPFLAGS = \
-I$(top_srcdir) \
-DDATADIR=\"$(datadir)\" \
@@ -157,6 +164,12 @@ gucharmap_LDADD = \
$(GTK_LIBS) \
$(INTL_LIBS)
+dist_noinst_DATA = gucharmap-ui.xml
+
+gucharmap-resources.h gucharmap-resources.c: gucharmap.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies gucharmap.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) \
+ --generate --c-name gucharmap $<
+
if OS_WIN32
gucharmap_LDADD += gucharmaprc.o
gucharmaprc.o: gucharmaprc.rc
@@ -207,6 +220,7 @@ EXTRA_DIST = \
gucharmaprc.rc \
download-unicode-files.sh \
gen-guch-unicode-tables.pl \
+ gucharmap.gresource.xml.in \
$(NULL)
CLEANFILES = \
diff --git a/gucharmap/gucharmap-ui.xml b/gucharmap/gucharmap-ui.xml
new file mode 100644
index 0000000..5de4455
--- /dev/null
+++ b/gucharmap/gucharmap-ui.xml
@@ -0,0 +1,37 @@
+<ui>
+ <menubar name='MenuBar'>
+ <menu action='File'>
+ <placeholder name='Printing' />
+ <separator />
+ <menuitem action='Close' />
+ <placeholder name='chpe' />
+ </menu>
+ <menu action='View'>
+ <menuitem action='ByScript' />
+ <menuitem action='ByUnicodeBlock' />
+ <separator />
+ <menuitem action='ShowOnlyGlyphsInFont' />
+ <menuitem action='SnapColumns' />
+ <separator />
+ <menuitem action='ZoomIn' />
+ <menuitem action='ZoomOut' />
+ <menuitem action='NormalSize' />
+ </menu>
+ <menu action='Search'>
+ <menuitem action='Find' />
+ <menuitem action='FindNext' />
+ <menuitem action='FindPrevious' />
+ </menu>
+ <menu action='Go'>
+ <menuitem action='NextCharacter' />
+ <menuitem action='PreviousCharacter' />
+ <separator />
+ <menuitem action='NextChapter' />
+ <menuitem action='PreviousChapter' />
+ </menu>
+ <menu action='Help'>
+ <menuitem action='HelpContents' />
+ <menuitem action='About' />
+ </menu>
+ </menubar>
+</ui>
diff --git a/gucharmap/gucharmap-window.c b/gucharmap/gucharmap-window.c
index fadf2a8..fa96c65 100644
--- a/gucharmap/gucharmap-window.c
+++ b/gucharmap/gucharmap-window.c
@@ -32,6 +32,8 @@
#define FONT_CHANGE_FACTOR (1.189207115f) /* 2^(0.25) */
+#define UI_RESOURCE "/org/gnome/charmap/gucharmap-ui.xml"
+
/* #define ENABLE_PRINTING */
static void gucharmap_window_class_init (GucharmapWindowClass *klass);
@@ -570,53 +572,6 @@ move_to_next_screen_cb (GtkAction *action,
}
#endif
-/* create the menu entries */
-
-static const char ui_info [] =
- "<menubar name='MenuBar'>"
- "<menu action='File'>"
-#ifdef ENABLE_PRINTING
- "<menuitem action='PageSetup' />"
-#if 0
- "<menuitem action='PrintPreview' />"
-#endif
- "<menuitem action='Print' />"
- "<separator />"
-#endif /* ENABLE_PRINTING */
- "<menuitem action='Close' />"
-#ifdef DEBUG_chpe
- "<menuitem action='MoveNextScreen' />"
-#endif
- "</menu>"
- "<menu action='View'>"
- "<menuitem action='ByScript' />"
- "<menuitem action='ByUnicodeBlock' />"
- "<separator />"
- "<menuitem action='ShowOnlyGlyphsInFont' />"
- "<menuitem action='SnapColumns' />"
- "<separator />"
- "<menuitem action='ZoomIn' />"
- "<menuitem action='ZoomOut' />"
- "<menuitem action='NormalSize' />"
- "</menu>"
- "<menu action='Search'>"
- "<menuitem action='Find' />"
- "<menuitem action='FindNext' />"
- "<menuitem action='FindPrevious' />"
- "</menu>"
- "<menu action='Go'>"
- "<menuitem action='NextCharacter' />"
- "<menuitem action='PreviousCharacter' />"
- "<separator />"
- "<menuitem action='NextChapter' />"
- "<menuitem action='PreviousChapter' />"
- "</menu>"
- "<menu action='Help'>"
- "<menuitem action='HelpContents' />"
- "<menuitem action='About' />"
- "</menu>"
- "</menubar>";
-
static void
insert_character_in_text_to_copy (GucharmapChartable *chartable,
GucharmapWindow *guw)
@@ -866,7 +821,36 @@ gucharmap_window_init (GucharmapWindow *guw)
gtk_ui_manager_insert_action_group (guw->uimanager, guw->action_group, 0);
g_object_unref (guw->action_group);
- gtk_ui_manager_add_ui_from_string (guw->uimanager, ui_info, strlen (ui_info), NULL);
+ gtk_ui_manager_add_ui_from_resource (guw->uimanager, UI_RESOURCE, NULL);
+
+#ifdef ENABLE_PRINTING
+ {
+ guint merge_id = gtk_ui_manager_new_merge_id (guw->uimanager);
+
+ gtk_ui_manager_add_ui (guw->uimanager, merge_id,
+ "/MenuBar/File/Printing",
+ _("Page _Setup"), "PageSetup",
+ GTK_UI_MANAGER_MENUITEM, FALSE);
+/*
+ gtk_ui_manager_add_ui (guw->uimanager, merge_id,
+ "/MenuBar/File/Printing",
+ _("Print Preview"), "PrintPreview",
+ GTK_UI_MANAGER_MENUITEM, FALSE);
+*/
+ gtk_ui_manager_add_ui (guw->uimanager, merge_id,
+ "/MenuBar/File/Printing",
+ _("_Print"), "Print",
+ GTK_UI_MANAGER_MENUITEM, FALSE);
+ }
+#endif
+
+#ifdef DEBUG_chpe
+ gtk_ui_manager_add_ui (guw->uimanager,
+ gtk_ui_manager_new_merge_id (guw->uimanager),
+ "/MenuBar/File/chpe",
+ "Move window to next screen", "MoveNextScreen",
+ GTK_UI_MANAGER_MENUITEM, FALSE);
+#endif
/* Now the widgets */
grid = gtk_grid_new ();
diff --git a/gucharmap/gucharmap.gresource.xml.in b/gucharmap/gucharmap.gresource.xml.in
new file mode 100644
index 0000000..2eb8a16
--- /dev/null
+++ b/gucharmap/gucharmap.gresource.xml.in
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright  2012 Red Hat, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope conf it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+<gresources>
+ <gresource prefix="/org/gnome/charmap">
+ <file alias="gucharmap-ui.xml">@srcdir@/gucharmap-ui.xml</file>
+ </gresource>
+</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]