[gtk+] bloatpad: use resources



commit b40672f145278963fb4218fc9e0a7b320d08716e
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Jul 2 20:35:49 2014 -0400

    bloatpad: use resources
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722092

 examples/bp/Makefile.am             |   13 +++++
 examples/bp/bloatpad.c              |   86 +----------------------------------
 examples/bp/bloatpad.gresources.xml |    7 +++
 examples/bp/menus.ui                |   83 +++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 84 deletions(-)
---
diff --git a/examples/bp/Makefile.am b/examples/bp/Makefile.am
index 5e92490..827432d 100644
--- a/examples/bp/Makefile.am
+++ b/examples/bp/Makefile.am
@@ -13,4 +13,17 @@ LDADD = \
 
 noinst_PROGRAMS = bloatpad
 
+
+bloatpad_SOURCES = bloatpad.c
+nodist_bloatpad_SOURCES = bloatpad-gresources.c
+
+resource_files = \
+       bloatpad.gresources.xml         \
+       menus.ui
+
+bloatpad-gresources.c: $(resource_files)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
+
+CLEANFILES = bloatpad-gresources.c
+
 -include $(top_srcdir)/git.mk
diff --git a/examples/bp/bloatpad.c b/examples/bp/bloatpad.c
index 1eae5b6..c0e2d7d 100644
--- a/examples/bp/bloatpad.c
+++ b/examples/bp/bloatpad.c
@@ -537,89 +537,7 @@ bloat_pad_startup (GApplication *application)
 
   g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), 
application);
 
