[Users] Undo for "Insert file" not working as expected
Michael Gmelin
freebsd at grem.de
Wed May 15 13:47:28 CEST 2013
Hi,
After inserting the wrong file into the message compose window by
accident through Message->Insert File, Edit->Undo won't undo this
action in one step, but line by line instead. I can imagine why this is
happening, but I think it's pretty counter intuitive. In fact it
appears to the user that nothing is happening at all, since the cursor
stays at the top of the inserted text after the insert file operation
and therefore removal of lines at the bottom through undo is not
apparent.
The code in question is (compose.c: compose_insert_file):
while (fgets(buf, sizeof(buf), fp) != NULL) {
gchar *str;
if (g_utf8_validate(buf, -1, NULL) == TRUE)
str = g_strdup(buf);
else
str = conv_codeset_strdup
(buf, cur_encoding, CS_INTERNAL);
if (!str) continue;
/* strip <CR> if DOS/Windows file,
replace <CR> with <LF> if Macintosh file. */
strcrchomp(str);
len = strlen(str);
if (len > 0 && str[len - 1] != '\n') {
while (--len >= 0)
if (str[len] == '\r') str[len] = '\n';
}
gtk_text_buffer_insert(buffer, &iter, str, -1);
g_free(str);
}
So every single gtk_text_buffer_insert call is regarded as one user
action to undo.
If I'm reading the gtk documentation correctly, wrapping this block
(plus the following compose auto wrap action) into
gtk_text_buffer_begin_user_action(buffer);
...
gtk_text_buffer_end_user_action(buffer);
*might* do the trick (I'm not in a position to test this myself right
now, but I assume that the claws developers know gtk pretty well at
this point).
Cheers,
Michael
--
Michael Gmelin
More information about the Users
mailing list