Added mapping custom types

This commit is contained in:
Yevgen Muntyan 2005-09-10 21:11:40 +00:00
parent f077958174
commit 968a4a4b03
13 changed files with 365 additions and 460 deletions

View File

@ -793,7 +793,7 @@ GtkWidget *moo_bookmark_mgr_get_editor (MooBookmarkMgr *mgr)
if (mgr->priv->editor)
return mgr->priv->editor;
xml = moo_glade_xml_parse_file (MOO_BOOKMARK_EDITOR_GLADE_FILE, NULL);
xml = moo_glade_xml_new (MOO_BOOKMARK_EDITOR_GLADE_FILE, NULL);
if (!xml)
g_error ("Yes, glade is great usually, but not always");

View File

@ -254,7 +254,7 @@ create_dialog (MooEditWindow *window,
{
GtkWidget *dir_entry, *pattern_entry;
stuff->xml = moo_glade_xml_parse_memory (MOO_GREP_GLADE_XML, -1, NULL);
stuff->xml = moo_glade_xml_new_from_buf (MOO_GREP_GLADE_XML, -1, NULL);
g_return_if_fail (stuff->xml != NULL);
stuff->dialog = moo_glade_xml_get_widget (stuff->xml, "dialog");

View File

@ -14,7 +14,7 @@ AM_CFLAGS = \
$(XML_CFLAGS) \
-DG_LOG_DOMAIN=\"Moo\"
noinst_LTLIBRARIES = libmooui.la
noinst_LTLIBRARIES = libmooui.la
libmooui_la_SOURCES = \
mooaccel.c \
@ -25,9 +25,9 @@ libmooui_la_SOURCES = \
mooactiongroup.h \
moomenuaction.c \
moomenuaction.h \
mooshortcutsprefs-glade.c \
mooshortcutsprefs.c \
mooshortcutsprefs.h \
mooshortcutsprefs-glade.h \
mootext.c \
mootext.h \
mootoggleaction.c \
@ -44,10 +44,8 @@ EXTRA_DIST = \
moouimanager.cpp \
moouimanager.h
BUILT_SOURCES = mooshortcutsprefs-glade.c
BUILT_SOURCES = mooshortcutsprefs-glade.h
GLADE = $(srcdir)/glade
SUPPORT = $(top_srcdir)/$(MOO_SRC_PREFIX)/mooutils/glade/support.sh
mooshortcutsprefs-glade.c: $(GLADE)/shortcutsprefs.c $(GLADE)/shortcutsprefs.sed $(SUPPORT)
cat $(GLADE)/shortcutsprefs.c | sh $(SUPPORT) | \
sed -f $(GLADE)/shortcutsprefs.sed > mooshortcutsprefs-glade.c
mooshortcutsprefs-glade.h: $(srcdir)/glade/shortcutsprefs.glade $(srcdir)/../mooutils/xml2h.sh
sh $(srcdir)/../mooutils/xml2h.sh MOO_SHORTCUTS_PREFS_GLADE_UI \
$(srcdir)/glade/shortcutsprefs.glade > mooshortcutsprefs-glade.h

View File

@ -3,7 +3,4 @@
#
EXTRA_DIST = \
shortcutsprefs.c \
shortcutsprefs.gladep \
shortcutsprefs.glade \
shortcutsprefs.sed
shortcutsprefs.glade

View File

@ -1,260 +0,0 @@
/*
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "callbacks.h"
#include "shortcutsprefs.h"
#include "support.h"
#define GLADE_HOOKUP_OBJECT(component,widget,name) \
g_object_set_data_full (G_OBJECT (component), name, \
gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
g_object_set_data (G_OBJECT (component), name, widget)
GtkWidget*
create_window (void)
{
GtkWidget *window;
GtkWidget *page;
GtkWidget *hbox9;
GtkWidget *label64;
GtkWidget *seach;
GtkWidget *scrolledwindow;
GtkWidget *treeview;
GtkWidget *shortcut_frame;
GtkWidget *alignment29;
GtkWidget *vbox11;
GtkWidget *hbox10;
GtkWidget *shortcut_none;
GSList *shortcut_none_group = NULL;
GtkWidget *shortcut_default;
GtkWidget *shortcut_custom;
GtkWidget *shortcut;
GtkWidget *hbox11;
GtkWidget *label66;
GtkWidget *default_label;
GtkWidget *label65;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
page = gtk_vbox_new (FALSE, 3);
gtk_widget_show (page);
gtk_container_add (GTK_CONTAINER (window), page);
gtk_container_set_border_width (GTK_CONTAINER (page), 3);
hbox9 = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (page), hbox9, FALSE, FALSE, 0);
label64 = gtk_label_new (_("Search: "));
gtk_widget_show (label64);
gtk_box_pack_start (GTK_BOX (hbox9), label64, FALSE, FALSE, 0);
seach = gtk_entry_new ();
gtk_widget_show (seach);
gtk_box_pack_start (GTK_BOX (hbox9), seach, TRUE, TRUE, 0);
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow);
gtk_box_pack_start (GTK_BOX (page), scrolledwindow, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN);
treeview = gtk_tree_view_new ();
gtk_widget_show (treeview);
gtk_container_add (GTK_CONTAINER (scrolledwindow), treeview);
GTK_WIDGET_SET_FLAGS (treeview, GTK_CAN_DEFAULT);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
shortcut_frame = gtk_frame_new (NULL);
gtk_widget_show (shortcut_frame);
gtk_box_pack_start (GTK_BOX (page), shortcut_frame, FALSE, FALSE, 0);
alignment29 = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (alignment29);
gtk_container_add (GTK_CONTAINER (shortcut_frame), alignment29);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment29), 3, 3, 3, 3);
vbox11 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox11);
gtk_container_add (GTK_CONTAINER (alignment29), vbox11);
hbox10 = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox10);
gtk_box_pack_start (GTK_BOX (vbox11), hbox10, TRUE, TRUE, 0);
shortcut_none = gtk_radio_button_new_with_mnemonic (NULL, _("None "));
gtk_widget_show (shortcut_none);
gtk_box_pack_start (GTK_BOX (hbox10), shortcut_none, FALSE, FALSE, 0);
gtk_button_set_focus_on_click (GTK_BUTTON (shortcut_none), FALSE);
gtk_radio_button_set_group (GTK_RADIO_BUTTON (shortcut_none), shortcut_none_group);
shortcut_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (shortcut_none));
shortcut_default = gtk_radio_button_new_with_mnemonic (NULL, _("Default "));
gtk_widget_show (shortcut_default);
gtk_box_pack_start (GTK_BOX (hbox10), shortcut_default, FALSE, FALSE, 0);
gtk_button_set_focus_on_click (GTK_BUTTON (shortcut_default), FALSE);
gtk_radio_button_set_group (GTK_RADIO_BUTTON (shortcut_default), shortcut_none_group);
shortcut_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (shortcut_default));
shortcut_custom = gtk_radio_button_new_with_mnemonic (NULL, _("Custom "));
gtk_widget_show (shortcut_custom);
gtk_box_pack_start (GTK_BOX (hbox10), shortcut_custom, FALSE, FALSE, 0);
gtk_button_set_focus_on_click (GTK_BUTTON (shortcut_custom), FALSE);
gtk_radio_button_set_group (GTK_RADIO_BUTTON (shortcut_custom), shortcut_none_group);
shortcut_none_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (shortcut_custom));
shortcut = gtk_button_new_with_mnemonic ("");
gtk_widget_show (shortcut);
gtk_box_pack_start (GTK_BOX (hbox10), shortcut, TRUE, TRUE, 0);
gtk_button_set_focus_on_click (GTK_BUTTON (shortcut), FALSE);
hbox11 = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox11);
gtk_box_pack_start (GTK_BOX (vbox11), hbox11, TRUE, TRUE, 0);
label66 = gtk_label_new (_(" Default key: "));
gtk_widget_show (label66);
gtk_box_pack_start (GTK_BOX (hbox11), label66, FALSE, FALSE, 0);
default_label = gtk_label_new ("");
gtk_widget_show (default_label);
gtk_box_pack_start (GTK_BOX (hbox11), default_label, FALSE, FALSE, 0);
label65 = gtk_label_new (_("Shortcut for selected action"));
gtk_widget_show (label65);
gtk_frame_set_label_widget (GTK_FRAME (shortcut_frame), label65);
/* Store pointers to all widgets, for use by lookup_widget(). */
GLADE_HOOKUP_OBJECT_NO_REF (window, window, "window");
GLADE_HOOKUP_OBJECT (window, page, "page");
GLADE_HOOKUP_OBJECT (window, hbox9, "hbox9");
GLADE_HOOKUP_OBJECT (window, label64, "label64");
GLADE_HOOKUP_OBJECT (window, seach, "seach");
GLADE_HOOKUP_OBJECT (window, scrolledwindow, "scrolledwindow");
GLADE_HOOKUP_OBJECT (window, treeview, "treeview");
GLADE_HOOKUP_OBJECT (window, shortcut_frame, "shortcut_frame");
GLADE_HOOKUP_OBJECT (window, alignment29, "alignment29");
GLADE_HOOKUP_OBJECT (window, vbox11, "vbox11");
GLADE_HOOKUP_OBJECT (window, hbox10, "hbox10");
GLADE_HOOKUP_OBJECT (window, shortcut_none, "shortcut_none");
GLADE_HOOKUP_OBJECT (window, shortcut_default, "shortcut_default");
GLADE_HOOKUP_OBJECT (window, shortcut_custom, "shortcut_custom");
GLADE_HOOKUP_OBJECT (window, shortcut, "shortcut");
GLADE_HOOKUP_OBJECT (window, hbox11, "hbox11");
GLADE_HOOKUP_OBJECT (window, label66, "label66");
GLADE_HOOKUP_OBJECT (window, default_label, "default_label");
GLADE_HOOKUP_OBJECT (window, label65, "label65");
gtk_widget_grab_focus (treeview);
return window;
}
GtkWidget*
create_dialog (void)
{
GtkWidget *dialog;
GtkWidget *dialog_vbox1;
GtkWidget *frame1;
GtkWidget *alignment30;
GtkWidget *page;
GtkWidget *dialog_action_area1;
GtkWidget *reset;
GtkWidget *alignment31;
GtkWidget *hbox12;
GtkWidget *image1;
GtkWidget *label67;
GtkWidget *cancel;
GtkWidget *ok;
dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW (dialog), _("Configure Shortcuts"));
gtk_window_set_default_size (GTK_WINDOW (dialog), -1, 350);
gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
dialog_vbox1 = GTK_DIALOG (dialog)->vbox;
gtk_widget_show (dialog_vbox1);
frame1 = gtk_frame_new (NULL);
gtk_widget_show (frame1);
gtk_box_pack_start (GTK_BOX (dialog_vbox1), frame1, TRUE, TRUE, 0);
alignment30 = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_widget_show (alignment30);
gtk_container_add (GTK_CONTAINER (frame1), alignment30);
gtk_alignment_set_padding (GTK_ALIGNMENT (alignment30), 3, 3, 3, 3);
page = gtk_vbox_new (FALSE, 0);
gtk_widget_show (page);
gtk_container_add (GTK_CONTAINER (alignment30), page);
dialog_action_area1 = GTK_DIALOG (dialog)->action_area;
gtk_widget_show (dialog_action_area1);
gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END);
reset = gtk_button_new ();
gtk_widget_show (reset);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), reset, GTK_RESPONSE_REJECT);
GTK_WIDGET_SET_FLAGS (reset, GTK_CAN_DEFAULT);
alignment31 = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_widget_show (alignment31);
gtk_container_add (GTK_CONTAINER (reset), alignment31);
hbox12 = gtk_hbox_new (FALSE, 2);
gtk_widget_show (hbox12);
gtk_container_add (GTK_CONTAINER (alignment31), hbox12);
image1 = gtk_image_new_from_stock ("gtk-refresh", GTK_ICON_SIZE_BUTTON);
gtk_widget_show (image1);
gtk_box_pack_start (GTK_BOX (hbox12), image1, FALSE, FALSE, 0);
label67 = gtk_label_new_with_mnemonic (_("Set _Defaults"));
gtk_widget_show (label67);
gtk_box_pack_start (GTK_BOX (hbox12), label67, FALSE, FALSE, 0);
cancel = gtk_button_new_from_stock ("gtk-cancel");
gtk_widget_show (cancel);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancel, GTK_RESPONSE_CANCEL);
GTK_WIDGET_SET_FLAGS (cancel, GTK_CAN_DEFAULT);
gtk_button_set_focus_on_click (GTK_BUTTON (cancel), FALSE);
ok = gtk_button_new_from_stock ("gtk-ok");
gtk_widget_show (ok);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), ok, GTK_RESPONSE_OK);
GTK_WIDGET_SET_FLAGS (ok, GTK_CAN_DEFAULT);
gtk_button_set_focus_on_click (GTK_BUTTON (ok), FALSE);
/* Store pointers to all widgets, for use by lookup_widget(). */
GLADE_HOOKUP_OBJECT_NO_REF (dialog, dialog, "dialog");
GLADE_HOOKUP_OBJECT_NO_REF (dialog, dialog_vbox1, "dialog_vbox1");
GLADE_HOOKUP_OBJECT (dialog, frame1, "frame1");
GLADE_HOOKUP_OBJECT (dialog, alignment30, "alignment30");
GLADE_HOOKUP_OBJECT (dialog, page, "page");
GLADE_HOOKUP_OBJECT_NO_REF (dialog, dialog_action_area1, "dialog_action_area1");
GLADE_HOOKUP_OBJECT (dialog, reset, "reset");
GLADE_HOOKUP_OBJECT (dialog, alignment31, "alignment31");
GLADE_HOOKUP_OBJECT (dialog, hbox12, "hbox12");
GLADE_HOOKUP_OBJECT (dialog, image1, "image1");
GLADE_HOOKUP_OBJECT (dialog, label67, "label67");
GLADE_HOOKUP_OBJECT (dialog, cancel, "cancel");
GLADE_HOOKUP_OBJECT (dialog, ok, "ok");
gtk_widget_grab_default (ok);
return dialog;
}

