summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-menu.h
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-03-12 14:59:03 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-04-10 11:18:24 +0800
commit1bbd230d618162ccd5ea97540a413c766a07c0cb (patch)
tree8bf596660165d015328d54930ba2f91ed4c4effd /ui/ncurses/nc-menu.h
parente07bd59ad5f4ba9cd113f8dfdcc72e6ca2e69819 (diff)
downloadtalos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.tar.gz
talos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.zip
ui/ncurses: Separate menu item creation & initialisation from insertion
Currently, the menu item creation is has two main functions: pmenu_item_alloc and pmenu_item_setup. The latter does initialisation (it sets item->name), and inserts the item into the menu. We have pmenu_item_init to combine this into one, but that means we need to do further initialisation (eg, to set on_execute) after the item has been added to the menu. Instead, this change use a more direct _create and _insert interface. Create does the allocation and initialisation, while _insert does the actual insertion. This means new_item failures will be detected at creation time, rather than during pmenu_insert. Also, we're now insert a completely-populated item into the menu, rather than populating on_edit, on_execute and data after insertion. Because we can detect errors from creation (ie, from new_item failing), we add handling code to cui_boot_option_add and cui_boot_editor_on_exit. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses/nc-menu.h')
-rw-r--r--ui/ncurses/nc-menu.h19
1 files changed, 3 insertions, 16 deletions
diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
index 63da2e5..8e9c56b 100644
--- a/ui/ncurses/nc-menu.h
+++ b/ui/ncurses/nc-menu.h
@@ -53,9 +53,9 @@ struct pmenu_item {
int (*on_execute)(struct pmenu_item *item);
};
-struct pmenu_item *pmenu_item_alloc(struct pmenu *menu);
-struct pmenu_item *pmenu_item_setup(struct pmenu *menu, struct pmenu_item *i,
- unsigned int index, const char *name);
+struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name);
+void pmenu_item_insert(struct pmenu *menu, struct pmenu_item *item,
+ unsigned int index);
void pmenu_item_delete(struct pmenu_item *item);
static inline struct pmenu_item *pmenu_item_from_arg(void *arg)
@@ -71,19 +71,6 @@ static inline struct cui_opt_data *cod_from_item(struct pmenu_item *item)
return item->data;
}
-static inline struct pmenu_item *pmenu_item_init(struct pmenu *menu,
- unsigned int index, const char *name)
-{
- struct pmenu_item *item = pmenu_item_alloc(menu);
-
- if (pmenu_item_setup(menu, item, index, name)) {
- talloc_free(item);
- item = NULL;
- }
-
- return item;
-}
-
/**
* struct pmenu - Data structure defining complete menu.
* @insert_pt: Index in nc item array.
OpenPOWER on IntegriCloud