]> Pileus Git - ~andy/gtk/commitdiff
Add an example for settings<>action integration
authorMatthias Clasen <mclasen@redhat.com>
Tue, 24 Jan 2012 05:07:03 +0000 (00:07 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 24 Jan 2012 05:07:03 +0000 (00:07 -0500)
Turn the 'color' action in gtk3-demo-application into an
action that is backed by a setting.

demos/gtk-demo/Makefile.am
demos/gtk-demo/application.c
demos/gtk-demo/menus.ui
demos/gtk-demo/org.gtk.Demo.gschema.xml [new file with mode: 0644]

index 4b38fe668978f2052489b945d91eaa90af74ac8e..db62767b71cb70273c58f7e70ae143f61376207c 100644 (file)
@@ -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
index 27c70e29a9ebeaca8a22d4384ab95565325c3c78..95d4be95815a7ea85d399f6c917393a1c4f92cb8 100644 (file)
@@ -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);
 
index 410596b036ba229188d2d022b9eec6982e99e1dc..2f1e105f6beb7e5f6612c8a01af68afaba036b3a 100644 (file)
@@ -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 (file)
index 0000000..33e12aa
--- /dev/null
@@ -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>