MsgInfo *msginfo,
const gchar *fmt,
const gchar *qmark,
- const gchar *body);
+ const gchar *body,
+ gboolean rewrap);
static void compose_reply_set_entry (Compose *compose,
MsgInfo *msginfo,
if (prefs_common.auto_exteditor)
compose_exec_ext_editor(compose);
+ compose->modified = FALSE;
compose_set_title(compose);
return compose;
}
compose_quote_fmt(compose, compose->replyinfo,
prefs_common.quotefmt,
- qmark, body);
+ qmark, body, FALSE);
}
if (procmime_msginfo_is_encrypted(compose->replyinfo)) {
compose_force_encryption(compose, account, FALSE);
if (prefs_common.auto_exteditor)
compose_exec_ext_editor(compose);
+ compose->modified = FALSE;
compose_set_title(compose);
return compose;
}
textview = GTK_TEXT_VIEW(compose->text);
textbuf = gtk_text_view_get_buffer(textview);
compose_create_tags(textview, compose);
-
+
+ undo_block(compose->undostruct);
if (as_attach) {
gchar *msgfile;
compose_quote_fmt(compose, full_msginfo,
prefs_common.fw_quotefmt,
- qmark, body);
+ qmark, body, FALSE);
compose_attach_parts(compose, msginfo);
procmsg_msginfo_free(full_msginfo);
g_free(folderidentifier);
}
+ undo_unblock(compose->undostruct);
+
+ compose->modified = FALSE;
compose_set_title(compose);
return compose;
}
textview = GTK_TEXT_VIEW(compose->text);
textbuf = gtk_text_view_get_buffer(textview);
compose_create_tags(textview, compose);
-
+
+ undo_block(compose->undostruct);
for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
if (!is_file_exist(msgfile))
gtk_text_buffer_place_cursor(textbuf, &iter);
gtk_widget_grab_focus(compose->header_last->entry);
-
+ undo_unblock(compose->undostruct);
+ compose->modified = FALSE;
compose_set_title(compose);
return compose;
}
if (prefs_common.auto_exteditor)
compose_exec_ext_editor(compose);
+ compose->modified = FALSE;
compose_set_title(compose);
}
msginfo->subject);
gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
- compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
+ compose_quote_fmt(compose, msginfo, "%M", NULL, NULL, FALSE);
gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
compose_colorize_signature(compose);
gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
+ compose->modified = FALSE;
compose_set_title(compose);
return compose;
}
static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
const gchar *fmt, const gchar *qmark,
- const gchar *body)
+ const gchar *body, gboolean rewrap)
{
static MsgInfo dummyinfo;
gchar *quote_str = NULL;
gchar *buf;
- gchar *p, *lastp;
- gint len;
gboolean prev_autowrap;
const gchar *trimmed_body = body;
- gint cursor_pos = 0;
+ gint cursor_pos = -1;
GtkTextView *text = GTK_TEXT_VIEW(compose->text);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
GtkTextIter iter;
+ GtkTextMark *mark;
if (!msginfo)
msginfo = &dummyinfo;
g_signal_handlers_block_by_func(G_OBJECT(buffer),
G_CALLBACK(text_inserted),
compose);
- for (p = buf; *p != '\0'; ) {
- GtkTextMark *mark;
-
- mark = gtk_text_buffer_get_insert(buffer);
- gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
-
- lastp = strchr(p, '\n');
- len = lastp ? lastp - p + 1 : -1;
- if (g_utf8_validate(p, -1, NULL)) {
- gtk_text_buffer_insert(buffer, &iter, p, len);
- } else {
- gchar *tmpin = g_strdup(p);
- gchar *tmpout = NULL;
- tmpin[len] = '\0';
- tmpout = conv_codeset_strdup
- (tmpin, conv_get_locale_charset_str(),
- CS_INTERNAL);
- gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
- g_free(tmpin);
+ mark = gtk_text_buffer_get_insert(buffer);
+ gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
+ if (g_utf8_validate(buf, -1, NULL)) {
+ gtk_text_buffer_insert(buffer, &iter, buf, -1);
+ } else {
+ gchar *tmpout = NULL;
+ tmpout = conv_codeset_strdup
+ (buf, conv_get_locale_charset_str(),
+ CS_INTERNAL);
+ if (!tmpout || !g_utf8_validate(tmpout, -1, NULL)) {
g_free(tmpout);
+ tmpout = g_malloc(strlen(buf)*2+1);
+ conv_localetodisp(tmpout, strlen(buf)*2+1, buf);
}
-
- if (lastp)
- p = lastp + 1;
- else
- break;
+ gtk_text_buffer_insert(buffer, &iter, tmpout, -1);
+ g_free(tmpout);
}
cursor_pos = quote_fmt_get_cursor_pos();
+ compose->set_cursor_pos = cursor_pos;
+ if (cursor_pos == -1) {
+ cursor_pos = 0;
+ }
gtk_text_buffer_get_start_iter(buffer, &iter);
gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
gtk_text_buffer_place_cursor(buffer, &iter);
- compose->set_cursor_pos = cursor_pos;
compose->autowrap = prev_autowrap;
- if (compose->autowrap)
+ if (compose->autowrap && rewrap)
compose_wrap_all(compose);
g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
/* put the cursor where it should be
* either where the quote_fmt says, either before the signature */
- if (compose->set_cursor_pos <= 0)
+ if (compose->set_cursor_pos < 0)
gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
else
gtk_text_buffer_get_iter_at_offset(buffer, &iter,
compose->autowrap = FALSE;
buffer = gtk_text_view_get_buffer(text);
-
- undo_block(compose->undostruct);
-
+ undo_wrapping(compose->undostruct, TRUE);
if (par_iter) {
iter = *par_iter;
} else {
if (par_iter)
*par_iter = iter;
-
- undo_unblock(compose->undostruct);
+ undo_wrapping(compose->undostruct, FALSE);
compose->autowrap = prev_autowrap;
}
buffer = gtk_text_view_get_buffer(text);
- undo_block(compose->undostruct);
-
gtk_text_buffer_get_start_iter(buffer, &iter);
while (!gtk_text_iter_is_end(&iter))
compose_beautify_paragraph(compose, &iter, force);
- undo_unblock(compose->undostruct);
}
static void compose_set_title(Compose *compose)
if ((compose->replyinfo == NULL) && (compose->fwdinfo == NULL)) {
parsed_str = compose_quote_fmt(compose, NULL, tmpl->value,
- NULL, NULL);
+ NULL, NULL, FALSE);
} else {
if (prefs_common.quotemark && *prefs_common.quotemark)
qmark = prefs_common.quotemark;
if (compose->replyinfo != NULL)
parsed_str = compose_quote_fmt(compose, compose->replyinfo,
- tmpl->value, qmark, NULL);
+ tmpl->value, qmark, NULL, FALSE);
else if (compose->fwdinfo != NULL)
parsed_str = compose_quote_fmt(compose, compose->fwdinfo,
- tmpl->value, qmark, NULL);
+ tmpl->value, qmark, NULL, FALSE);
else
parsed_str = NULL;
}
if (parsed_str) {
cursor_pos = quote_fmt_get_cursor_pos();
+ compose->set_cursor_pos = cursor_pos;
+ if (cursor_pos == -1)
+ cursor_pos = 0;
gtk_text_buffer_get_start_iter(buffer, &iter);
gtk_text_buffer_get_iter_at_offset(buffer, &iter, cursor_pos);
gtk_text_buffer_place_cursor(buffer, &iter);
- compose->set_cursor_pos = cursor_pos;
}
if (parsed_str)
mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
gtk_text_buffer_place_cursor(buffer, iter);
- compose_quote_fmt(compose, NULL, "%Q", qmark, new_text);
+ compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE);
g_free(new_text);
g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation",
GINT_TO_POINTER(paste_as_quotation - 1));
gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
+ gtk_text_buffer_place_cursor(buffer, iter);
} else
gtk_text_buffer_insert(buffer, iter, text, len);
undostruct);
}
+void undo_wrapping(UndoMain *undostruct, gboolean wrap)
+{
+ debug_print("undo wrapping now %d\n", wrap);
+ undostruct->wrap = wrap;
+}
+
void undo_insert_text_cb(GtkTextBuffer *textbuf, GtkTextIter *iter,
gchar *new_text, gint new_text_length,
UndoMain *undostruct)
{
gchar *text_to_insert;
gint pos;
-
if (prefs_common.undolevels <= 0) return;
pos = gtk_text_iter_get_offset(iter);
-
+ if (undostruct->wrap && undostruct->undo) {
+ UndoInfo *last_undo = undostruct->undo->data;
+ if (last_undo && last_undo->action == UNDO_ACTION_INSERT
+ && last_undo->start_pos < pos && last_undo->end_pos > pos) {
+ GtkTextIter start,end;
+ last_undo->end_pos += g_utf8_strlen(new_text, -1);
+ gtk_text_buffer_get_iter_at_offset(textbuf, &start, last_undo->start_pos);
+ gtk_text_buffer_get_iter_at_offset(textbuf, &end, last_undo->end_pos);
+ g_free(last_undo->text);
+ last_undo->text = gtk_text_buffer_get_text(textbuf, &start, &end, FALSE);
+ debug_print("add:undo upd %d-%d\n", last_undo->start_pos, last_undo->end_pos);
+ return;
+ } else debug_print("add:last: %d, %d-%d (%d)\n", last_undo->action,
+ last_undo->start_pos, last_undo->end_pos, pos);
+
+ }
Xstrndup_a(text_to_insert, new_text, new_text_length, return);
+ debug_print("add:undo add %d-%ld\n", pos, pos + g_utf8_strlen(text_to_insert, -1));
undo_add(text_to_insert, pos, pos + g_utf8_strlen(text_to_insert, -1),
UNDO_ACTION_INSERT, undostruct);
}
start_pos = gtk_text_iter_get_offset(start);
end_pos = gtk_text_iter_get_offset(end);
+ if (undostruct->wrap && undostruct->undo) {
+ UndoInfo *last_undo = undostruct->undo->data;
+ if (last_undo && last_undo->action == UNDO_ACTION_INSERT
+ && last_undo->start_pos < start_pos && last_undo->end_pos > end_pos) {
+ GtkTextIter start,end;
+ last_undo->end_pos -= g_utf8_strlen(text_to_delete, -1);
+ gtk_text_buffer_get_iter_at_offset(textbuf, &start, last_undo->start_pos);
+ gtk_text_buffer_get_iter_at_offset(textbuf, &end, last_undo->end_pos);
+ g_free(last_undo->text);
+ last_undo->text = gtk_text_buffer_get_text(textbuf, &start, &end, FALSE);
+ debug_print("del:undo upd %d-%d\n", last_undo->start_pos, last_undo->end_pos);
+ return;
+ } else debug_print("del:last: %d, %d-%d (%d)\n", last_undo->action,
+ last_undo->start_pos, last_undo->end_pos, start_pos);
+
+ }
+ debug_print("del:undo add %d-%d\n", start_pos, end_pos);
undo_add(text_to_delete, start_pos, end_pos, UNDO_ACTION_DELETE,
undostruct);
g_free(text_to_delete);