poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 03446e528209433df3f52c6f0c66f8c1f61c3128
родитељ e278a2d890be264d44f235befefdc5970239da1b
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sat, 10 Jul 2021 14:41:34 +0200

Fix: reset info box focus when closing edit dialog; tidied up key handlers

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 5+----
Mpoe.c | 128+++++++++++++++++++++++++++++++++++++++++++------------------------------------
измењених датотека: 2, додавања: 70(+), брисања: 63(-)

diff --git a/TODO b/TODO @@ -4,10 +4,7 @@ [x] Line editing with cursor [ ] Previous/next word? - [x] Handle tabs in u32_draw_string when string start < first shown char - (Should take into account the shift, *after* % TAB_SIZE) - - [ ] Enter -> F6 -> Esc -> Enter should not focus info box + [x] Enter -> F6 -> Esc -> Enter should not focus info box [ ] Yank/paste (entire current msgstr) [ ] Copy msgid (only) to msgstr diff --git a/poe.c b/poe.c @@ -51,6 +51,8 @@ void next_untranslated(struct DrawState* state); void next_fuzzy(struct DrawState* state); void move_up(struct DrawState* state); void move_down(struct DrawState* state); +void edit_page_up(struct DrawState* state); +void edit_page_down(struct DrawState* state); void move_start(struct DrawState* state); void move_left(struct DrawState* state); void move_right(struct DrawState* state); @@ -403,6 +405,10 @@ void save_msgstr(struct DrawState* state) { uint32_t to_save[MAXMSG]; + + state->show_edit = 0; + state->edit_info_focused = 0; + if (state->input_buffer) { struct BufferLine* pinput_buffer = NULL; @@ -432,12 +438,16 @@ save_msgstr(struct DrawState* state) u32_set_msgstr(&state->entries[state->msgid_number-1], to_save, state->msgstr_index, 0, state); state->input_changed_fuzzy = UNCHANGED; - //state->dirty = 1; + + tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR); } void cancel_msgstr(struct DrawState* state) { + state->show_edit = 0; + state->edit_info_focused = 0; + if (state->input_buffer) for (size_t i = 0; i < state->input_rows_count; i++) free_bufferline(state->input_buffer+i); @@ -462,6 +472,8 @@ cancel_msgstr(struct DrawState* state) default:; } state->input_changed_fuzzy = UNCHANGED; + + tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR); } void @@ -917,6 +929,60 @@ move_down(struct DrawState* state) state->input_column); } +void +edit_page_up(struct DrawState* state) +{ + if (state->edit_info_focused) + { + if (state->info_first_shown_row > (EDIT_HEIGHT-3)/2) + state->info_first_shown_row -= (EDIT_HEIGHT-3)/2; + else + move_start(state); + return; + } + + save_msgstr(state); + move_list_up(state); + state->msgstr_index = 0; + load_msgstr(state); + load_info(state); + state->input_row = 0; + state->input_first_shown_row = 0; + state->input_first_shown_column = 0; + state->info_first_shown_row = 0; + state->info_first_shown_column = 0; + move_start(state); + state->error[0] = 0; +} + +void +edit_page_down(struct DrawState* state) +{ + if (state->edit_info_focused) + { + if (state->info_first_shown_row + (EDIT_HEIGHT-3)/2 < + state->info_rows_count-1) + state->info_first_shown_row += (EDIT_HEIGHT-3)/2; + return; + } + + save_msgstr(state); + state->dirty_before_edit = state->dirty; + state->fuzzy_before_edit = state->fuzzy_count; + state->input_changed_fuzzy = UNCHANGED; + move_list_down(state); + state->msgstr_index = 0; + load_msgstr(state); + load_info(state); + state->input_row = 0; + state->input_first_shown_row = 0; + state->input_first_shown_column = 0; + state->info_first_shown_row = 0; + state->info_first_shown_column = 0; + move_start(state); + state->error[0] = 0; +} + void move_start(struct DrawState* state) { @@ -1389,11 +1455,7 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) else if (ev->key == TB_KEY_CTRL_Q) strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); else if (ev->key == TB_KEY_CTRL_S) - { - state->show_edit = 0; save_msgstr(state); - tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR); - } else if (ev->key == TB_KEY_CTRL_U) erase_to_start(state); else if (ev->key == TB_KEY_CTRL_Z) @@ -1412,11 +1474,7 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) } } else if (ev->key == TB_KEY_ESC) - { - state->show_edit = 0; cancel_msgstr(state); - tb_set_cursor(TB_HIDE_CURSOR, TB_HIDE_CURSOR); - } else if (ev->key == TB_KEY_F6) state->edit_info_focused = !state->edit_info_focused; else if (ev->key == TB_KEY_F8) @@ -1428,58 +1486,10 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) move_start(state); else if (ev->key == TB_KEY_PGDN || ev->key == TB_KEY_CTRL_F) - { - if (state->edit_info_focused) - { - if (state->info_first_shown_row + (EDIT_HEIGHT-3)/2 < - state->info_rows_count-1) - state->info_first_shown_row += (EDIT_HEIGHT-3)/2; - } - else - { - save_msgstr(state); - state->dirty_before_edit = state->dirty; - state->fuzzy_before_edit = state->fuzzy_count; - state->input_changed_fuzzy = UNCHANGED; - move_list_down(state); - state->msgstr_index = 0; - load_msgstr(state); - load_info(state); - state->input_row = 0; - state->input_first_shown_row = 0; - state->input_first_shown_column = 0; - state->info_first_shown_row = 0; - state->info_first_shown_column = 0; - move_start(state); - state->error[0] = 0; - } - } + edit_page_down(state); else if (ev->key == TB_KEY_PGUP || ev->key == TB_KEY_CTRL_B) - { - if (state->edit_info_focused) - { - if (state->info_first_shown_row > (EDIT_HEIGHT-3)/2) - state->info_first_shown_row -= (EDIT_HEIGHT-3)/2; - else - move_start(state); - } - else - { - save_msgstr(state); - move_list_up(state); - state->msgstr_index = 0; - load_msgstr(state); - load_info(state); - state->input_row = 0; - state->input_first_shown_row = 0; - state->input_first_shown_column = 0; - state->info_first_shown_row = 0; - state->info_first_shown_column = 0; - move_start(state); - state->error[0] = 0; - } - } + edit_page_up(state); else if (ev->key == TB_KEY_SPACE) insert_char(state, ' '); else if (ev->key == TB_KEY_TAB)