Commit 9a7ea73f603de2ef3dfa522351d901b8e60700d3
1 parent
19751b8c
Exists in
master
and in
4 other branches
Researching about gtkbuilder.
Showing
2 changed files
with
90 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<interface> | ||
| 3 | + <requires lib="gtk+" version="3.0"/> | ||
| 4 | + <menu id="app-menu"> | ||
| 5 | + <section> | ||
| 6 | + <item> | ||
| 7 | + <attribute name="label" translatable="yes">About</attribute> | ||
| 8 | + <attribute name="action">app.about</attribute> | ||
| 9 | + </item> | ||
| 10 | + <item> | ||
| 11 | + <attribute name="label" translatable="yes">Help</attribute> | ||
| 12 | + <attribute name="action">app.help</attribute> | ||
| 13 | + <attribute name="accel">F1</attribute> | ||
| 14 | + </item> | ||
| 15 | + <item> | ||
| 16 | + <attribute name="label" translatable="yes">Quit</attribute> | ||
| 17 | + <attribute name="action">app.quit</attribute> | ||
| 18 | + <attribute name="accel"><Primary>q</attribute> | ||
| 19 | + </item> | ||
| 20 | + </section> | ||
| 21 | + </menu> | ||
| 22 | +</interface> | ||
| 23 | + |
src/objects/window/testprogram/testprogram.c
| @@ -85,6 +85,72 @@ GtkWidget * pw3270_toolbar_new(void) { | @@ -85,6 +85,72 @@ GtkWidget * pw3270_toolbar_new(void) { | ||
| 85 | return toolbar; | 85 | return toolbar; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | +static void preferences_activated(GSimpleAction * action, GtkApplication *application) { | ||
| 89 | + | ||
| 90 | + debug("%s",__FUNCTION__); | ||
| 91 | + | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +static void quit_activated(GSimpleAction * action, GVariant *parameter, gpointer application) { | ||
| 95 | + | ||
| 96 | + debug("%s",__FUNCTION__); | ||
| 97 | + | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +void startup(GtkApplication *application, gpointer user_data) { | ||
| 101 | + | ||
| 102 | + static GActionEntry app_entries[] = { | ||
| 103 | + { | ||
| 104 | + "app.about", | ||
| 105 | + quit_activated, | ||
| 106 | + NULL, | ||
| 107 | + NULL, | ||
| 108 | + NULL | ||
| 109 | + }, | ||
| 110 | + { | ||
| 111 | + "app.help", | ||
| 112 | + quit_activated, | ||
| 113 | + NULL, | ||
| 114 | + NULL, | ||
| 115 | + NULL | ||
| 116 | + }, | ||
| 117 | + { | ||
| 118 | + "app.preferences", | ||
| 119 | + preferences_activated, | ||
| 120 | + NULL, | ||
| 121 | + NULL, | ||
| 122 | + NULL | ||
| 123 | + }, | ||
| 124 | + { | ||
| 125 | + "app.quit", | ||
| 126 | + quit_activated, | ||
| 127 | + NULL, | ||
| 128 | + NULL, | ||
| 129 | + NULL | ||
| 130 | + } | ||
| 131 | + }; | ||
| 132 | + | ||
| 133 | + g_action_map_add_action_entries( | ||
| 134 | + G_ACTION_MAP(application), | ||
| 135 | + app_entries, | ||
| 136 | + G_N_ELEMENTS(app_entries), | ||
| 137 | + application | ||
| 138 | + ); | ||
| 139 | + | ||
| 140 | + GtkBuilder * builder = gtk_builder_new_from_file("application.ui"); | ||
| 141 | + | ||
| 142 | + debug("Builder: %p",builder); | ||
| 143 | + | ||
| 144 | + GMenuModel * app_menu = G_MENU_MODEL(gtk_builder_get_object(builder, "app-menu")); | ||
| 145 | + debug("app-menu: %p", app_menu); | ||
| 146 | + gtk_application_set_app_menu(application, app_menu); | ||
| 147 | + | ||
| 148 | + | ||
| 149 | + // gtk_application_set_menubar(application, G_MENU_MODEL(gtk_builder_get_object(builder, "app-menubar"))); | ||
| 150 | + | ||
| 151 | + g_object_unref(builder); | ||
| 152 | +} | ||
| 153 | + | ||
| 88 | int main (int argc, char **argv) { | 154 | int main (int argc, char **argv) { |
| 89 | 155 | ||
| 90 | GtkApplication *app; | 156 | GtkApplication *app; |
| @@ -93,6 +159,7 @@ int main (int argc, char **argv) { | @@ -93,6 +159,7 @@ int main (int argc, char **argv) { | ||
| 93 | app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); | 159 | app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); |
| 94 | 160 | ||
| 95 | g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); | 161 | g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); |
| 162 | + g_signal_connect (app, "startup", G_CALLBACK(startup), NULL); | ||
| 96 | 163 | ||
| 97 | status = g_application_run (G_APPLICATION (app), argc, argv); | 164 | status = g_application_run (G_APPLICATION (app), argc, argv); |
| 98 | g_object_unref (app); | 165 | g_object_unref (app); |