diff --git a/term_util.c b/term_util.c index fba2068..14e5a08 100644 --- a/term_util.c +++ b/term_util.c @@ -293,6 +293,27 @@ Qform* qform_create(int id) { Qform* qform_of(Qblock* qb) { return ORCA_CONTAINER_OF(qb, Qform, qblock); } +int qform_id(Qform const* qf) { return qf->id; } + +void qform_add_text_line(Qform* qf, int id, char const* initial) { + FIELD* f = new_field(1, 20, 0, 0, 0, 0); + set_field_buffer(f, 0, initial); + set_field_userptr(f, (void*)(intptr_t)(id)); + qf->ncurses_fields[qf->fields_count] = f; + ++qf->fields_count; + qf->ncurses_fields[qf->fields_count] = NULL; +} + +void qform_push_to_nav(Qform* qf) { + qf->ncurses_form = new_form(qf->ncurses_fields); + int form_min_h, form_min_w; + scale_form(qf->ncurses_form, &form_min_h, &form_min_w); + qnav_stack_push(Qblock_type_qform, form_min_h, form_min_w, &qf->qblock); + set_form_win(qf->ncurses_form, qf->qblock.outer_window); + set_form_sub(qf->ncurses_form, qf->qblock.content_window); + post_form(qf->ncurses_form); +} + void qform_free(Qform* qf) { unpost_form(qf->ncurses_form); free_form(qf->ncurses_form); @@ -301,3 +322,14 @@ void qform_free(Qform* qf) { } free(qf); } + +bool qform_drive(Qform* qf, int key, Qform_action* out_action) { + (void)qf; + switch (key) { + case 27: { + out_action->any.type = Qform_action_type_canceled; + return true; + } + } + return false; +} diff --git a/term_util.h b/term_util.h index 669e54a..33edcc1 100644 --- a/term_util.h +++ b/term_util.h @@ -85,6 +85,16 @@ typedef union { typedef struct Qform Qform; +typedef enum { + Qform_action_type_canceled, +} Qform_action_type; +typedef struct { + Qform_action_type type; +} Qform_action_any; +typedef union { + Qform_action_any any; +} Qform_action; + void qnav_init(void); void qnav_deinit(void); Qblock* qnav_top_block(void); @@ -110,6 +120,10 @@ Qmenu* qmenu_of(Qblock* qb); bool qmenu_top_is_menu(int id); Qform* qform_create(int id); +int qform_id(Qform const* qf); Qform* qform_of(Qblock* qb); +void qform_add_text_line(Qform* qf, int id, char const* initial); +void qform_push_to_nav(Qform* qf); +bool qform_drive(Qform* qf, int key, Qform_action* out_action); extern Qnav_stack qnav_stack; diff --git a/tui_main.c b/tui_main.c index 43563a9..be8db3c 100644 --- a/tui_main.c +++ b/tui_main.c @@ -1485,6 +1485,7 @@ bool hacky_try_save(Field* field, char const* filename) { enum { Main_menu_id = 1, + Save_as_form_id, }; enum { @@ -1631,6 +1632,12 @@ void try_save_with_msg(Ged* ged) { } } +void push_save_as_form(void) { + Qform* qf = qform_create(Save_as_form_id); + qform_add_text_line(qf, 0, "file name"); + qform_push_to_nav(qf); +} + // // main // @@ -1950,10 +1957,11 @@ int main(int argc, char** argv) { try_save_with_msg(&ged_state); break; case Main_menu_save_as: { - Qmsg* msg = qmsg_push(3, 30); - WINDOW* msgw = qmsg_window(msg); - wmove(msgw, 0, 1); - wprintw(msgw, "Not yet implemented"); + // Qmsg* msg = qmsg_push(3, 30); + // WINDOW* msgw = qmsg_window(msg); + // wmove(msgw, 0, 1); + // wprintw(msgw, "Not yet implemented"); + push_save_as_form(); } break; } } @@ -1962,6 +1970,15 @@ int main(int argc, char** argv) { } } break; case Qblock_type_qform: { + Qform* qf = qform_of(qb); + Qform_action act; + if (qform_drive(qf, key, &act)) { + switch (act.any.type) { + case Qform_action_type_canceled: + qnav_stack_pop(); + break; + } + } } break; } goto next_getch;