Update the interface definition to use the new version of Glade (3.6 and
authorfliep <fliep@ddfedd41-794f-dd11-ae45-00112f111e67>
Fri, 11 Sep 2009 21:13:58 +0000 (21:13 +0000)
committerfliep <fliep@ddfedd41-794f-dd11-ae45-00112f111e67>
Fri, 11 Sep 2009 21:13:58 +0000 (21:13 +0000)
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.

tests/Makefile.am
tests/callbacks.c
tests/callbacks.h
tests/chimara.glade [deleted file]
tests/chimara.menus [new file with mode: 0644]
tests/main.c

index ca4bec5c1365c4056f5b154212c2403bbdb69c77..9033f4287e9c8c8d5bb7559025aee7dbe567818f 100644 (file)
@@ -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
index 6067526bde9fab7ed7848d83b90a7508d58d8e91..8c6f83e29a299d224e26e18bf4a6e61869fa08ee 100644 (file)
  */
 
 #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();
 }
 
index f14403cc931b0a61c2e95c0acd81c656a86f7b4e..e14a66727e901eca5704a495c87171cded8b520e 100644 (file)
@@ -31,8 +31,7 @@
  */
 
 #include <gtk/gtk.h>
-#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 (file)
index 558f45b..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Wed May  6 22:39:03 2009 -->
-<glade-interface>
-  <widget class="GtkWindow" id="gargoyle-gtk">
-    <property name="title" translatable="yes">Gargoyle GTK</property>
-    <property name="default_width">500</property>
-    <property name="default_height">600</property>
-    <signal name="delete_event" handler="on_window_delete_event"/>
-    <child>
-      <widget class="GtkVBox" id="vbox">
-        <property name="visible">True</property>
-        <child>
-          <widget class="GtkMenuBar" id="menubar">
-            <property name="visible">True</property>
-            <child>
-              <widget class="GtkMenuItem" id="file_menu">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_File</property>
-                <property name="use_underline">True</property>
-                <child>
-                  <widget class="GtkMenu" id="menu1">
-                    <property name="visible">True</property>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="file_open">
-                        <property name="visible">True</property>
-                        <property name="tooltip" translatable="yes">Opens an interactive fiction game</property>
-                        <property name="label" translatable="yes">gtk-open</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
-                        <property name="visible">True</property>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="file_quit">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">gtk-quit</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_file_quit_activate"/>
-                      </widget>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkMenuItem" id="edit_menu">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Edit</property>
-                <property name="use_underline">True</property>
-                <child>
-                  <widget class="GtkMenu" id="menu2">
-                    <property name="visible">True</property>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="edit_cut_menu_item">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">gtk-cut</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="edit_copy_menu_item">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">gtk-copy</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="edit_paste_menu_item">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">gtk-paste</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="edit_delete_menu_item">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">gtk-delete</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </widget>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkMenuItem" id="game_menu">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Game</property>
-                <property name="use_underline">True</property>
-                <child>
-                  <widget class="GtkMenu" id="menu4">
-                    <property name="visible">True</property>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="game_save_menu_item">
-                        <property name="visible">True</property>
-                        <property name="tooltip" translatable="yes">Saves your progress in the game</property>
-                        <property name="label" translatable="yes">_Save</property>
-                        <property name="use_underline">True</property>
-                        <child internal-child="image">
-                          <widget class="GtkImage" id="menu-item-image13">
-                            <property name="stock">gtk-save</property>
-                          </widget>
-                        </child>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="game_restore_menu_item">
-                        <property name="visible">True</property>
-                        <property name="tooltip" translatable="yes">Restores a previously saved game</property>
-                        <property name="label" translatable="yes">_Restore</property>
-                        <property name="use_underline">True</property>
-                        <child internal-child="image">
-                          <widget class="GtkImage" id="menu-item-image12">
-                            <property name="stock">gtk-open</property>
-                          </widget>
-                        </child>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="game_restart_menu_item">
-                        <property name="visible">True</property>
-                        <property name="tooltip" translatable="yes">Restart the game</property>
-                        <property name="label" translatable="yes">Res_tart</property>
-                        <property name="use_underline">True</property>
-                        <child internal-child="image">
-                          <widget class="GtkImage" id="menu-item-image11">
-                            <property name="visible">True</property>
-                            <property name="stock">gtk-refresh</property>
-                          </widget>
-                        </child>
-                      </widget>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkMenuItem" id="help_menu">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Help</property>
-                <property name="use_underline">True</property>
-                <child>
-                  <widget class="GtkMenu" id="menu3">
-                    <property name="visible">True</property>
-                    <child>
-                      <widget class="GtkImageMenuItem" id="help_about_menu_item">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">gtk-about</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </widget>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-          </packing>
-        </child>
-        <child>
-          <widget class="GtkToolbar" id="toolbar">
-            <property name="visible">True</property>
-            <child>
-              <widget class="GtkToolButton" id="save_tool_button">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Save</property>
-                <property name="stock_id">gtk-save</property>
-                <signal name="clicked" handler="on_save_tool_button_clicked"/>
-              </widget>
-              <packing>
-                <property name="homogeneous">True</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkToolButton" id="restore_tool_button">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Restore</property>
-                <property name="stock_id">gtk-open</property>
-              </widget>
-              <packing>
-                <property name="homogeneous">True</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-  </widget>
-</glade-interface>
diff --git a/tests/chimara.menus b/tests/chimara.menus
new file mode 100644 (file)
index 0000000..233ec4c
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<ui>
+  <menubar>
+    <menu action="game">
+      <menuitem action="open"/>
+      <menuitem action="save"/>
+      <separator/>
+      <menuitem action="quit"/>
+    </menu>
+  </menubar>
+  <toolbar>
+    <toolitem action="save"/>
+  </toolbar>
+</ui>
index 0a03c3c535a93c0a9df444fc9b4297e01490fa24..d7f09bb52c1e236d00d20ab27f57510ef8202c08 100644 (file)
@@ -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", "<ctrl>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);