View File

@ -447,7 +447,7 @@
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
<child>
<widget class="GtkAlignment" id="alignment30">
<widget class="GtkAlignment" id="page_holder">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
@ -459,15 +459,7 @@
<property name="right_padding">3</property>
<child>
<widget class="GtkVBox" id="page">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<placeholder/>
</child>
</widget>
<placeholder/>
</child>
</widget>
</child>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-project SYSTEM "http://glade.gnome.org/glade-project-2.0.dtd">
<glade-project>
<name>shortcutsprefs</name>
<program_name>shortcutsprefs</program_name>
<source_directory></source_directory>
<pixmaps_directory></pixmaps_directory>
<gnome_support>FALSE</gnome_support>
<output_main_file>FALSE</output_main_file>
<output_support_files>FALSE</output_support_files>
<output_build_files>FALSE</output_build_files>
<backup_source_files>FALSE</backup_source_files>
<main_source_file>shortcutsprefs.c</main_source_file>
<main_header_file>shortcutsprefs.h</main_header_file>
</glade-project>

View File

@ -1,29 +0,0 @@
s/#include <sys\/types.h>//
s/#include <sys\/stat.h>//
s/#include <unistd.h>//
s/#include <string.h>/#include "mooutils\/moocompat.h"/
s/#include <stdio.h>/#include "mooutils\/mooprefsdialog.h"/
s/#include "callbacks.h"/#include "mooutils\/mooaccelbutton.h"/
s/#include "shortcutsprefs.h"//
s/create_window (void)/_moo_create_shortcutsprefs_page (GtkWidget *page);\nGtkWidget *_moo_create_shortcutsprefs_page (GtkWidget *page)/
s/create_dialog (void)/_moo_create_shortcutsprefs_dialog (GtkWidget *page);\nGtkWidget *_moo_create_shortcutsprefs_dialog (GtkWidget *page)/
s/GtkWidget \*window;//
s/GtkWidget \*page;//
s/window = gtk_window_new (GTK_WINDOW_TOPLEVEL);//
s/page = gtk_vbox_new (FALSE, .*//
s/gtk_widget_show (page);//
s/shortcut = gtk_button_new_with_mnemonic ("");/shortcut = moo_accel_button_new (NULL);/
s/gtk_container_add (GTK_CONTAINER (window), page);//
s/[ \t]*GLADE_HOOKUP_OBJECT (window, [a-z_]*[0-9][0-9]*,.*//
s/[ \t]*GLADE_HOOKUP_OBJECT (dialog, [a-z_]*[0-9][0-9]*,.*//
s/[ \t]*GLADE_HOOKUP_OBJECT_NO_REF (window, [a-z_]*[0-9][0-9]*,.*//
s/[ \t]*GLADE_HOOKUP_OBJECT_NO_REF (dialog, [a-z_]*[0-9][0-9]*,.*//
s/GLADE_HOOKUP_OBJECT_NO_REF (window, window, \"window\");//
s/GLADE_HOOKUP_OBJECT (window, page, \"page\");/GLADE_HOOKUP_OBJECT_NO_REF (page, page, \"page\");/
s/GLADE_HOOKUP_OBJECT (window, /GLADE_HOOKUP_OBJECT (page, /
s/GLADE_HOOKUP_OBJECT_NO_REF (window, tooltips, \"tooltips\");/GLADE_HOOKUP_OBJECT_NO_REF (page, tooltips, \"tooltips\");/
s/return window;/return GTK_WIDGET (page);/
s/g_signal_connect ((gpointer) \([A-Za-z0-9_]*\), "moo_prefs_key", G_CALLBACK (\([A-Za-z0-9_]*\)), NULL);/moo_prefs_dialog_page_bind_setting (page, \1, moo_term_setting (\2));/
s/g_signal_connect ((gpointer) \([A-Za-z0-9_]*\), "moo_sensitive", G_CALLBACK (\([A-Za-z0-9_]*\)), NULL);/moo_bind_sensitive (GTK_TOGGLE_BUTTON (\2), \&\1, 1, FALSE);/
s/g_signal_connect_swapped ((gpointer) \([A-Za-z0-9_]*\), "moo_sensitive", G_CALLBACK (\([A-Za-z0-9_]*\)), GTK_OBJECT (invert));/moo_bind_sensitive (GTK_TOGGLE_BUTTON (\2), \&\1, 1, TRUE);/
s/g_signal_connect_swapped ((gpointer) \([A-Za-z0-9_]*\), "moo_radio", G_CALLBACK (\([A-Za-z0-9_]*\)), GTK_OBJECT (\([A-Za-z0-9_]*\)));/moo_prefs_dialog_page_bind_radio (page, moo_term_setting (\2), GTK_TOGGLE_BUTTON (\1), \3);/

View File

@ -12,16 +12,15 @@
*/
#include "mooui/mooshortcutsprefs.h"
#include "mooui/mooshortcutsprefs-glade.h"
#include "mooui/mooaccel.h"
#include "mooutils/mooaccelbutton.h"
#include "mooutils/moostock.h"
#include "mooutils/mooprefs.h"
#include "mooutils/mooglade.h"
#include <gtk/gtk.h>
#include <string.h>
GtkWidget *_moo_create_shortcutsprefs_page (GtkWidget *page);
GtkWidget *_moo_create_shortcutsprefs_dialog (GtkWidget *page);
typedef enum {
NONE,
@ -149,13 +148,20 @@ inline static void unblock_radio (Stuff *stuff)
GtkWidget *moo_shortcuts_prefs_page_new (MooActionGroup *actions)
{
GtkWidget *page;
GtkWidget *page, *page_content;
Stuff *stuff;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
MooGladeXML *xml;
xml = moo_glade_xml_new_empty ();
moo_glade_xml_map_type (xml, GTK_TYPE_BUTTON, MOO_TYPE_ACCEL_BUTTON);
moo_glade_xml_parse_memory (xml, MOO_SHORTCUTS_PREFS_GLADE_UI, -1, "page");
page = moo_prefs_dialog_page_new ("Shortcuts", MOO_STOCK_KEYBOARD);
_moo_create_shortcutsprefs_page (page);
page_content = moo_glade_xml_get_widget (xml, "page");
gtk_box_pack_start (GTK_BOX (page), page_content, TRUE, TRUE, 0);
stuff = stuff_new ();
if (actions)
@ -171,7 +177,7 @@ GtkWidget *moo_shortcuts_prefs_page_new (MooActionGroup *actions)
G_CALLBACK (init),
stuff);
stuff->treeview = GTK_TREE_VIEW (g_object_get_data (G_OBJECT (page), "treeview"));
stuff->treeview = moo_glade_xml_get_widget (xml, "treeview");
gtk_tree_view_set_headers_clickable (stuff->treeview, TRUE);
gtk_tree_view_set_search_column (stuff->treeview, 0);
@ -179,12 +185,14 @@ GtkWidget *moo_shortcuts_prefs_page_new (MooActionGroup *actions)
G_CALLBACK (row_activated),
stuff);
stuff->shortcut_frame = GTK_WIDGET (g_object_get_data (G_OBJECT (page), "shortcut_frame"));
stuff->shortcut_default = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (page), "shortcut_default"));
stuff->shortcut_none = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (page), "shortcut_none"));
stuff->shortcut_custom = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (page), "shortcut_custom"));
stuff->shortcut = MOO_ACCEL_BUTTON (g_object_get_data (G_OBJECT (page), "shortcut"));
stuff->default_label = GTK_LABEL (g_object_get_data (G_OBJECT (page), "default_label"));
stuff->shortcut_frame = moo_glade_xml_get_widget (xml, "shortcut_frame");
stuff->shortcut_default = moo_glade_xml_get_widget (xml, "shortcut_default");
stuff->shortcut_none = moo_glade_xml_get_widget (xml, "shortcut_none");
stuff->shortcut_custom = moo_glade_xml_get_widget (xml, "shortcut_custom");
stuff->shortcut = moo_glade_xml_get_widget (xml, "shortcut");
stuff->default_label = moo_glade_xml_get_widget (xml, "default_label");
moo_glade_xml_unref (xml);
stuff->store = gtk_tree_store_new (N_COLUMNS,
G_TYPE_STRING,
@ -628,11 +636,22 @@ static void dialog_response (GObject *page,
GtkWidget *moo_shortcuts_prefs_dialog_new (MooActionGroup *group)
{
GtkWidget *page, *dialog;
GtkWidget *page, *dialog, *page_holder;
MooGladeXML *xml;
xml = moo_glade_xml_new_from_buf (MOO_SHORTCUTS_PREFS_GLADE_UI,
-1, "dialog");
g_return_val_if_fail (xml != NULL, NULL);
dialog = moo_glade_xml_get_widget (xml, "dialog");
page = moo_shortcuts_prefs_page_new (group);
gtk_widget_show (page);
dialog = _moo_create_shortcutsprefs_dialog (page);
page_holder = moo_glade_xml_get_widget (xml, "page_holder");
gtk_container_add (GTK_CONTAINER (page_holder), page);
moo_glade_xml_unref (xml);
#if GTK_MINOR_VERSION >= 6
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
@ -640,9 +659,11 @@ GtkWidget *moo_shortcuts_prefs_dialog_new (MooActionGroup *group)
GTK_RESPONSE_REJECT,
-1);
#endif /* GTK_MINOR_VERSION >= 6 */
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (dialog_response), page);
g_signal_emit_by_name (page, "init", NULL);
return dialog;
}
@ -652,15 +673,21 @@ void moo_shortcuts_prefs_dialog_run (MooActionGroup *group,
{
GtkWidget *dialog = moo_shortcuts_prefs_dialog_new (group);
GtkWindow *parent_window = GTK_WINDOW (gtk_widget_get_toplevel (parent));
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
while (TRUE) {
while (TRUE)
{
int response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response != GTK_RESPONSE_REJECT)
break;
}
gtk_widget_destroy (dialog);
#ifdef __WIN32__ /* TODO */
gtk_window_present (parent_window);
#endif /* __WIN32__ */
return;
}

View File

@ -259,7 +259,7 @@ static void moo_accel_button_clicked (MooAccelButton *button)
Stuff s = {0, 0, NULL};
int response;
xml = moo_glade_xml_parse_memory (MOO_ACCEL_BUTTON_GLADE_UI, -1, "dialog");
xml = moo_glade_xml_new_from_buf (MOO_ACCEL_BUTTON_GLADE_UI, -1, "dialog");
g_return_if_fail (xml != NULL);
dialog = moo_glade_xml_get_widget (xml, "dialog");

View File

@ -111,14 +111,27 @@ struct _MooGladeXML {
MooMarkupDoc *doc;
MooMarkupNode *root;
GHashTable *widgets;
GHashTable *type_to_type;
GHashTable *id_to_type;
GHashTable *id_to_func;
};
typedef struct {
MooGladeCreateFunc func;
gpointer data;
} FuncDataPair;
#define NODE_IS_WIDGET(node) (!strcmp (node->name, "widget"))
#define NODE_IS_PROPERTY(node) (!strcmp (node->name, "property"))
#define NODE_IS_CHILD(node) (!strcmp (node->name, "child"))
#define NODE_IS_PACKING(node) (!strcmp (node->name, "packing"))
static FuncDataPair *func_data_pair_new (MooGladeCreateFunc func,
gpointer data);
static void func_data_pair_free (FuncDataPair *pair);
static Widget *widget_new (Child *parent,
MooMarkupNode *node);
static void widget_free (Widget *widget);
@ -140,17 +153,16 @@ static gboolean parse_property (GParamSpec *param_spec,
const char *value,
GParameter *param);
static MooGladeXML *moo_glade_xml_parse_markup (MooMarkupDoc *doc,
static gboolean moo_glade_xml_parse_markup (MooGladeXML *xml,
MooMarkupDoc *doc,
const char *root);
static MooGladeXML *moo_glade_xml_new (MooMarkupDoc *doc,
MooMarkupNode *root);
static void moo_glade_xml_free (MooGladeXML *xml);
static void moo_glade_xml_add_widget (MooGladeXML *xml,
const char *id,
GtkWidget *widget);
static gboolean create_widgets (MooGladeXML *xml,
static gboolean moo_glade_xml_build (MooGladeXML *xml,
Widget *widget);
static gboolean create_child (MooGladeXML *xml,
GtkWidget *parent,
Child *child,
@ -175,21 +187,20 @@ static gboolean pack_children (MooGladeXML *xml,
Widget *widget_node,
GtkWidget *widget,
GtkTooltips *tooltips);
static GtkWidget *instantiate_widget (GType type,
WidgetProps *props);
static GtkWidget *moo_glade_xml_create_widget(MooGladeXML *xml,
Widget *node);
static void dump_widget (Widget *widget_node);
static gboolean
create_widgets (MooGladeXML *xml,
Widget *widget_node)
moo_glade_xml_build (MooGladeXML *xml,
Widget *widget_node)
{
GtkWidget *widget;
GtkTooltips *tooltips;
widget = instantiate_widget (widget_node->type,
widget_node->props);
widget = moo_glade_xml_create_widget (xml, widget_node);
moo_glade_xml_add_widget (xml, widget_node->id, widget);
widget_node->widget = widget;
@ -284,8 +295,7 @@ create_widget (MooGladeXML *xml,
{
GtkWidget *widget;
widget = instantiate_widget (widget_node->type,
widget_node->props);
widget = moo_glade_xml_create_widget (xml, widget_node);
moo_glade_xml_add_widget (xml, widget_node->id, widget);
@ -370,64 +380,90 @@ set_special_props (MooGladeXML *xml,
static GtkWidget*
instantiate_widget (GType type,
WidgetProps *props)
moo_glade_xml_create_widget (MooGladeXML *xml,
Widget *node)
{
WidgetProps *props;
GType type;
GtkWidget *widget = NULL;
FuncDataPair *pair;
g_return_val_if_fail (type != 0, NULL);
g_return_val_if_fail (props != NULL, NULL);
g_return_val_if_fail (node != NULL, NULL);
if (props->mask & PROP_LABEL)
pair = g_hash_table_lookup (xml->id_to_func, node->id);
if (pair)
{
if (!props->label)
widget = pair->func (xml, node->id, pair->data);
}
if (!widget)
type = GPOINTER_TO_SIZE (g_hash_table_lookup (xml->id_to_type, node->id));
if (!widget && !type)
type = GPOINTER_TO_SIZE (g_hash_table_lookup (xml->type_to_type,
GSIZE_TO_POINTER (node->type)));
if (!widget && !type)
type = node->type;
props = node->props;
g_return_val_if_fail (widget != NULL || type != 0, NULL);
if (!widget)
{
if (props->mask & PROP_LABEL)
{
g_warning ("%s: oops", G_STRLOC);
}
if (type == GTK_TYPE_MENU_ITEM)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_menu_item_new_with_mnemonic (props->label);
if (!props->label)
{
g_warning ("%s: oops", G_STRLOC);
}
if (type == GTK_TYPE_MENU_ITEM)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_menu_item_new_with_mnemonic (props->label);
else
widget = gtk_menu_item_new_with_label (props->label);
}
else if (type == GTK_TYPE_IMAGE_MENU_ITEM)
{
if (props->mask & PROP_USE_STOCK)
widget = gtk_image_menu_item_new_from_stock (props->label, NULL);
else if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_image_menu_item_new_with_mnemonic (props->label);
else
widget = gtk_image_menu_item_new_with_label (props->label);
}
else if (type == GTK_TYPE_RADIO_MENU_ITEM)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_radio_menu_item_new_with_mnemonic (NULL, props->label);
else
widget = gtk_radio_menu_item_new_with_label (NULL, props->label);
}
else if (type == GTK_TYPE_CHECK_BUTTON)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_check_button_new_with_mnemonic (props->label);
else
widget = gtk_check_button_new_with_label (props->label);
}
else if (type == GTK_TYPE_RADIO_BUTTON)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_radio_button_new_with_mnemonic (NULL, props->label);
else
widget = gtk_radio_button_new_with_label (NULL, props->label);
}
else if (type == GTK_TYPE_LIST_ITEM)
{
widget = gtk_list_item_new_with_label (props->label);
}
else
widget = gtk_menu_item_new_with_label (props->label);
}
else if (type == GTK_TYPE_IMAGE_MENU_ITEM)
{
if (props->mask & PROP_USE_STOCK)
widget = gtk_image_menu_item_new_from_stock (props->label, NULL);
else if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_image_menu_item_new_with_mnemonic (props->label);
else
widget = gtk_image_menu_item_new_with_label (props->label);
}
else if (type == GTK_TYPE_RADIO_MENU_ITEM)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_radio_menu_item_new_with_mnemonic (NULL, props->label);
else
widget = gtk_radio_menu_item_new_with_label (NULL, props->label);
}
else if (type == GTK_TYPE_CHECK_BUTTON)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_check_button_new_with_mnemonic (props->label);
else
widget = gtk_check_button_new_with_label (props->label);
}
else if (type == GTK_TYPE_RADIO_BUTTON)
{
if (props->mask & PROP_USE_UNDERLINE)
widget = gtk_radio_button_new_with_mnemonic (NULL, props->label);
else
widget = gtk_radio_button_new_with_label (NULL, props->label);
}
else if (type == GTK_TYPE_LIST_ITEM)
{
widget = gtk_list_item_new_with_label (props->label);
}
else
{
g_warning ("%s: oops", G_STRLOC);
{
g_warning ("%s: oops", G_STRLOC);
}
}
}
@ -1442,14 +1478,36 @@ moo_glade_xml_unref (MooGladeXML *xml)
MooGladeXML*
moo_glade_xml_parse_file (const char *file,
const char *root)
moo_glade_xml_new_empty (void)
{
MooGladeXML *xml;
xml = g_new0 (MooGladeXML, 1);
xml->widgets = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
xml->type_to_type = g_hash_table_new (g_direct_hash, g_direct_equal);
xml->id_to_type = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
xml->id_to_func = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free,
(GDestroyNotify) func_data_pair_free);
return xml;
}
gboolean
moo_glade_xml_parse_file (MooGladeXML *xml,
const char *file,
const char *root)
{
MooMarkupDoc *doc;
GError *error = NULL;
gboolean result;
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (xml != NULL, FALSE);
g_return_val_if_fail (file != NULL, FALSE);
doc = moo_markup_parse_file (file, &error);
@ -1463,25 +1521,28 @@ moo_glade_xml_parse_file (const char *file,
g_error_free (error);
}
return NULL;
return FALSE;
}
xml = moo_glade_xml_parse_markup (doc, root);
result = moo_glade_xml_parse_markup (xml, doc, root);
moo_markup_doc_unref (doc);
return xml;
return result;
}
MooGladeXML*
moo_glade_xml_parse_memory (const char *buffer,
gboolean
moo_glade_xml_parse_memory (MooGladeXML *xml,
const char *buffer,
int size,
const char *root)
{
MooGladeXML *xml;
MooMarkupDoc *doc;
GError *error = NULL;
gboolean result;
g_return_val_if_fail (buffer != NULL, NULL);
g_return_val_if_fail (xml != NULL, FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
doc = moo_markup_parse_memory (buffer, size, &error);
@ -1495,11 +1556,53 @@ moo_glade_xml_parse_memory (const char *buffer,
g_error_free (error);
}
return FALSE;
}
result = moo_glade_xml_parse_markup (xml, doc, root);
moo_markup_doc_unref (doc);
return result;
}
MooGladeXML*
moo_glade_xml_new (const char *file,
const char *root)
{
MooGladeXML *xml;
g_return_val_if_fail (file != NULL, NULL);
xml = moo_glade_xml_new_empty ();
if (!moo_glade_xml_parse_file (xml, file, root))
{
moo_glade_xml_unref (xml);
return NULL;
}
return xml;
}
MooGladeXML*
moo_glade_xml_new_from_buf (const char *buffer,
int size,
const char *root)
{
MooGladeXML *xml;
g_return_val_if_fail (buffer != NULL, NULL);
xml = moo_glade_xml_new_empty ();
if (!moo_glade_xml_parse_memory (xml, buffer, size, root))
{
moo_glade_xml_unref (xml);
return NULL;
}
xml = moo_glade_xml_parse_markup (doc, root);
moo_markup_doc_unref (doc);
return xml;
}
@ -1540,19 +1643,20 @@ find_widget (MooMarkupNode *node,
}
static MooGladeXML*
moo_glade_xml_parse_markup (MooMarkupDoc *doc,
const char *root_id)
static gboolean
moo_glade_xml_parse_markup (MooGladeXML *xml,
MooMarkupDoc *doc,
const char *root_id)
{
MooGladeXML *xml;
MooMarkupNode *glade_elm;
MooMarkupNode *root = NULL;
Widget *widget;
g_return_val_if_fail (doc != NULL, NULL);
g_return_val_if_fail (doc != NULL, FALSE);
g_return_val_if_fail (xml->doc == NULL, FALSE);
glade_elm = moo_markup_get_root_element (doc, "glade-interface");
g_return_val_if_fail (glade_elm != NULL, NULL);
g_return_val_if_fail (glade_elm != NULL, FALSE);
FOREACH_ELM_START(glade_elm, elm)
{
@ -1590,54 +1694,34 @@ moo_glade_xml_parse_markup (MooMarkupDoc *doc,
else
g_warning ("%s: could not find root element", G_STRLOC);
return NULL;
return FALSE;
}
xml = moo_glade_xml_new (doc, root);
g_return_val_if_fail (xml != NULL, NULL);
xml->doc = moo_markup_doc_ref (doc);
xml->root = root;
widget = widget_new (NULL, xml->root);
if (!widget)
{
moo_glade_xml_free (xml);
return NULL;
return FALSE;
}
dump_widget (widget);
if (!create_widgets (xml, widget))
if (!moo_glade_xml_build (xml, widget))
{
moo_glade_xml_free (xml);
widget_free (widget);
return NULL;
return FALSE;
}
#if 0
gtk_widget_show_all (widget->widget);
#endif
return xml;
}
static MooGladeXML*
moo_glade_xml_new (MooMarkupDoc *doc,
MooMarkupNode *root)
{
MooGladeXML *xml;
g_return_val_if_fail (MOO_MARKUP_IS_DOC (doc), NULL);
g_return_val_if_fail (MOO_MARKUP_IS_ELEMENT (root), NULL);
g_return_val_if_fail (root->doc == doc, NULL);
xml = g_new0 (MooGladeXML, 1);
xml->doc = moo_markup_doc_ref (doc);
xml->root = root;
xml->widgets = g_hash_table_new (g_str_hash, g_str_equal);
return xml;
return TRUE;
}
@ -1697,13 +1781,16 @@ moo_glade_xml_free (MooGladeXML *xml)
g_hash_table_foreach (xml->widgets,
(GHFunc) unref_widget, NULL);
g_hash_table_destroy (xml->widgets);
g_hash_table_destroy (xml->type_to_type);
g_hash_table_destroy (xml->id_to_type);
g_hash_table_destroy (xml->id_to_func);
moo_markup_doc_unref (xml->doc);
g_free (xml);
}
}
GtkWidget*
gpointer
moo_glade_xml_get_widget (MooGladeXML *xml,
const char *id)
{
@ -1713,6 +1800,80 @@ moo_glade_xml_get_widget (MooGladeXML *xml,
}
void
moo_glade_xml_map_type (MooGladeXML *xml,
GType type,
GType use_type)
{
g_return_if_fail (xml != NULL);
if (use_type)
g_hash_table_insert (xml->type_to_type,
GSIZE_TO_POINTER (type),
GSIZE_TO_POINTER (use_type));
else
g_hash_table_remove (xml->type_to_type,
GSIZE_TO_POINTER (type));
}
void
moo_glade_xml_map_id (MooGladeXML *xml,
const char *id,
GType use_type)
{
g_return_if_fail (xml != NULL);
g_return_if_fail (id != NULL);
if (use_type)
g_hash_table_insert (xml->id_to_type,
g_strdup (id),
GSIZE_TO_POINTER (use_type));
else
g_hash_table_remove (xml->id_to_type, id);
}
void moo_glade_xml_map_custom (MooGladeXML *xml,
const char *id,
MooGladeCreateFunc func,
gpointer data)
{
g_return_if_fail (xml != NULL);
g_return_if_fail (id != NULL);
if (func)
g_hash_table_insert (xml->id_to_func,
g_strdup (id),
func_data_pair_new (func, data));
else
g_hash_table_remove (xml->id_to_func, id);
}
static FuncDataPair*
func_data_pair_new (MooGladeCreateFunc func,
gpointer data)
{
FuncDataPair *pair;
g_return_val_if_fail (func != NULL, NULL);
pair = g_new (FuncDataPair, 1);
pair->func = func;
pair->data = data;
return pair;
}
static void
func_data_pair_free (FuncDataPair *pair)
{
g_free (pair);
}
#define REGISTER_TYPE(class_name,type) \
if (!strcmp (name, class_name)) \
return type

View File

@ -22,18 +22,53 @@ typedef struct _MooGladeXML MooGladeXML;
#define MOO_TYPE_GLADE_XML (moo_glade_xml_get_type ())
GType moo_glade_xml_get_type (void);
typedef GtkWidget* (*MooGladeCreateFunc)(MooGladeXML *xml,
const char *id,
gpointer data);
typedef void (*MooGladeSignalFunc)(MooGladeXML *xml,
const char *widget_id,
GtkWidget *widget,
const char *signal,
const char *object,
gpointer data);
MooGladeXML *moo_glade_xml_parse_file (const char *file,
GType moo_glade_xml_get_type (void);
MooGladeXML *moo_glade_xml_new_empty (void);
void moo_glade_xml_map_type (MooGladeXML *xml,
GType type,
GType use_type);
void moo_glade_xml_map_id (MooGladeXML *xml,
const char *id,
GType use_type);
void moo_glade_xml_map_custom (MooGladeXML *xml,
const char *id,
MooGladeCreateFunc func,
gpointer data);
void moo_glade_xml_map_signal (MooGladeXML *xml,
MooGladeSignalFunc func,
gpointer data);
gboolean moo_glade_xml_parse_file (MooGladeXML *xml,
const char *file,
const char *root);
MooGladeXML *moo_glade_xml_parse_memory (const char *buffer,
gboolean moo_glade_xml_parse_memory (MooGladeXML *xml,
const char *buffer,
int size,
const char *root);
MooGladeXML *moo_glade_xml_new (const char *file,
const char *root);
MooGladeXML *moo_glade_xml_new_from_buf (const char *buffer,
int size,
const char *root);
MooGladeXML *moo_glade_xml_ref (MooGladeXML *xml);
void moo_glade_xml_unref (MooGladeXML *xml);
GtkWidget *moo_glade_xml_get_widget (MooGladeXML *xml,
gpointer moo_glade_xml_get_widget (MooGladeXML *xml,
const char *id);

View File

@ -36,7 +36,7 @@ int main (int argc, char *argv[])
file = argv[1];
}
my_xml = moo_glade_xml_parse_file (file, NULL);
my_xml = moo_glade_xml_new (file, NULL);
if (!my_xml)
{