ref: 170dcd22006fe070a133860e5dd971278057af9f
parent: e1a9def1933089b3c9f7d4f2a6f265fa03c17e42
author: cancel <cancel@cancel.fm>
date: Mon Dec 17 20:03:41 EST 2018
Add start of Qform driving code
--- a/term_util.c
+++ b/term_util.c
@@ -293,6 +293,27 @@
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);
@@ -300,4 +321,15 @@
free_field(qf->ncurses_fields[i]);
}
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;
}
--- a/term_util.h
+++ b/term_util.h
@@ -85,6 +85,16 @@
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 @@
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;
--- a/tui_main.c
+++ b/tui_main.c
@@ -1485,6 +1485,7 @@
enum {
Main_menu_id = 1,
+ Save_as_form_id,
};
enum {
@@ -1631,6 +1632,12 @@
}
}
+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 @@
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 @@
}
} 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;