+ ObMenuParseState *state = data;
+ gchar *name = NULL, *title = NULL, *script = NULL;
+ ObMenu *menu;
+
+ if (!parse_attr_string("id", node, &name))
+ goto parse_menu_fail;
+
+ if (!g_hash_table_lookup(menu_hash, name)) {
+ if (!parse_attr_string("label", node, &title))
+ goto parse_menu_fail;
+
+ if ((menu = menu_new(name, title, NULL))) {
+ menu->pipe_creator = state->pipe_creator;
+ if (parse_attr_string("execute", node, &script)) {
+ menu->execute = parse_expand_tilde(script);
+ } else {
+ ObMenu *old;
+
+ old = state->parent;
+ state->parent = menu;
+ parse_tree(i, doc, node->children);
+ state->parent = old;
+ }
+ }
+ }
+
+ if (state->parent)
+ menu_add_submenu(state->parent, -1, name);
+
+parse_menu_fail:
+ g_free(name);
+ g_free(title);
+ g_free(script);
+}
+
+ObMenu* menu_new(gchar *name, gchar *title, gpointer data)
+{
+ ObMenu *self;
+
+ self = g_new0(ObMenu, 1);
+ self->name = g_strdup(name);
+ self->title = g_strdup(title);
+ self->data = data;
+
+ g_hash_table_replace(menu_hash, self->name, self);
+
+ return self;
+}
+
+static void menu_destroy_hash_value(ObMenu *self)
+{
+ /* make sure its not visible */
+ {
+ GList *it;
+ ObMenuFrame *f;
+
+ for (it = menu_frame_visible; it; it = g_list_next(it)) {
+ f = it->data;
+ if (f->menu == self)
+ menu_frame_hide_all();
+ }
+ }
+
+ if (self->destroy_func)
+ self->destroy_func(self, self->data);
+
+ menu_clear_entries(self);
+ g_free(self->name);
+ g_free(self->title);
+ g_free(self->execute);
+
+ g_free(self);
+}
+
+void menu_free(ObMenu *menu)
+{
+ g_hash_table_remove(menu_hash, menu->name);
+}
+
+void menu_show(gchar *name, gint x, gint y, ObClient *client)
+{
+ ObMenu *self;
+ ObMenuFrame *frame;
+
+ if (!(self = menu_from_name(name))) return;
+
+ menu_frame_hide_all();
+
+ frame = menu_frame_new(self, client);
+ menu_frame_move(frame, x, y);
+ menu_frame_show(frame, NULL);
+ if (frame->entries)
+ menu_frame_select_next(frame);