[gtk+] Add an example for settings<>action integration



commit 3104e5d2c192fa1d31fbf73049c0ad140888e059
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 24 00:07:03 2012 -0500

    Add an example for settings<>action integration
    
    Turn the 'color' action in gtk3-demo-application into an
    action that is backed by a setting.

 demos/gtk-demo/Makefile.am              |    8 +++++++-
 demos/gtk-demo/application.c            |    8 +++++++-
 demos/gtk-demo/menus.ui                 |    6 +++---
 demos/gtk-demo/org.gtk.Demo.gschema.xml |   17 +++++++++++++++++
 4 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 4b38fe6..db62767 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -77,7 +77,13 @@ EXTRA_DIST += 				\
 	application.ui			\
 	menus.ui			\
 	gtk-logo-24.png			\
-	gtk-logo-48.png
+	gtk-logo-48.png			\
+	org.gtk.Demo.gschema.xml
+
+gsettings_SCHEMAS = \
+	org.gtk.Demo.gschema.xml
+
+ GSETTINGS_RULES@
 
 demos.h: @REBUILD@ $(demos) geninclude.pl
 	$(AM_V_GEN) (here=`pwd` ; cd $(srcdir) && $(PERL) $$here/geninclude.pl $(demos)) > demos.h
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index 27c70e2..95d4be9 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -280,7 +280,6 @@ static GActionEntry app_entries[] = {
 
 static GActionEntry win_entries[] = {
   { "titlebar", activate_toggle, NULL, "false", change_titlebar_state },
-  { "color", activate_radio, "s", "'red'", change_radio_state },
   { "shape", activate_radio, "s", "'oval'", change_radio_state },
   { "bold", activate_toggle, NULL, "false", NULL },
   { "about", activate_about, NULL, NULL, NULL },
@@ -370,17 +369,24 @@ int
 main (int argc, char *argv[])
 {
   GtkApplication *app;
+  GSettings *settings;
+  GAction *action;
 
   gtk_init (NULL, NULL);
 
   register_stock_icons ();
 
   app = gtk_application_new ("org.gtk.Demo", 0);
+  settings = g_settings_new ("org.gtk.Demo");
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
 
+  action = g_settings_create_action (settings, "color");
+
+  g_action_map_add_action (G_ACTION_MAP (app), action);
+
   g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
 
diff --git a/demos/gtk-demo/menus.ui b/demos/gtk-demo/menus.ui
index 410596b..2f1e105 100644
--- a/demos/gtk-demo/menus.ui
+++ b/demos/gtk-demo/menus.ui
@@ -18,9 +18,9 @@
         <item label="_Hide Titlebar when maximized" action="win.titlebar"/>
         <submenu label="_Color">
           <section>
-            <item label="_Red" action="win.color" target="red" accel="&lt;Primary&gt;r"/>
-            <item label="_Green" action="win.color" target="green" accel="&lt;Primary&gt;g"/>
-            <item label="_Blue" action="win.color" target="blue" accel="&lt;Primary&gt;b"/>
+            <item label="_Red" action="app.color" target="red" accel="&lt;Primary&gt;r"/>
+            <item label="_Green" action="app.color" target="green" accel="&lt;Primary&gt;g"/>
+            <item label="_Blue" action="app.color" target="blue" accel="&lt;Primary&gt;b"/>
           </section>
         </submenu>
         <submenu label="_Shape">
diff --git a/demos/gtk-demo/org.gtk.Demo.gschema.xml b/demos/gtk-demo/org.gtk.Demo.gschema.xml
new file mode 100644
index 0000000..33e12aa
--- /dev/null
+++ b/demos/gtk-demo/org.gtk.Demo.gschema.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<schemalist>
+
+  <enum id='org.gtk.Demo.Color'>
+    <value nick='red'   value='0'/>
+    <value nick='green' value='1'/>
+    <value nick='blue'  value='2'/>
+  </enum>
+
+  <schema id='org.gtk.Demo' path='/org/gtk/Demo/'>
+    <key name='color' enum='org.gtk.Demo.Color'>
+      <default>'red'</default>
+    </key>
+  </schema>
+
+</schemalist>



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