poe

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

чување da8bfeee3ada652b60199749797dbdd98498706d
родитељ 6e6546c95da52a2594e0deebe3b3e4491a9476e0
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Fri,  2 Jul 2021 23:34:48 +0200

Start of msgstr[] plural switching support

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

Diffstat:
MTODO | 4+++-
Mpoe.c | 44++++++++++++++++++++++++++++++++++++++------
измењених датотека: 2, додавања: 41(+), брисања: 7(-)

diff --git a/TODO b/TODO @@ -42,7 +42,9 @@ [ ] .po file save - [ ] Editing of plural forms + [~] Editing of plural forms + [~] C-P/C-N = prev/next plural + [ ] Show current plural # in status line [ ] Yank/paste (entire current msgstr) diff --git a/poe.c b/poe.c @@ -91,6 +91,8 @@ quit_callback(struct DrawState* state, struct tb_event* ev) } } +struct BufferLine* load_msgstr(struct DrawState* state); +void save_msgstr(struct DrawState* state); void move_up(struct DrawState* state); void move_down(struct DrawState* state); void move_start(struct DrawState* state); @@ -103,6 +105,9 @@ void move_list_start(struct DrawState* state); void move_list_end(struct DrawState* state); void move_list_page_up(struct DrawState* state); void move_list_page_down(struct DrawState* state); +void next_plural(struct DrawState* state); +void prev_plural(struct DrawState* state); +void toggle_fuzzy(struct DrawState* state); size_t display_length(const struct DrawState* state, const size_t max_index); size_t input_length(const struct DrawState* state, const size_t max_index); void insert_char(struct DrawState* state, uint32_t ch); @@ -112,8 +117,9 @@ struct DrawState* insert_line(struct DrawState* state); struct DrawState* join_lines(struct DrawState* state, size_t first_line); struct BufferLine* -load_msgstr(struct DrawState* state, int msgstr_index) +load_msgstr(struct DrawState* state) { + int msgstr_index = state->msgstr_index; struct PoEntry* current = &state->entries[state->msgid_number-1]; size_t num_lines = current->msgstr_count == 0 ? 1 : u32_lines_in_string(*(current->msgstr+msgstr_index)); @@ -390,6 +396,25 @@ move_list_page_down(struct DrawState* state) move_list_end(state); } +void +next_plural(struct DrawState* state) +{ + struct PoEntry* current = &state->entries[state->msgid_number-1]; + save_msgstr(state); + if (state->msgstr_index + 1 < current->msgstr_count) + state->msgstr_index++; + load_msgstr(state); +} + +void +prev_plural(struct DrawState* state) +{ + save_msgstr(state); + if (state->msgstr_index > 0) + state->msgstr_index--; + load_msgstr(state); +} + void toggle_fuzzy(struct DrawState* state) { @@ -632,6 +657,12 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) if (!join_lines(state, state->input_row-1)) strcpy(state->error, errors[ERR_CANT_ALLOC]); } + else if (ev->key == TB_KEY_CTRL_K) + erase_to_end(state); + else if (ev->key == TB_KEY_CTRL_N) + next_plural(state); + else if (ev->key == TB_KEY_CTRL_P) + prev_plural(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) @@ -642,8 +673,6 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) } else if (ev->key == TB_KEY_CTRL_U) erase_to_start(state); - else if (ev->key == TB_KEY_CTRL_K) - erase_to_end(state); else if (ev->key == TB_KEY_CTRL_Z) toggle_fuzzy(state); else if (ev->key == TB_KEY_DELETE) @@ -685,7 +714,8 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) { save_msgstr(state); move_list_down(state); - load_msgstr(state, 0); + state->msgstr_index = 0; + load_msgstr(state); state->input_row = 0; state->input_first_shown_row = 0; move_start(state); @@ -696,7 +726,8 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) { save_msgstr(state); move_list_up(state); - load_msgstr(state, 0); + state->msgstr_index = 0; + load_msgstr(state); state->input_row = 0; state->input_first_shown_row = 0; move_start(state); @@ -777,7 +808,8 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) strcpy(state->error, errors[ERR_EMPTY_FILE]); else { - if (load_msgstr(state, 0)) + state->msgstr_index = 0; + if (load_msgstr(state)) { state->show_edit = 1; state->input_row = 0;