[gtk+] gtk-demo: Improve the GtkApplication demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk-demo: Improve the GtkApplication demo
- Date: Mon, 16 Jan 2012 22:07:38 +0000 (UTC)
commit 2a6a354aa84af4c72a9fee88f0ef85c0fb424d0d
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jan 16 17:07:12 2012 -0500
gtk-demo: Improve the GtkApplication demo
Following suggestions in bug 667968
demos/gtk-demo/Makefile.am | 17 ++++++------
demos/gtk-demo/application.c | 36 ++++++++++++++++---------
demos/gtk-demo/application.gresource.xml | 1 +
demos/gtk-demo/application.ui | 41 ------------------------------
demos/gtk-demo/menus.ui | 34 ++++++++++++++++++++++++
5 files changed, 67 insertions(+), 62 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 3396a99..4b38fe6 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -70,12 +70,13 @@ bin_PROGRAMS = gtk3-demo gtk3-demo-application
BUILT_SOURCES = demos.h application_resources.c
-EXTRA_DIST += \
- $(IMAGEFILES) \
- demo.ui \
- application.gresource.xml \
- application.ui \
- gtk-logo-24.png \
+EXTRA_DIST += \
+ $(IMAGEFILES) \
+ demo.ui \
+ application.gresource.xml \
+ application.ui \
+ menus.ui \
+ gtk-logo-24.png \
gtk-logo-48.png
demos.h: @REBUILD@ $(demos) geninclude.pl
@@ -97,8 +98,8 @@ gtk3_demo_application_SOURCES = \
gtk3_demo_application_LDADD = $(LDADDS)
-application_resources.c: application.gresource.xml gtk-logo-24.png gtk-logo-48.png application.ui
- glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source $(srcdir)/application.gresource.xml
+application_resources.c: application.gresource.xml gtk-logo-24.png gtk-logo-48.png application.ui menus.ui
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $(srcdir)/application.gresource.xml
IMAGEFILES= alphatest.png \
apple-red.png \
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index fc27dec..27c70e2 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -294,6 +294,25 @@ clicked_cb (GtkWidget *widget, GtkWidget *info)
}
static void
+startup (GApplication *app)
+{
+ GtkBuilder *builder;
+ GMenuModel *appmenu;
+ GMenuModel *menubar;
+
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_resource (builder, "/ui/menus.ui", NULL);
+
+ appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
+ menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
+
+ gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
+ gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
+
+ g_object_unref (builder);
+}
+
+static void
activate (GApplication *app)
{
GtkBuilder *builder;
@@ -305,10 +324,6 @@ activate (GApplication *app)
GtkWidget *button;
GtkWidget *infobar;
GtkTextBuffer *buffer;
- GMenuModel *appmenu, *menubar;
- GBytes *bytes;
- const gchar *data;
- gsize size;
window = gtk_application_window_new (GTK_APPLICATION (app));
gtk_window_set_title (GTK_WINDOW (window), "Application Class");
@@ -320,15 +335,9 @@ activate (GApplication *app)
window);
builder = gtk_builder_new ();
-
- bytes = g_resources_lookup_data ("/ui/application.ui", 0, NULL);
- data = g_bytes_get_data (bytes, &size);
- gtk_builder_add_from_string (builder, data, size, NULL);
- g_bytes_unref (bytes);
+ gtk_builder_add_from_resource (builder, "/ui/application.ui", NULL);
grid = (GtkWidget *)gtk_builder_get_object (builder, "grid");
- appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
- menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
contents = (GtkWidget *)gtk_builder_get_object (builder, "contents");
status = (GtkWidget *)gtk_builder_get_object (builder, "status");
message = (GtkWidget *)gtk_builder_get_object (builder, "message");
@@ -339,8 +348,6 @@ activate (GApplication *app)
g_object_set_data (G_OBJECT (window), "infobar", infobar);
gtk_container_add (GTK_CONTAINER (window), grid);
- gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
- gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
gtk_widget_grab_focus (contents);
g_signal_connect (button, "clicked", G_CALLBACK (clicked_cb), infobar);
@@ -355,6 +362,8 @@ activate (GApplication *app)
update_statusbar (buffer, GTK_STATUSBAR (status));
gtk_widget_show_all (window);
+
+ g_object_unref (builder);
}
int
@@ -372,6 +381,7 @@ main (int argc, char *argv[])
app_entries, G_N_ELEMENTS (app_entries),
app);
+ g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_application_run (G_APPLICATION (app), 0, NULL);
diff --git a/demos/gtk-demo/application.gresource.xml b/demos/gtk-demo/application.gresource.xml
index 80fcc47..ed5c81e 100644
--- a/demos/gtk-demo/application.gresource.xml
+++ b/demos/gtk-demo/application.gresource.xml
@@ -6,5 +6,6 @@
</gresource>
<gresource prefix="/ui">
<file>application.ui</file>
+ <file>menus.ui</file>
</gresource>
</gresources>
diff --git a/demos/gtk-demo/application.ui b/demos/gtk-demo/application.ui
index 0dcee00..af92b1c 100644
--- a/demos/gtk-demo/application.ui
+++ b/demos/gtk-demo/application.ui
@@ -106,45 +106,4 @@
</packing>
</child>
</object>
- <menu id="appmenu">
- <section>
- <item label="_New" action="app.new" accel="<Primary>n"/>
- <item label="_Open" action="app.open"/>
- <item label="_Save" action="app.save" accel="<Primary>s"/>
- <item label="Save _As..." action="app.save-as" accel="<Primary>s"/>
- </section>
- <section>
- <item label="_Quit" action="app.quit" accel="<Primary>q"/>
- </section>
- </menu>
- <menu id="menubar">
- <section>
- <submenu label="_Preferences">
- <section>
- <item label="_Prefer Dark Theme" action="app.dark"/>
- <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"/>
- </section>
- </submenu>
- <submenu label="_Shape">
- <section>
- <item label="_Square" action="win.shape" target="square" accel="<Primary>s"/>
- <item label="_Rectangle" action="win.shape" target="rectangle" accel="<Primary>r"/>
- <item label="_Oval" action="win.shape" target="oval" accel="<Primary>o"/>
- </section>
- </submenu>
- <item label="_Bold" action="win.bold" accel="<Primary>b"/>
- </section>
- </submenu>
- <submenu label="_Help">
- <section>
- <item label="_About" action="win.about" accel="<Primary>a"/>
- </section>
- </submenu>
- </section>
- </menu>
</interface>
diff --git a/demos/gtk-demo/menus.ui b/demos/gtk-demo/menus.ui
new file mode 100644
index 0000000..da30b4f
--- /dev/null
+++ b/demos/gtk-demo/menus.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<interface>
+ <menu id="appmenu">
+ <section>
+ <item label="_New" action="app.new" accel="<Primary>n"/>
+ <item label="_Open" action="app.open"/>
+ <item label="_Save" action="app.save" accel="<Primary>s"/>
+ <item label="Save _As..." action="app.save-as" accel="<Primary>s"/>
+ </section>
+ <section>
+ <item label="_Quit" action="app.quit" accel="<Primary>q"/>
+ </section>
+ </menu>
+ <menu id="menubar">
+ <submenu label="_Preferences">
+ <item label="_Prefer Dark Theme" action="app.dark"/>
+ <item label="_Hide Titlebar when maximized" action="win.titlebar"/>
+ <submenu label="_Color">
+ <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"/>
+ </submenu>
+ <submenu label="_Shape">
+ <item label="_Square" action="win.shape" target="square" accel="<Primary>s"/>
+ <item label="_Rectangle" action="win.shape" target="rectangle" accel="<Primary>r"/>
+ <item label="_Oval" action="win.shape" target="oval" accel="<Primary>o"/>
+ </submenu>
+ <item label="_Bold" action="win.bold" accel="<Primary>b"/>
+ </submenu>
+ <submenu label="_Help">
+ <item label="_About" action="win.about" accel="<Primary>a"/>
+ </submenu>
+ </menu>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]