-  builder = gtk_builder_new ();
-  gtk_builder_add_from_string (builder,
-                               "<interface>"
-                               "  <menu id='app-menu'>"
-                               "    <section>"
-                               "      <item>"
-                               "        <attribute name='label' translatable='yes'>_New Window</attribute>"
-                               "        <attribute name='action'>app.new</attribute>"
-                               "      </item>"
-                               "    </section>"
-                               "    <section>"
-                               "      <item>"
-                               "        <attribute name='label' translatable='yes'>_About 
Bloatpad</attribute>"
-                               "        <attribute name='action'>app.about</attribute>"
-                               "      </item>"
-                               "    </section>"
-                               "    <section>"
-                               "      <item>"
-                               "        <attribute name='label' translatable='yes'>_Quit</attribute>"
-                               "        <attribute name='action'>app.quit</attribute>"
-                               "      </item>"
-                               "    </section>"
-                               "  </menu>"
-                               "  <menu id='menubar'>"
-                               "    <submenu>"
-                               "      <attribute name='label' translatable='yes'>_Edit</attribute>"
-                               "      <section>"
-                               "        <item>"
-                               "          <attribute name='label' translatable='yes'>_Copy</attribute>"
-                               "          <attribute name='action'>win.copy</attribute>"
-                               "        </item>"
-                               "        <item>"
-                               "          <attribute name='label' translatable='yes'>_Paste</attribute>"
-                               "          <attribute name='action'>win.paste</attribute>"
-                               "        </item>"
-                               "      </section>"
-                               "      <section>"
-                               "        <item>"
-                               "          <attribute name='label'>Clear (always shown)</attribute>"
-                               "          <attribute name='action'>win.clear</attribute>"
-                                                   /* action should never be missing (so always shown) */
-                               "          <attribute name='hidden-when'>action-missing</attribute>"
-                               "        </item>"
-                               "        <item>"
-                               "          <attribute name='label'>Clear (hidden when no text)</attribute>"
-                               "          <attribute name='hidden-when'>action-disabled</attribute>"
-                               "          <attribute name='action'>win.clear</attribute>"
-                               "        </item>"
-                               "        <item>"
-                               "          <attribute name='label'>Spell check (does nothing, 
hides)</attribute>"
-                               "          <attribute name='hidden-when'>action-missing</attribute>"
-                               "          <attribute name='action'>win.spell-check</attribute>"
-                               "        </item>"
-                               "      </section>"
-                               "      <section>"
-                               "        <item>"
-                               "          <attribute name='label' 
translatable='yes'>Accelerators...</attribute>"
-                               "          <attribute name='action'>app.edit-accels</attribute>"
-                               "        </item>"
-                               "      </section>"
-                               "    </submenu>"
-                               "    <submenu>"
-                               "      <attribute name='label' translatable='yes'>_View</attribute>"
-                               "      <section>"
-                               "        <item>"
-                               "          <attribute name='label' translatable='yes'>_Fullscreen</attribute>"
-                               "          <attribute name='action'>win.fullscreen</attribute>"
-                               "        </item>"
-                               "        <item>"
-                               "          <attribute name='label' translatable='yes'>_Look Busy</attribute>"
-                               "          <attribute name='action'>win.busy</attribute>"
-                               "        </item>"
-                               "      </section>"
-                               "    </submenu>"
-                               "    <submenu id='icon-menu'>"
-                               "      <attribute name='label' translatable='yes'>_Icons</attribute>"
-                               "    </submenu>"
-                               "    <submenu id='time-menu'>"
-                               "      <attribute name='label' translatable='yes'>Time</attribute>"
-                               "      <attribute name='submenu-action'>app.time-active</attribute>"
-                               "    </submenu>"
-                               "  </menu>"
-                               "</interface>", -1, NULL);
+  builder = gtk_builder_new_from_resource ("/org/gtk/bloatpad/menus.ui");
   gtk_application_set_app_menu (app, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
   gtk_application_set_menubar (app, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   for (i = 0; i < G_N_ELEMENTS (accels); i++)
@@ -738,7 +656,7 @@ bloat_pad_new (void)
   g_set_application_name ("Bloatpad");
 
   bloat_pad = g_object_new (bloat_pad_get_type (),
-                            "application-id", "org.gtk.Test.bloatpad",
+                            "application-id", "org.gtk.bloatpad",
                             "flags", G_APPLICATION_HANDLES_OPEN,
                             "inactivity-timeout", 30000,
                             "register-session", TRUE,
diff --git a/examples/bp/bloatpad.gresources.xml b/examples/bp/bloatpad.gresources.xml
new file mode 100644
index 0000000..beee6b2
--- /dev/null
+++ b/examples/bp/bloatpad.gresources.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<gresources>
+  <gresource prefix="/org/gtk/bloatpad">
+    <file preprocess="xml-stripblanks">menus.ui</file>
+  </gresource>
+</gresources>
diff --git a/examples/bp/menus.ui b/examples/bp/menus.ui
new file mode 100644
index 0000000..a05986f
--- /dev/null
+++ b/examples/bp/menus.ui
@@ -0,0 +1,83 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<interface>
+  <menu id='app-menu'>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_New Window</attribute>
+        <attribute name='action'>app.new</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_About Bloatpad</attribute>
+        <attribute name='action'>app.about</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_Quit</attribute>
+        <attribute name='action'>app.quit</attribute>
+      </item>
+    </section>
+  </menu>
+  <menu id='menubar'>
+    <submenu>
+      <attribute name='label' translatable='yes'>_Edit</attribute>
+      <section>
+        <item>
+          <attribute name='label' translatable='yes'>_Copy</attribute>
+          <attribute name='action'>win.copy</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>_Paste</attribute>
+          <attribute name='action'>win.paste</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <!-- action should never be missing (so always shown) -->
+          <attribute name='label'>Clear (always shown)</attribute>
+          <attribute name='action'>win.clear</attribute>
+          <attribute name='hidden-when'>action-missing</attribute>
+        </item>
+        <item>
+          <attribute name='label'>Clear (hidden when no text)</attribute>
+          <attribute name='hidden-when'>action-disabled</attribute>
+          <attribute name='action'>win.clear</attribute>
+        </item>
+        <item>
+          <attribute name='label'>Spell check (does nothing, hides)</attribute>
+          <attribute name='hidden-when'>action-missing</attribute>
+          <attribute name='action'>win.spell-check</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name='label' translatable='yes'>Accelerators...</attribute>
+          <attribute name='action'>app.edit-accels</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name='label' translatable='yes'>_View</attribute>
+      <section>
+        <item>
+          <attribute name='label' translatable='yes'>_Fullscreen</attribute>
+          <attribute name='action'>win.fullscreen</attribute>
+        </item>
+        <item>
+          <attribute name='label' translatable='yes'>_Look Busy</attribute>
+          <attribute name='action'>win.busy</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu id='icon-menu'>
+      <attribute name='label' translatable='yes'>_Icons</attribute>
+    </submenu>
+    <submenu id='time-menu'>
+      <attribute name='label' translatable='yes'>Time</attribute>
+      <attribute name='submenu-action'>app.time-active</attribute>
+    </submenu>
+  </menu>
+</interface>


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