чување fae96b49de5ba30faf0d61608292afacd1074079
родитељ 8834e27fb0ca71c52c3589d346cd854f93f4fb42
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 18 Nov 2021 13:07:35 +0100
poe.c: Fix handling of dirty state when saving msgstr from edit box
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | poe.c | | | 48 | +++++++++++++++++++++++++----------------------- |
измењених датотека: 1, додавања: 25(+), брисања: 23(-)
diff --git a/poe.c b/poe.c
@@ -128,7 +128,8 @@ format_filename(char* result, size_t result_size, const char* format,
if (!result)
return;
snprintf(result, result_size, format, u8_basename(state->filename),
- state->show_edit ? (state->dirty_before_edit ? "*" : "")
+ state->show_edit ? (
+ (state->dirty_before_edit || state->dirty) ? "*" : "")
: (state->dirty ? "*" : ""));
}
@@ -287,7 +288,7 @@ load_info(struct DrawState* state)
if (current->msgid_plural)
{
newlen = u32_u8_strncpy(pnewbuf->text,
- "msgid_plural:", MAXBUFLINE);
+ "msgid_plural:", MAXBUFLINE);
pnewbuf->length = newlen;
if (newlen > state->info_rows_maxlen)
state->info_rows_maxlen = newlen;
@@ -311,7 +312,7 @@ load_info(struct DrawState* state)
if (first->plural_forms)
{
newlen = u32_u8_strncpy(pnewbuf->text,
- "Plural forms:", MAXBUFLINE);
+ "Plural forms:", MAXBUFLINE);
pnewbuf->length = newlen;
if (newlen > state->info_rows_maxlen)
state->info_rows_maxlen = newlen;
@@ -340,7 +341,7 @@ load_info(struct DrawState* state)
uint32_t* comment = current->comments[i];
size_t len = u32_strlen(comment);
newlen = u32_strncpy(pnewbuf->text, comment,
- MIN(len + 1, MAXBUFLINE));
+ MIN(len + 1, MAXBUFLINE));
pnewbuf->length = newlen;
if (newlen > state->info_rows_maxlen)
state->info_rows_maxlen = newlen;
@@ -350,7 +351,7 @@ load_info(struct DrawState* state)
if (current->trans_comments)
{
newlen = u32_u8_strncpy(pnewbuf->text,
- "Translation comments:", MAXBUFLINE);
+ "Translation comments:", MAXBUFLINE);
pnewbuf->length = newlen;
if (newlen > state->info_rows_maxlen)
state->info_rows_maxlen = newlen;
@@ -372,7 +373,7 @@ load_info(struct DrawState* state)
if (current->ref_comments)
{
newlen = u32_u8_strncpy(pnewbuf->text,
- "References:", MAXBUFLINE);
+ "References:", MAXBUFLINE);
pnewbuf->length = newlen;
if (newlen > state->info_rows_maxlen)
state->info_rows_maxlen = newlen;
@@ -442,7 +443,7 @@ load_msgstr(struct DrawState* state)
u32_strncpy(pnewbuf->text, pumsgstr,
MIN(len + 1, MAXBUFLINE));
newlen = u32_decode_tabs(pnewbuf->text,
- MAXBUFLINE);
+ MAXBUFLINE);
pnewbuf->length = newlen;
pumsgstr += len + (pumsgstr[len] ? 2 : 0);
pnewbuf++;
@@ -494,11 +495,12 @@ save_msgstr(struct DrawState* state)
}
}
free(state->input_buffer);
- state->input_buffer = NULL;
+ state->input_buffer = NULL;
state->input_rows_count = 0;
for (size_t i = 0; i < state->info_rows_count; i++)
free_bufferline(state->info_buffer + i);
free(state->info_buffer);
+ state->dirty = (state->dirty_before_edit || state->dirty);
state->info_rows_count = 0;
state->info_buffer = NULL;
u32_encode_tabs(to_save, to_save_size * sizeof(uint32_t));
@@ -1018,7 +1020,7 @@ paste_paste_buffer_to_input(struct DrawState* state)
for (size_t i = 1; i < state->input_rows_count; i++)
free_bufferline(state->input_buffer + i);
state->input_buffer = realloc(state->input_buffer,
- sizeof(struct BufferLine));
+ sizeof(struct BufferLine));
*(state->input_buffer->text) = 0;
state->input_column = 0;
state->input_display_column = 0;
@@ -1150,18 +1152,18 @@ next_untranslated(struct DrawState* state)
if (!current->msgstr || !*current->msgstr
|| u32_strlen(*current->msgstr) == 0)
{
- int save_show_edit = state->show_edit;
- if (save_show_edit)
+ int saved_show_edit = state->show_edit;
+ if (saved_show_edit)
{
if (state->dirty)
save_msgstr(state);
- else
+ else /* No need to call cancel_msgstr */
state->dirty = state->dirty_before_edit;
}
goto_msgid(state, e + 1);
- if (save_show_edit)
+ if (saved_show_edit)
{
state->msgstr_index = 0;
show_edit(state);
@@ -1186,18 +1188,18 @@ next_fuzzy(struct DrawState* state)
current = state->entries + e;
if (current->flags & FL_FUZZY)
{
- int save_show_edit = state->show_edit;
- if (save_show_edit)
+ int saved_show_edit = state->show_edit;
+ if (saved_show_edit)
{
if (state->dirty)
save_msgstr(state);
- else
+ else /* No need to call cancel_msgstr */
state->dirty = state->dirty_before_edit;
}
goto_msgid(state, e + 1);
- if (save_show_edit)
+ if (saved_show_edit)
{
state->msgstr_index = 0;
show_edit(state);
@@ -1323,7 +1325,7 @@ edit_page_up(struct DrawState* state)
if (state->dirty)
save_msgstr(state);
- else
+ else /* No need to call cancel_msgstr */
state->dirty = state->dirty_before_edit;
move_list_up(state);
state->msgstr_index = 0;
@@ -1343,7 +1345,7 @@ edit_page_down(struct DrawState* state)
if (state->dirty)
save_msgstr(state);
- else
+ else /* No need to call cancel_msgstr */
state->dirty = state->dirty_before_edit;
move_list_down(state);
state->msgstr_index = 0;
@@ -1502,8 +1504,8 @@ erase_prev_word(struct DrawState* state)
pline[len] = 0;
state->input_column = i;
state->input_display_column = display_length(state,
- state->input_buffer[state->input_row].text,
- state->input_column);
+ state->input_buffer[state->input_row].text,
+ state->input_column);
state->dirty = 1;
}
@@ -1522,8 +1524,8 @@ move_end(struct DrawState* state)
size_t len = state->input_buffer[state->input_row].length;
state->input_column = len;
size_t dlen = display_length(state,
- state->input_buffer[state->input_row].text,
- state->input_column);
+ state->input_buffer[state->input_row].text,
+ state->input_column);
state->input_display_column = dlen;
if (dlen > EDIT_WIDTH - 4)
state->input_first_shown_column = dlen - EDIT_WIDTH + 4;