poe

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

чување 9ce3033da362df49ec39b6c2ea20474a563e98a6
родитељ 26e7e0cddd03536129f8c155ec995640c6838b97
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sat, 10 Jul 2021 22:16:47 +0200

Added F5 = copy msgid to current msgstr

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

Diffstat:
MTODO | 6++++--
Mdraw.c | 1+
Mpoe.1.in | 5+++++
Mpoe.c | 108++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
измењених датотека: 4, додавања: 95(+), брисања: 25(-)

diff --git a/TODO b/TODO @@ -6,8 +6,10 @@ [x] Enter -> F6 -> Esc -> Enter should not focus info box - [ ] Yank/paste (entire current msgstr) - [ ] Copy msgid (only) to msgstr + [~] Yank/paste (entire current msgstr) + [x] Copy msgid (only) to msgstr + [ ] Yank msgstr to paste buffer + [ ] Paste paste buffer to msgstr [ ] Handle #~ (Don't show; flag? But write to file) diff --git a/draw.c b/draw.c @@ -110,6 +110,7 @@ init_drawstate(struct DrawState* state, char* error, char* filename, state->show_help = 0; state->show_edit = 0; state->edit_info_focused = 0; + state->show_search = 0; state->msgid_number = state->msgid_count > 0 ? 1 : 0; state->fuzzy_count = 0; state->untranslated_count = 0; diff --git a/poe.1.in b/poe.1.in @@ -132,6 +132,11 @@ When the info box is focused, arrow keys, \fCC-B\fP/\fCC-F\fP (\fCPgUp\fP/\fCPgDn\fP) and \fCC-A\fP/\fCC-E\fP (\fCHome\fP/\fCEnd\fP) keys scroll the info box. . +.LP +When the search box is open, relevant text editing and movement commands from +the edit box also apply. For example, \fCC-R\fP moves one word backwards, and +\fCC-W\fP deletes one word backwards. +. .SH "MESSAGE FLAGS" . .LP diff --git a/poe.c b/poe.c @@ -48,6 +48,7 @@ void erase_search_to_end(struct DrawState* state); void move_search_prev_word(struct DrawState* state); void move_search_next_word(struct DrawState* state); void erase_search_prev_word(struct DrawState* state); +struct DrawState* copy_msgid_to_input(struct DrawState* state); void next_match(struct DrawState* state); void prev_match(struct DrawState* state); void next_untranslated(struct DrawState* state); @@ -776,6 +777,59 @@ erase_search_prev_word(struct DrawState* state) next_match(state); } +struct DrawState* +copy_msgid_to_input(struct DrawState* state) +{ + if (state->edit_info_focused) + return state; + struct PoEntry* current = &state->entries[state->msgid_number-1]; + size_t msgid_num_lines = u32_lines_in_string(current->msgid); + size_t lines_to_init = state->input_rows_count < msgid_num_lines + ? msgid_num_lines - state->input_rows_count : 0; + size_t lines_to_free = state->input_rows_count > msgid_num_lines + ? state->input_rows_count - msgid_num_lines : 0; + for (size_t i = 0; i < lines_to_free; i++) + free_bufferline(state->input_buffer+ + state->input_rows_count-i-1); + struct BufferLine* newbuf = realloc( + state->input_buffer, msgid_num_lines * + sizeof(struct BufferLine)); + uint32_t* pmsgid = current->msgid; + + if (!newbuf) + return NULL; + + struct BufferLine* pbuffer = NULL; + for (size_t i = 0; i < lines_to_init; i++) + { + pbuffer = newbuf+msgid_num_lines-1-i; + init_bufferline(pbuffer); + uint32_t* newtext = calloc(MAXBUFLINE, sizeof(uint32_t)); + if (!newtext) + return NULL; + pbuffer->text = newtext; + } + + if (pmsgid) + for (size_t i = 0; i < msgid_num_lines; i++) + { + pbuffer = newbuf+i; + size_t len = u32_line_length(pmsgid); + size_t newlen = 0; + u32_strncpy(pbuffer->text, pmsgid, MIN(len+1, + MAXBUFLINE)); + newlen = u32_decode_tabs(pbuffer->text, MAXBUFLINE); + pbuffer->length = newlen; + pmsgid += len+(pmsgid[len] ? 2 : 0); + } + + state->input_rows_count = msgid_num_lines; + state->input_buffer = newbuf; + state->dirty = 1; + + return state; +} + void next_match(struct DrawState* state) { @@ -1044,7 +1098,16 @@ edit_page_up(struct DrawState* state) return; } - save_msgstr(state); + if (state->dirty) + { + save_msgstr(state); + state->dirty_before_edit = 1; + } + else + state->dirty = state->dirty_before_edit; + state->fuzzy_before_edit = state->fuzzy_count; + state->input_changed_fuzzy = UNCHANGED; + state->show_edit = 1; move_list_up(state); state->msgstr_index = 0; load_msgstr(state); @@ -1069,10 +1132,17 @@ edit_page_down(struct DrawState* state) return; } - save_msgstr(state); - state->dirty_before_edit = state->dirty; + if (state->dirty) + { + save_msgstr(state); + state->dirty_before_edit = 1; + } + else + state->dirty = state->dirty_before_edit; + state->dirty = state->dirty_before_edit; state->fuzzy_before_edit = state->fuzzy_count; state->input_changed_fuzzy = UNCHANGED; + state->show_edit = 1; move_list_down(state); state->msgstr_index = 0; load_msgstr(state); @@ -1665,6 +1735,8 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state) } else if (ev->key == TB_KEY_ESC) cancel_msgstr(state); + else if (ev->key == TB_KEY_F5) + copy_msgid_to_input(state); else if (ev->key == TB_KEY_F6) state->edit_info_focused = !state->edit_info_focused; else if (ev->key == TB_KEY_F8) @@ -1736,11 +1808,9 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) } else if (state->show_help) strcpy(state->error, errors[ERR_DLG_OPEN]); - else if (ev->key == TB_KEY_ARROW_DOWN - || ev->ch == 'j') + else if (ev->key == TB_KEY_ARROW_DOWN || ev->ch == 'j') move_list_down(state); - else if (ev->key == TB_KEY_ARROW_UP - || ev->ch == 'k') + else if (ev->key == TB_KEY_ARROW_UP || ev->ch == 'k') move_list_up(state); else if (ev->key == TB_KEY_CTRL_B || ev->key == TB_KEY_PGUP) move_list_page_up(state); @@ -1772,11 +1842,9 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) } state->dirty = 0; } - else if (ev->key == TB_KEY_CTRL_Z - || (ev->ch == 'f' && !state->show_edit)) + else if (ev->key == TB_KEY_CTRL_Z || ev->ch == 'f') toggle_fuzzy(state); - else if (ev->key == TB_KEY_END - || ev->ch == 'G') + else if (ev->key == TB_KEY_END || ev->ch == 'G') move_list_end(state); else if (ev->key == TB_KEY_ENTER) { @@ -1806,17 +1874,14 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) } } } - else if (ev->key == TB_KEY_F1 - || ev->ch == 'H') + else if (ev->key == TB_KEY_F1 || ev->ch == 'H') { state->show_help = 1; state->error[0] = 0; } - else if (ev->key == TB_KEY_F3 - || ev->ch == 'n') + else if (ev->key == TB_KEY_F3 || ev->ch == 'n') next_match(state); - else if (ev->key == TB_KEY_F4 - || ev->ch == 'N') + else if (ev->key == TB_KEY_F4 || ev->ch == 'N') prev_match(state); else if (ev->key == TB_KEY_F7 || ev->ch == '/') show_search(state); @@ -1840,8 +1905,7 @@ handle_search_key_event(struct tb_event* ev, struct DrawState* state) move_search_left(state); else if (ev->key == TB_KEY_ARROW_RIGHT) move_search_right(state); - else if ((ev->key == TB_KEY_BACKSPACE - || ev->key == TB_KEY_BACKSPACE2)) + else if ((ev->key == TB_KEY_BACKSPACE || ev->key == TB_KEY_BACKSPACE2)) erase_search_backwards(state); else if (ev->key == TB_KEY_CTRL_K) erase_search_to_end(state); @@ -1855,8 +1919,7 @@ handle_search_key_event(struct tb_event* ev, struct DrawState* state) erase_search_prev_word(state); else if (ev->key == TB_KEY_DELETE) erase_search_forward(state); - else if (ev->key == TB_KEY_END - || ev->key == TB_KEY_CTRL_E) + else if (ev->key == TB_KEY_END || ev->key == TB_KEY_CTRL_E) move_search_end(state); else if (ev->key == TB_KEY_ENTER) hide_search(state); @@ -1866,8 +1929,7 @@ handle_search_key_event(struct tb_event* ev, struct DrawState* state) next_match(state); else if (ev->key == TB_KEY_F4) prev_match(state); - else if (ev->key == TB_KEY_HOME - || ev->key == TB_KEY_CTRL_A) + else if (ev->key == TB_KEY_HOME || ev->key == TB_KEY_CTRL_A) move_search_start(state); else if (ev->key == TB_KEY_SPACE) insert_search_char(state, ' ');