poe

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

чување ebdf20e6e756b87f6d56921e05cf7dcb5efde2a5
родитељ c51e1dd6d73e183cb8bdd497ee6e68fe682bbd3c
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Thu,  3 Aug 2023 16:27:40 +0200

Tidy up error messages

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

Diffstat:
MTODO | 2+-
Mdraw.c | 8+++++---
Mdraw.h | 2--
Mpoe.c | 86+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Mutil.h | 4+++-
измењених датотека: 5, додавања: 56(+), брисања: 46(-)

diff --git a/TODO b/TODO @@ -1,7 +1,7 @@ TODO ==== -[ ] Replace "Unknown key (H for help)" with "Unknown key" where H is not +[x] Replace "Unknown key (H for help)" with "Unknown key" where H is not applicable as help character [ ] Replace strn* -> strc*: like str[^n]*, but with configurable string diff --git a/draw.c b/draw.c @@ -39,10 +39,12 @@ static const char* help[] = { "See the manual (man poe) for full help."}; static const char* editbox_title = "Edit translation"; const char* errors[] = { - [ERR_UNKNOWN_KEY] = "Unknown key (press H for help)", + [ERR_UNKNOWN_KEY] = "Unknown key", + [ERR_UNKNOWN_KEY_HELP] = "Unknown key (press H or F1 for help)", [ERR_EXIT_KEY] = "Press q or C-Q to quit", - [ERR_DLG_OPEN] = "Press Esc to close dialog or q/C-Q to quit", - [ERR_DLG_OPEN_QUIT] = "Press Esc to close dialog", + [ERR_DLG_OPEN_QUIT] = "Press Esc to close dialog or q/C-Q to quit", + [ERR_DLG_OPEN] = "Press Esc to close dialog first", + [ERR_DLG_FOCUS_EDIT] = "Switch to edit box first with F6", [ERR_EMPTY_FILE] = "No msgids to edit", [ERR_CANT_ALLOC] = "Memory allocation failed", [ERR_CANT_SAVE] = "File is not writeable", diff --git a/draw.h b/draw.h @@ -100,8 +100,6 @@ struct StatusSegment { Alignment alignment; }; -extern struct PoEntry* entries; - void init_bufferline(struct BufferLine* bl); void free_bufferline(struct BufferLine* bl); void init_drawstate(struct DrawState* state, char* error, char* filename, diff --git a/poe.c b/poe.c @@ -35,7 +35,7 @@ extern const char* program_name; void cancel_callback(struct DrawState* state, struct tb_event* ev); void goto_msgid(struct DrawState* state, const size_t msgid_number); void handle_key_event(struct tb_event* ev, struct DrawState* state); -void insert_char(struct DrawState* state, uint32_t ch); +int insert_char(struct DrawState* state, uint32_t ch); void insert_search_char(struct DrawState* state, uint32_t ch); struct DrawState* join_lines(struct DrawState* state, size_t first_line, int forward); @@ -76,6 +76,8 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) { const struct Key* current = NULL; + *state->error = 0; + if (state->in_prompt) { if (ev->ch == 'y' || ev->ch == 'n') @@ -107,7 +109,7 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) if (state->show_help) { - strcpy(state->error, errors[ERR_DLG_OPEN]); + strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); return; } else if (state->show_edit) @@ -122,7 +124,7 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) && !current->callback(state)) return; } - if (ev->ch) + if (!state->edit_info_focused && ev->ch) { insert_char(state, ev->ch); return; @@ -154,20 +156,29 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) if (((current->ev.key == ev->key) && !ev->ch) || (current->ev.ch && (current->ev.ch == ev->ch))) - if (current->callback - && !current->callback(state)) - return; + if (current->callback) + { + if (!current->callback(state)) + return; + else + break; + } } } - strcpy(state->error, errors[ERR_UNKNOWN_KEY]); + if (state->edit_info_focused) + strcpy(state->error, errors[ERR_DLG_FOCUS_EDIT]); + else if (state->show_edit || state->show_search) + strcpy(state->error, errors[ERR_UNKNOWN_KEY]); + else + strcpy(state->error, errors[ERR_UNKNOWN_KEY_HELP]); } -void +int insert_char(struct DrawState* state, uint32_t ch) { if (state->edit_info_focused) - return; + return 1; struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; size_t len = buffer_line->length; if (state->input_column < MAXBUFLINE - 1) @@ -200,6 +211,7 @@ insert_char(struct DrawState* state, uint32_t ch) buffer_line->text[state->input_column] = 0; } state->dirty = 1; + return 0; } void @@ -753,7 +765,7 @@ erase_backwards(struct DrawState* state) { struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; if (state->edit_info_focused) - return 0; + return 1; if (state->input_column > 0) { @@ -798,7 +810,7 @@ erase_forward(struct DrawState* state) { struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; if (state->edit_info_focused) - return 0; + return 1; if (buffer_line->text[state->input_column]) { @@ -827,10 +839,7 @@ int erase_prev_word(struct DrawState* state) { if (state->edit_info_focused) - { - strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); - return 0; - } + return 1; int i = state->input_column; size_t len = state->input_buffer[state->input_row].length; @@ -976,9 +985,12 @@ erase_search_to_start(struct DrawState* state) int erase_to_end(struct DrawState* state) { + struct BufferLine* buffer_line = NULL; + if (state->edit_info_focused) - return 0; - struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; + return 1; + + buffer_line = &state->input_buffer[state->input_row]; buffer_line->text[state->input_column] = 0; buffer_line->length = state->input_column; move_end(state); @@ -989,15 +1001,13 @@ erase_to_end(struct DrawState* state) int erase_to_start(struct DrawState* state) { - if (state->edit_info_focused) - { - strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); - return 0; - } - size_t i = state->input_column; struct BufferLine* buffer_line = &state->input_buffer[state->input_row]; size_t len = buffer_line->length; + + if (state->edit_info_focused) + return 1; + do { buffer_line->text[i - state->input_column] @@ -1016,7 +1026,7 @@ exit_program(struct DrawState* state) { if (state->show_edit) { - strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); + strcpy(state->error, errors[ERR_DLG_OPEN]); return 0; } if (state->dirty) @@ -1042,10 +1052,13 @@ hide_search(struct DrawState* state) int insert_line(struct DrawState* state) { + struct BufferLine* newbuf = NULL; + if (state->edit_info_focused) - return 0; + return 1; + state->input_rows_count++; - struct BufferLine* newbuf = realloc(state->input_buffer, + newbuf = realloc(state->input_buffer, state->input_rows_count * sizeof(struct BufferLine)); if (!newbuf) { @@ -1296,10 +1309,7 @@ int move_next_word(struct DrawState* state) { if (state->edit_info_focused) - { - strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); - return 0; - } + return 1; int i = state->input_column; uint32_t* pline = state->input_buffer[state->input_row].text; @@ -1324,10 +1334,7 @@ int move_prev_word(struct DrawState* state) { if (state->edit_info_focused) - { - strcpy(state->error, errors[ERR_DLG_OPEN_QUIT]); - return 0; - } + return 1; int i = state->input_column; uint32_t* pline = state->input_buffer[state->input_row].text; @@ -1619,9 +1626,10 @@ next_match(struct DrawState* state) int next_plural(struct DrawState* state) { + struct PoEntry* current = NULL; if (state->edit_info_focused) - return 0; - struct PoEntry* current = &state->entries[state->msgid_number - 1]; + return 1; + current = &state->entries[state->msgid_number - 1]; save_msgstr(state); if (state->msgstr_index + 1 < current->msgstr_count) state->msgstr_index++; @@ -1671,7 +1679,7 @@ int paste_paste_buffer_to_input(struct DrawState* state) { if (state->edit_info_focused) - return 0; + return 1; if (!state->in_prompt && *state->input_buffer->text) { @@ -1784,7 +1792,7 @@ int prev_plural(struct DrawState* state) { if (state->edit_info_focused) - return 0; + return 1; save_msgstr(state); if (state->msgstr_index > 0) state->msgstr_index--; @@ -1941,7 +1949,7 @@ int yank_input_to_paste_buffer(struct DrawState* state) { if (state->edit_info_focused) - return 0; + return 1; if (state->msgid_number == 1) { diff --git a/util.h b/util.h @@ -7,9 +7,11 @@ enum { ERR_UNKNOWN_KEY, + ERR_UNKNOWN_KEY_HELP, ERR_EXIT_KEY, - ERR_DLG_OPEN, ERR_DLG_OPEN_QUIT, + ERR_DLG_OPEN, + ERR_DLG_FOCUS_EDIT, ERR_EMPTY_FILE, ERR_CANT_ALLOC, ERR_CANT_SAVE,