forked from AuroraMiddleware/gtk
Add an example for settings<>action integration
Turn the 'color' action in gtk3-demo-application into an action that is backed by a setting.
This commit is contained in:
parent
0363a7a2e3
commit
3104e5d2c1
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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="<Primary>r"/>
|
||||
<item label="_Green" action="win.color" target="green" accel="<Primary>g"/>
|
||||
<item label="_Blue" action="win.color" target="blue" accel="<Primary>b"/>
|
||||
<item label="_Red" action="app.color" target="red" accel="<Primary>r"/>
|
||||
<item label="_Green" action="app.color" target="green" accel="<Primary>g"/>
|
||||
<item label="_Blue" action="app.color" target="blue" accel="<Primary>b"/>
|
||||
</section>
|
||||
</submenu>
|
||||
<submenu label="_Shape">
|
||||
|
17
demos/gtk-demo/org.gtk.Demo.gschema.xml
Normal file
17
demos/gtk-demo/org.gtk.Demo.gschema.xml
Normal file
@ -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>
|
Loading…
Reference in New Issue
Block a user