Commit d0bf1b0de1c8827b320582e5a6804ba4a0d7345b
1 parent
52e0d15a
Exists in
master
and in
5 other branches
Implementando associação de ids com os popups definidos no .xml
Showing
3 changed files
with
39 additions
and
4 deletions
Show diff stats
src/gtk/uiparser/parser.c
| @@ -255,6 +255,7 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con | @@ -255,6 +255,7 @@ GtkWidget * ui_parse_xml_folder(const gchar *path, const gchar ** groupname, con | ||
| 255 | p.toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 255 | p.toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 256 | p.center_widget = widget; | 256 | p.center_widget = widget; |
| 257 | p.group = groupname; | 257 | p.group = groupname; |
| 258 | + p.popup = popupname; | ||
| 258 | p.strings = g_string_chunk_new(0); | 259 | p.strings = g_string_chunk_new(0); |
| 259 | 260 | ||
| 260 | for(current = g_list_first(file);current;current = g_list_next(current)) | 261 | for(current = g_list_first(file);current;current = g_list_next(current)) |
src/gtk/uiparser/popup.c
| @@ -35,7 +35,10 @@ | @@ -35,7 +35,10 @@ | ||
| 35 | 35 | ||
| 36 | GObject * ui_create_popup(GtkAction *action,struct parser *info,const gchar **names, const gchar **values, GError **error) | 36 | GObject * ui_create_popup(GtkAction *action,struct parser *info,const gchar **names, const gchar **values, GError **error) |
| 37 | { | 37 | { |
| 38 | - GtkWidget *widget = NULL; | 38 | + GtkWidget * widget = NULL; |
| 39 | + const gchar * id; | ||
| 40 | + int pos = -1; | ||
| 41 | + int f; | ||
| 39 | 42 | ||
| 40 | if(info->element) | 43 | if(info->element) |
| 41 | { | 44 | { |
| @@ -44,9 +47,39 @@ | @@ -44,9 +47,39 @@ | ||
| 44 | } | 47 | } |
| 45 | 48 | ||
| 46 | if(action) | 49 | if(action) |
| 47 | - widget = gtk_action_create_menu(action); | ||
| 48 | - else | ||
| 49 | - widget = gtk_menu_new(); | 50 | + { |
| 51 | + *error = g_error_new(ERROR_DOMAIN,EINVAL,"%s", _( "Unexpected action attribute in <popup>")); | ||
| 52 | + return NULL; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + id = ui_get_attribute("group",names,values); | ||
| 56 | + if(!id) | ||
| 57 | + id = ui_get_attribute("type",names,values); | ||
| 58 | + | ||
| 59 | + if(!id) | ||
| 60 | + { | ||
| 61 | + *error = g_error_new(ERROR_DOMAIN,ENOENT,"%s", _( "<popup> needs a type or group attribute")); | ||
| 62 | + return NULL; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + for(f=0;info->popup[f] && pos < 0;pos++) | ||
| 66 | + { | ||
| 67 | + if(!g_strcasecmp(info->popup[f],id)) | ||
| 68 | + { | ||
| 69 | + pos = f; | ||
| 70 | + break; | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + if(pos < 0) | ||
| 75 | + { | ||
| 76 | + *error = g_error_new(ERROR_DOMAIN,EINVAL,_( "Unknown popup type \"%s\""),id); | ||
| 77 | + return NULL; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + widget = gtk_menu_new(); | ||
| 81 | + | ||
| 82 | + g_object_set_data(G_OBJECT(widget),"popup_id",(gpointer) pos); | ||
| 50 | 83 | ||
| 51 | return G_OBJECT(ui_insert_element(info, action, UI_ELEMENT_POPUP, names, values, G_OBJECT(widget), error)); | 84 | return G_OBJECT(ui_insert_element(info, action, UI_ELEMENT_POPUP, names, values, G_OBJECT(widget), error)); |
| 52 | } | 85 | } |
src/gtk/uiparser/private.h
| @@ -58,6 +58,7 @@ | @@ -58,6 +58,7 @@ | ||
| 58 | GtkWidget * center_widget; | 58 | GtkWidget * center_widget; |
| 59 | GStringChunk * strings; | 59 | GStringChunk * strings; |
| 60 | const gchar ** group; /**< Action group list */ | 60 | const gchar ** group; /**< Action group list */ |
| 61 | + const gchar ** popup; /**< Popup names */ | ||
| 61 | GHashTable * actions; /**< List of actions */ | 62 | GHashTable * actions; /**< List of actions */ |
| 62 | GHashTable * element_list[UI_ELEMENT_COUNT]; | 63 | GHashTable * element_list[UI_ELEMENT_COUNT]; |
| 63 | }; | 64 | }; |