Browse Source

Add message on successful save

master
cancel 6 years ago
parent
commit
2e556815eb
  1. 41
      tui_main.c

41
tui_main.c

@ -1460,10 +1460,13 @@ void app_input_cmd(App_state* a, App_input_cmd ev) {
} }
bool app_hacky_try_save(App_state* a) { bool app_hacky_try_save(App_state* a) {
if (!a->filename) return false; if (!a->filename)
if (a->field.height == 0 || a->field.width == 0) return false; return false;
if (a->field.height == 0 || a->field.width == 0)
return false;
FILE* f = fopen(a->filename, "w"); FILE* f = fopen(a->filename, "w");
if (!f) return false; if (!f)
return false;
field_fput(&a->field, f); field_fput(&a->field, f);
fclose(f); fclose(f);
return true; return true;
@ -1849,9 +1852,35 @@ int main(int argc, char** argv) {
app_input_character(&app_state, '.'); app_input_character(&app_state, '.');
break; break;
case KEY_F(2): case KEY_F(2): {
app_hacky_try_save(&app_state); if (app_state.is_playing) {
break; app_input_cmd(&app_state, App_input_cmd_toggle_play_pause);
}
bool ok = app_hacky_try_save(&app_state);
werase(stdscr);
notimeout(stdscr, FALSE);
wmove(stdscr, 0, 0);
if (ok) {
wprintw(stdscr, "Saved file %s\nPress any key to continue\n",
app_state.filename);
} else {
wprintw(stdscr, "FAILED to save %s\nPress any key to continue\n",
app_state.filename);
}
bool did_resize = false;
for (;;) {
int key0 = wgetch(stdscr);
if (key0 == KEY_RESIZE)
did_resize = true;
if (key0 != KEY_RESIZE && key0 != ERR)
break;
}
werase(stdscr);
app_state.is_draw_dirty = true;
if (did_resize)
ungetch(KEY_RESIZE);
wtimeout(stdscr, cur_timeout);
} break;
default: default:
if (key >= CHAR_MIN && key <= CHAR_MAX && is_valid_glyph((Glyph)key)) { if (key >= CHAR_MIN && key <= CHAR_MAX && is_valid_glyph((Glyph)key)) {

Loading…
Cancel
Save