struct cui *cui;
void *data;
struct pmenu_item *item;
+ enum {
+ STATE_EDIT,
+ STATE_CANCEL,
+ STATE_SAVE,
+ } state;
void (*on_exit)(struct cui *cui,
struct pmenu_item *item,
struct pb_boot_data *bd);
if (!value || !*value)
return NULL;
- sep = NULL;
+ sep = "";
if (!prefix)
prefix = "";
else if (prefix[strlen(prefix)] != '/')
static void boot_editor_process_key(struct nc_scr *scr, int key)
{
struct boot_editor *boot_editor = boot_editor_from_scr(scr);
+ struct pmenu_item *item;
+ struct pb_boot_data *bd;
bool handled;
handled = widgetset_process_key(boot_editor->widgetset, key);
- if (handled) {
+ if (handled)
pad_refresh(boot_editor);
- return;
- }
- switch (key) {
- case 'x':
- case 27: /* ESC */
- boot_editor->on_exit(boot_editor->cui, NULL, NULL);
- nc_flush_keys();
+ else if (key == 'x' || key == 27)
+ boot_editor->state = STATE_CANCEL;
+
+ item = NULL;
+ bd = NULL;
+
+ switch (boot_editor->state) {
+ case STATE_SAVE:
+ item = boot_editor->item;
+ bd = boot_editor_prepare_data(boot_editor);
+ /* fall through */
+ case STATE_CANCEL:
+ boot_editor->on_exit(boot_editor->cui, item, bd);
+ break;
+ default:
+ break;
}
}
static void ok_click(void *arg)
{
struct boot_editor *boot_editor = arg;
- struct pb_boot_data *bd;
-
- bd = boot_editor_prepare_data(boot_editor);
- boot_editor->on_exit(boot_editor->cui, boot_editor->item, bd);
+ boot_editor->state = STATE_SAVE;
}
static void cancel_click(void *arg)
{
struct boot_editor *boot_editor = arg;
- boot_editor->on_exit(boot_editor->cui, NULL, NULL);
+ boot_editor->state = STATE_CANCEL;
}
static int layout_pair(struct boot_editor *boot_editor, int y,
boot_editor_populate_device_select(boot_editor, sysinfo);
+ boot_editor_layout_widgets(boot_editor);
+
widgetset_post(boot_editor->widgetset);
pad_refresh(boot_editor);
boot_editor->cui = cui;
boot_editor->item = item;
boot_editor->on_exit = on_exit;
+ boot_editor->state = STATE_EDIT;
boot_editor->label_x = 1;
boot_editor->field_x = 9;
boot_editor->scr.frame.rtitle = NULL;
boot_editor->scr.frame.help = talloc_strdup(boot_editor,
"Enter=accept");
+ nc_scr_frame_draw(&boot_editor->scr);
if (item) {
struct pb_boot_data *bd = cod_from_item(item)->bd;
boot_editor_setup_widgets(boot_editor, sysinfo);
boot_editor_layout_widgets(boot_editor);
+ wrefresh(boot_editor->scr.main_ncw);
return boot_editor;
}