From a3d91c0ef8fdc6165b4619790e133641036068ad Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 11 Sep 2009 21:13:58 +0000 Subject: [PATCH] Update the interface definition to use the new version of Glade (3.6 and above.) Glade now writes GtkBuilder files directly, and so we don't have to use gtk-builder-convert to convert a Glade file into a GtkBuilder file. git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@115 ddfedd41-794f-dd11-ae45-00112f111e67 --- tests/Makefile.am | 9 +- tests/callbacks.c | 9 +- tests/callbacks.h | 5 +- tests/chimara.glade | 205 -------------------------------------------- tests/chimara.menus | 14 +++ tests/main.c | 54 ++++++++++-- 6 files changed, 69 insertions(+), 227 deletions(-) delete mode 100644 tests/chimara.glade create mode 100644 tests/chimara.menus diff --git a/tests/Makefile.am b/tests/Makefile.am index ca4bec5..9033f42 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ AM_CFLAGS = -Wall AM_CPPFLAGS = -I$(top_srcdir) -data_DATA = chimara.ui +dist_data_DATA = chimara.ui chimara.menus noinst_PROGRAMS = test-chimara @@ -30,10 +30,3 @@ splittest_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) multiwin_la_SOURCES = multiwin.c multiwin_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) - -CLEANFILES = chimara.ui - -chimara.ui: chimara.glade - gtk-builder-convert $< $@ - -EXTRA_DIST = chimara.glade diff --git a/tests/callbacks.c b/tests/callbacks.c index 6067526..8c6f83e 100644 --- a/tests/callbacks.c +++ b/tests/callbacks.c @@ -31,9 +31,12 @@ */ #include "callbacks.h" +#include "error.h" -void on_save_tool_button_clicked(GtkToolButton *toolbutton, gpointer user_data) { - error_dialog( GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(toolbutton))), NULL, "Not implemented yet" ); +void on_save(GtkAction *action, gpointer user_data) { + GSList *widgets = gtk_action_get_proxies(action); + GtkWindow *top = GTK_WINDOW( gtk_widget_get_toplevel(widgets->data) ); + error_dialog(top, NULL, "Not implemented yet"); } gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { @@ -41,7 +44,7 @@ gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer use return TRUE; } -void on_file_quit_activate(GtkMenuItem *menuitem, gpointer user_data) { +void on_quit(GtkAction *action, gpointer user_data) { gtk_main_quit(); } diff --git a/tests/callbacks.h b/tests/callbacks.h index f14403c..e14a667 100644 --- a/tests/callbacks.h +++ b/tests/callbacks.h @@ -31,8 +31,7 @@ */ #include -#include "error.h" -void on_save_tool_button_clicked(GtkToolButton *toolbutton, gpointer user_data); +void on_save(GtkAction *action, gpointer user_data); gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data); -void on_file_quit_activate(GtkMenuItem *menuitem, gpointer user_data); +void on_quit(GtkAction *action, gpointer user_data); diff --git a/tests/chimara.glade b/tests/chimara.glade deleted file mode 100644 index 558f45b..0000000 --- a/tests/chimara.glade +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - Gargoyle GTK - 500 - 600 - - - - True - - - True - - - True - _File - True - - - True - - - True - Opens an interactive fiction game - gtk-open - True - True - - - - - True - - - - - True - gtk-quit - True - True - - - - - - - - - - True - _Edit - True - - - True - - - True - gtk-cut - True - True - - - - - True - gtk-copy - True - True - - - - - True - gtk-paste - True - True - - - - - True - gtk-delete - True - True - - - - - - - - - True - _Game - True - - - True - - - True - Saves your progress in the game - _Save - True - - - gtk-save - - - - - - - True - Restores a previously saved game - _Restore - True - - - gtk-open - - - - - - - True - Restart the game - Res_tart - True - - - True - gtk-refresh - - - - - - - - - - - True - _Help - True - - - True - - - True - gtk-about - True - True - - - - - - - - - False - - - - - True - - - True - Save - gtk-save - - - - True - - - - - True - Restore - gtk-open - - - True - - - - - False - 1 - - - - - - diff --git a/tests/chimara.menus b/tests/chimara.menus new file mode 100644 index 0000000..233ec4c --- /dev/null +++ b/tests/chimara.menus @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/tests/main.c b/tests/main.c index 0a03c3c..d7f09bb 100644 --- a/tests/main.c +++ b/tests/main.c @@ -46,6 +46,7 @@ /* Global pointers to widgets */ GtkBuilder *builder = NULL; +GtkUIManager *uimanager = NULL; GtkWidget *window = NULL; GtkWidget *glk = NULL; @@ -61,14 +62,51 @@ on_stopped(ChimaraGlk *glk) g_printerr("Stopped!\n"); } +static GObject * +load_object(const gchar *name) +{ + GObject *retval; + if( (retval = gtk_builder_get_object(builder, name)) == NULL) { + error_dialog(NULL, NULL, "Error while getting object '%s'", name); + g_error("Error while getting object '%s'", name); + } + return retval; +} + static void create_window(void) { - if( (window = GTK_WIDGET(gtk_builder_get_object(builder, "gargoyle-gtk"))) == NULL ) { - error_dialog(NULL, NULL, "Error while getting main window object"); + GError *error = NULL; + + builder = gtk_builder_new(); + if( !gtk_builder_add_from_file(builder, "chimara.ui", &error) ) { + error_dialog(NULL, error, "Error while building interface: "); return; } + window = GTK_WIDGET(load_object("chimara")); + GtkActionGroup *actiongroup = GTK_ACTION_GROUP(load_object("actiongroup")); + + /* Add all the actions to the action group. This for-loop is a temporary fix + and can be removed once Glade supports adding actions and accelerators to an + action group. */ + const gchar *actions[] = { + "game", "", + "open", "F7", + "save", NULL, /* NULL means use stock accelerator */ + "quit", NULL, + NULL + }; + const gchar **ptr; + for(ptr = actions; *ptr; ptr += 2) + gtk_action_group_add_action_with_accel(actiongroup, GTK_ACTION(load_object(ptr[0])), ptr[1]); + + GtkUIManager *uimanager = gtk_ui_manager_new(); + if( !gtk_ui_manager_add_ui_from_file(uimanager, "chimara.menus", &error) ) { + error_dialog(NULL, error, "Error while building interface: "); + return; + } + gtk_builder_connect_signals(builder, NULL); glk = chimara_glk_new(); @@ -85,7 +123,13 @@ create_window(void) return; } + gtk_ui_manager_insert_action_group(uimanager, actiongroup, 0); + GtkWidget *menubar = gtk_ui_manager_get_widget(uimanager, "/menubar"); + GtkWidget *toolbar = gtk_ui_manager_get_widget(uimanager, "/toolbar"); + gtk_box_pack_end(vbox, glk, TRUE, TRUE, 0); + gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0); + gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0); } int @@ -107,12 +151,6 @@ main(int argc, char *argv[]) gtk_set_locale(); gtk_init(&argc, &argv); - builder = gtk_builder_new(); - if( !gtk_builder_add_from_file(builder, "chimara.ui", &error) ) { - error_dialog(NULL, error, "Error while building interface: "); - return 1; - } - create_window(); gtk_widget_show_all(window); -- 2.30.2