From 913af05ba8c8ce5dce988c7ec4e897a149ad6491 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Fri, 18 Nov 2005 13:05:59 +0000 Subject: [PATCH] Try to find placeholder when node at given path doesn't exist --- moo/mooutils/moouixml.c | 36 +++++++++++++++++++++++++++--------- moo/mooutils/moouixml.h | 2 ++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/moo/mooutils/moouixml.c b/moo/mooutils/moouixml.c index f32a7b69..139c2ac5 100644 --- a/moo/mooutils/moouixml.c +++ b/moo/mooutils/moouixml.c @@ -84,7 +84,7 @@ G_STMT_START { \ } G_STMT_END -/* walking nodes stops when func returns FALSE */ +/* walking nodes stops when func returns TRUE */ typedef gboolean (*NodeForeachFunc) (Node *node, gpointer data); @@ -819,7 +819,7 @@ moo_ui_xml_add_item (MooUIXML *xml, merge = lookup_merge (xml, merge_id); g_return_val_if_fail (merge != NULL, NULL); - parent = moo_ui_xml_get_node (xml, parent_path); + parent = moo_ui_xml_find_node (xml, parent_path); g_return_val_if_fail (parent != NULL, NULL); switch (parent->type) @@ -1015,7 +1015,7 @@ moo_ui_xml_insert_markup_after (MooUIXML *xml, if (parent_path) { - parent = moo_ui_xml_get_node (xml, parent_path); + parent = moo_ui_xml_find_node (xml, parent_path); g_return_if_fail (parent != NULL); } else @@ -1047,7 +1047,7 @@ moo_ui_xml_insert_markup_before (MooUIXML *xml, if (parent_path) { - parent = moo_ui_xml_get_node (xml, parent_path); + parent = moo_ui_xml_find_node (xml, parent_path); g_return_if_fail (parent != NULL); } else @@ -1079,7 +1079,7 @@ moo_ui_xml_insert_markup (MooUIXML *xml, if (parent_path) { - parent = moo_ui_xml_get_node (xml, parent_path); + parent = moo_ui_xml_find_node (xml, parent_path); g_return_if_fail (parent != NULL); } else @@ -1221,6 +1221,24 @@ moo_ui_xml_get_node (MooUIXML *xml, } +MooUINode* +moo_ui_xml_find_node (MooUIXML *xml, + const char *path) +{ + MooUINode *node; + + g_return_val_if_fail (MOO_IS_UI_XML (xml), NULL); + g_return_val_if_fail (path != NULL, NULL); + + node = moo_ui_xml_get_node (xml, path); + + if (!node) + node = moo_ui_xml_find_placeholder (xml, path); + + return node; +} + + static gboolean find_placeholder_func (Node *node, gpointer user_data) @@ -1231,15 +1249,15 @@ find_placeholder_func (Node *node, } *data = user_data; if (node->type != PLACEHOLDER) - return TRUE; + return FALSE; if (!strcmp (node->name, data->name)) { data->found = node; - return FALSE; + return TRUE; } - return TRUE; + return FALSE; } MooUINode* @@ -1409,7 +1427,7 @@ static void xml_add_item_widget (MooUIXML *xml, GtkWidget *widget) { - g_signal_connect (widget, "notify::visibility", + g_signal_connect (widget, "notify::visible", G_CALLBACK (visibility_notify), xml); } diff --git a/moo/mooutils/moouixml.h b/moo/mooutils/moouixml.h index 0b4385dd..248904c7 100644 --- a/moo/mooutils/moouixml.h +++ b/moo/mooutils/moouixml.h @@ -123,6 +123,8 @@ void moo_ui_xml_add_ui_from_string (MooUIXML *xml, MooUINode *moo_ui_xml_get_node (MooUIXML *xml, const char *path); +MooUINode *moo_ui_xml_find_node (MooUIXML *xml, + const char *path_or_placeholder); MooUINode *moo_ui_xml_find_placeholder (MooUIXML *xml, const char *name); char *moo_ui_node_get_path (MooUINode *node);