From d0bf1b0de1c8827b320582e5a6804ba4a0d7345b Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 9 Mar 2012 15:01:42 +0000 Subject: [PATCH] Implementando associação de ids com os popups definidos no .xml --- src/gtk/uiparser/parser.c | 1 + src/gtk/uiparser/popup.c | 41 +++++++++++++++++++++++++++++++++++++---- src/gtk/uiparser/private.h | 1 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/gtk/uiparser/parser.c b/src/gtk/uiparser/parser.c index 514d684..6599100 100644 --- a/src/gtk/uiparser/parser.c +++ b/src/gtk/uiparser/parser.c @@ -255,6 +255,7 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con p.toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); p.center_widget = widget; p.group = groupname; + p.popup = popupname; p.strings = g_string_chunk_new(0); for(current = g_list_first(file);current;current = g_list_next(current)) diff --git a/src/gtk/uiparser/popup.c b/src/gtk/uiparser/popup.c index f588038..d5b2c2e 100644 --- a/src/gtk/uiparser/popup.c +++ b/src/gtk/uiparser/popup.c @@ -35,7 +35,10 @@ GObject * ui_create_popup(GtkAction *action,struct parser *info,const gchar **names, const gchar **values, GError **error) { - GtkWidget *widget = NULL; + GtkWidget * widget = NULL; + const gchar * id; + int pos = -1; + int f; if(info->element) { @@ -44,9 +47,39 @@ } if(action) - widget = gtk_action_create_menu(action); - else - widget = gtk_menu_new(); + { + *error = g_error_new(ERROR_DOMAIN,EINVAL,"%s", _( "Unexpected action attribute in ")); + return NULL; + } + + id = ui_get_attribute("group",names,values); + if(!id) + id = ui_get_attribute("type",names,values); + + if(!id) + { + *error = g_error_new(ERROR_DOMAIN,ENOENT,"%s", _( " needs a type or group attribute")); + return NULL; + } + + for(f=0;info->popup[f] && pos < 0;pos++) + { + if(!g_strcasecmp(info->popup[f],id)) + { + pos = f; + break; + } + } + + if(pos < 0) + { + *error = g_error_new(ERROR_DOMAIN,EINVAL,_( "Unknown popup type \"%s\""),id); + return NULL; + } + + widget = gtk_menu_new(); + + g_object_set_data(G_OBJECT(widget),"popup_id",(gpointer) pos); return G_OBJECT(ui_insert_element(info, action, UI_ELEMENT_POPUP, names, values, G_OBJECT(widget), error)); } diff --git a/src/gtk/uiparser/private.h b/src/gtk/uiparser/private.h index b1dac5f..36035a6 100644 --- a/src/gtk/uiparser/private.h +++ b/src/gtk/uiparser/private.h @@ -58,6 +58,7 @@ GtkWidget * center_widget; GStringChunk * strings; const gchar ** group; /**< Action group list */ + const gchar ** popup; /**< Popup names */ GHashTable * actions; /**< List of actions */ GHashTable * element_list[UI_ELEMENT_COUNT]; }; -- libgit2 0.21.2