ref: 16bae89e9d04d991e90168880f91cfda05550f7f
parent: 0c0fa96f1ff0d1e1e47db9d8549e665030dcd3b1
author: cancel <cancel@cancel.fm>
date: Mon Dec 17 21:33:46 EST 2018
Add more save as form logic
--- a/term_util.c
+++ b/term_util.c
@@ -149,6 +149,12 @@
if (qb->title) {
qblock_print_title(qb, qb->title, active ? A_NORMAL : A_DIM);
}
+ if (qb->tag == Qblock_type_qform) {
+ Qform* qf = qform_of(qb);
+ if (qf->ncurses_form) {
+ pos_form_cursor(qf->ncurses_form);
+ }
+ }
}
WINDOW* qmsg_window(Qmsg* qm) { return qm->qblock.content_window; }
@@ -296,9 +302,10 @@
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);
+ FIELD* f = new_field(1, 30, 0, 0, 0, 0);
set_field_buffer(f, 0, initial);
set_field_userptr(f, (void*)(intptr_t)(id));
+ field_opts_off(f, O_WRAP | O_BLANK | O_STATIC);
qf->ncurses_fields[qf->fields_count] = f;
++qf->fields_count;
qf->ncurses_fields[qf->fields_count] = NULL;
@@ -314,8 +321,13 @@
post_form(qf->ncurses_form);
// quick'n'dirty cursor change for now
curs_set(1);
+ form_driver(qf->ncurses_form, REQ_END_LINE);
}
+void qform_set_title(Qform* qf, char const* title) {
+ qblock_set_title(&qf->qblock, title);
+}
+
void qform_free(Qform* qf) {
curs_set(0);
unpost_form(qf->ncurses_form);
@@ -327,12 +339,25 @@
}
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;
}
+ case KEY_RIGHT:
+ form_driver(qf->ncurses_form, REQ_RIGHT_CHAR);
+ return false;
+ case KEY_LEFT:
+ form_driver(qf->ncurses_form, REQ_LEFT_CHAR);
+ return false;
+ case 127: // backspace in terminal.app, apparently
+ case KEY_BACKSPACE:
+ case CTRL_PLUS('h'):
+ form_driver(qf->ncurses_form, REQ_DEL_PREV);
+ return false;
+ default:
+ form_driver(qf->ncurses_form, key);
+ return false;
}
return false;
}
--- a/term_util.h
+++ b/term_util.h
@@ -124,6 +124,7 @@
Qform* qform_of(Qblock* qb);
void qform_add_text_line(Qform* qf, int id, char const* initial);
void qform_push_to_nav(Qform* qf);
+void qform_set_title(Qform* qf, char const* title);
bool qform_drive(Qform* qf, int key, Qform_action* out_action);
extern Qnav_stack qnav_stack;
--- a/tui_main.c
+++ b/tui_main.c
@@ -1636,6 +1636,7 @@
Qform* qf = qform_create(Save_as_form_id);
qform_add_text_line(qf, 0, "file name");
qform_push_to_nav(qf);
+ qform_set_title(qf, "Save As");
}
//