From aa595e3dc228059196551dbda166cbf69ea296a0 Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Sun, 5 Aug 2007 08:29:05 +0000 Subject: [PATCH] 2007-08-05 [colin] 2.10.0cvs91 * src/compose.c * src/compose.h reverting buggy patch for now --- ChangeLog | 6 ++ PATCHSETS | 1 + configure.ac | 2 +- src/compose.c | 252 +++++++++++++++++--------------------------------- src/compose.h | 6 -- 5 files changed, 95 insertions(+), 172 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a7e0423a..e8512ffe7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-08-05 [colin] 2.10.0cvs91 + + * src/compose.c + * src/compose.h + reverting buggy patch for now + 2007-08-05 [colin] 2.10.0cvs90 * src/folder.c diff --git a/PATCHSETS b/PATCHSETS index a8b4eb714..f7cb40cd9 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -2744,3 +2744,4 @@ ( cvs diff -u -r 1.79.2.58 -r 1.79.2.59 src/mh.c; ) > 2.10.0cvs88.patchset ( cvs diff -u -r 1.1.2.46 -r 1.1.2.47 src/prefs_summaries.c; cvs diff -u -r 1.15.2.51 -r 1.15.2.52 src/summary_search.c; ) > 2.10.0cvs89.patchset ( cvs diff -u -r 1.213.2.152 -r 1.213.2.153 src/folder.c; ) > 2.10.0cvs90.patchset +( cvs diff -u -r 1.382.2.398 -r 1.382.2.399 src/compose.c; cvs diff -u -r 1.50.2.39 -r 1.50.2.40 src/compose.h; ) > 2.10.0cvs91.patchset diff --git a/configure.ac b/configure.ac index 7b1a5e9c0..66087ee42 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=10 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=90 +EXTRA_VERSION=91 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/compose.c b/src/compose.c index 072730928..df545b209 100644 --- a/src/compose.c +++ b/src/compose.c @@ -273,7 +273,7 @@ static gboolean compose_attach_append (Compose *compose, static void compose_attach_parts (Compose *compose, MsgInfo *msginfo); -static gboolean compose_beautify_paragraph (Compose *compose, +static void compose_beautify_paragraph (Compose *compose, GtkTextIter *par_iter, gboolean force); static void compose_wrap_all (Compose *compose); @@ -901,26 +901,26 @@ static void compose_create_tags(GtkTextView *text, Compose *compose) } if (prefs_common.enable_color && prefs_common.enable_bgcolor) { - compose->quote0_tag = gtk_text_buffer_create_tag(buffer, "quote0", + gtk_text_buffer_create_tag(buffer, "quote0", "foreground-gdk", "e_color1, "paragraph-background-gdk", "e_bgcolor1, NULL); - compose->quote1_tag = gtk_text_buffer_create_tag(buffer, "quote1", + gtk_text_buffer_create_tag(buffer, "quote1", "foreground-gdk", "e_color2, "paragraph-background-gdk", "e_bgcolor2, NULL); - compose->quote2_tag = gtk_text_buffer_create_tag(buffer, "quote2", + gtk_text_buffer_create_tag(buffer, "quote2", "foreground-gdk", "e_color3, "paragraph-background-gdk", "e_bgcolor3, NULL); } else { - compose->quote0_tag = gtk_text_buffer_create_tag(buffer, "quote0", + gtk_text_buffer_create_tag(buffer, "quote0", "foreground-gdk", "e_color1, NULL); - compose->quote1_tag = gtk_text_buffer_create_tag(buffer, "quote1", + gtk_text_buffer_create_tag(buffer, "quote1", "foreground-gdk", "e_color2, NULL); - compose->quote2_tag = gtk_text_buffer_create_tag(buffer, "quote2", + gtk_text_buffer_create_tag(buffer, "quote2", "foreground-gdk", "e_color3, NULL); } @@ -928,8 +928,7 @@ static void compose_create_tags(GtkTextView *text, Compose *compose) gtk_text_buffer_create_tag(buffer, "signature", "foreground-gdk", &signature_color, NULL); - - compose->uri_tag = gtk_text_buffer_create_tag(buffer, "link", + gtk_text_buffer_create_tag(buffer, "link", "foreground-gdk", &uri_color, NULL); compose->no_wrap_tag = gtk_text_buffer_create_tag(buffer, "no_wrap", NULL); @@ -1814,36 +1813,6 @@ static void compose_colorize_signature(Compose *compose) } } -#define BLOCK_WRAP() { \ - prev_autowrap = compose->autowrap; \ - buffer = gtk_text_view_get_buffer( \ - GTK_TEXT_VIEW(compose->text)); \ - compose->autowrap = FALSE; \ - \ - g_signal_handlers_block_by_func(G_OBJECT(buffer), \ - G_CALLBACK(compose_changed_cb), \ - compose); \ - g_signal_handlers_block_by_func(G_OBJECT(buffer), \ - G_CALLBACK(text_inserted), \ - compose); \ -} -#define UNBLOCK_WRAP() { \ - compose->autowrap = prev_autowrap; \ - if (compose->autowrap) { \ - gint old = compose->draft_timeout_tag; \ - compose->draft_timeout_tag = -2; \ - compose_wrap_all(compose); \ - compose->draft_timeout_tag = old; \ - } \ - \ - g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \ - G_CALLBACK(compose_changed_cb), \ - compose); \ - g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \ - G_CALLBACK(text_inserted), \ - compose); \ -} - Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) { Compose *compose = NULL; @@ -2045,13 +2014,14 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) if (fp != NULL) { gboolean prev_autowrap = compose->autowrap; - GtkTextBuffer *buffer = textbuf; - BLOCK_WRAP(); + + compose->autowrap = FALSE; while (fgets(buf, sizeof(buf), fp) != NULL) { strcrchomp(buf); gtk_text_buffer_insert(textbuf, &iter, buf, -1); } - UNBLOCK_WRAP(); + compose_wrap_all_full(compose, FALSE); + compose->autowrap = prev_autowrap; fclose(fp); } @@ -3013,7 +2983,8 @@ static void compose_insert_sig(Compose *compose, gboolean replace) g_return_if_fail(compose->account != NULL); - BLOCK_WRAP(); + prev_autowrap = compose->autowrap; + compose->autowrap = FALSE; g_signal_handlers_block_by_func(G_OBJECT(buffer), G_CALLBACK(compose_changed_cb), @@ -3086,7 +3057,9 @@ again: G_CALLBACK(compose_changed_cb), compose); - UNBLOCK_WRAP(); + compose->autowrap = prev_autowrap; + if (compose->autowrap) + compose_wrap_all(compose); } static gchar *compose_get_signature_str(Compose *compose) @@ -3791,7 +3764,8 @@ static gboolean compose_join_next_line(Compose *compose, g_warning("alloc error scanning URIs\n"); \ } -static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force) +static gboolean automatic_break = FALSE; +static void compose_beautify_paragraph(Compose *compose, GtkTextIter *par_iter, gboolean force) { GtkTextView *text = GTK_TEXT_VIEW(compose->text); GtkTextBuffer *buffer; @@ -3805,18 +3779,6 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it gint nouri_start = -1, nouri_stop = -1; gint num_blocks = 0; gint quotelevel = -1; - gboolean modified = force; - gboolean removed = FALSE; - gboolean modified_before_remove = FALSE; - gint lines = 0; - gboolean start = TRUE; - - if (force) { - modified = TRUE; - } - if (compose->draft_timeout_tag == -2) { - modified = TRUE; - } compose->autowrap = FALSE; @@ -3830,26 +3792,24 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); } - - if (compose->draft_timeout_tag == -2) { - if (gtk_text_iter_ends_line(&iter)) { - while (gtk_text_iter_ends_line(&iter) && - gtk_text_iter_forward_line(&iter)) - ; - } else { - while (gtk_text_iter_backward_line(&iter)) { - if (gtk_text_iter_ends_line(&iter)) { - gtk_text_iter_forward_line(&iter); - break; - } + /* move to paragraph start */ + gtk_text_iter_set_line_offset(&iter, 0); + if (gtk_text_iter_ends_line(&iter)) { + while (gtk_text_iter_ends_line(&iter) && + gtk_text_iter_forward_line(&iter)) + ; + } else { + while (gtk_text_iter_backward_line(&iter)) { + if (gtk_text_iter_ends_line(&iter)) { + gtk_text_iter_forward_line(&iter); + break; } } - } else { - /* move to line start */ - gtk_text_iter_set_line_offset(&iter, 0); } + /* go until paragraph end (empty line) */ - while (start || !gtk_text_iter_ends_line(&iter)) { + + while (!gtk_text_iter_ends_line(&iter)) { gchar *scanpos = NULL; /* parse table - in order of priority */ struct table { @@ -3884,7 +3844,6 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL; gint walk_pos; - start = FALSE; if (!prev_autowrap && num_blocks == 0) { num_blocks++; g_signal_handlers_block_by_func(G_OBJECT(buffer), @@ -3926,17 +3885,15 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it prefs_common.linewrap_len, quote_len)) { GtkTextIter prev, next, cur; - + if (prev_autowrap != FALSE || force) { - compose->automatic_break = TRUE; - modified = TRUE; + automatic_break = TRUE; gtk_text_buffer_insert(buffer, &break_pos, "\n", 1); - compose->automatic_break = FALSE; + automatic_break = FALSE; } else if (quote_str && wrap_quote) { - compose->automatic_break = TRUE; - modified = TRUE; + automatic_break = TRUE; gtk_text_buffer_insert(buffer, &break_pos, "\n", 1); - compose->automatic_break = FALSE; + automatic_break = FALSE; } else goto colorize; /* remove trailing spaces */ @@ -3963,7 +3920,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it quote_str, -1); iter = break_pos; - modified |= compose_join_next_line(compose, buffer, &iter, quote_str); + compose_join_next_line(compose, buffer, &iter, quote_str); /* move iter to current line start */ gtk_text_iter_set_line_offset(&iter, 0); @@ -3971,11 +3928,10 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it g_free(quote_str); quote_str = NULL; } - continue; + continue; } else { /* move iter to next line start */ iter = break_pos; - lines++; } colorize: @@ -4035,41 +3991,14 @@ colorize: endquote = iter; switch (quotelevel) { - case 0: - if (!gtk_text_iter_has_tag(&startquote, compose->quote0_tag) || - !gtk_text_iter_has_tag(&end_of_line, compose->quote0_tag)) { - gtk_text_buffer_apply_tag_by_name( - buffer, "quote0", &startquote, &endquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote1", &startquote, &endquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote2", &startquote, &endquote); - modified = TRUE; - } + case 0: gtk_text_buffer_apply_tag_by_name( + buffer, "quote0", &startquote, &endquote); break; - case 1: - if (!gtk_text_iter_has_tag(&startquote, compose->quote1_tag) || - !gtk_text_iter_has_tag(&end_of_line, compose->quote1_tag)) { - gtk_text_buffer_apply_tag_by_name( - buffer, "quote1", &startquote, &endquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote0", &startquote, &endquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote2", &startquote, &endquote); - modified = TRUE; - } + case 1: gtk_text_buffer_apply_tag_by_name( + buffer, "quote1", &startquote, &endquote); break; - case 2: - if (!gtk_text_iter_has_tag(&startquote, compose->quote2_tag) || - !gtk_text_iter_has_tag(&end_of_line, compose->quote2_tag)) { - gtk_text_buffer_apply_tag_by_name( - buffer, "quote2", &startquote, &endquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote0", &startquote, &endquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote1", &startquote, &endquote); - modified = TRUE; - } + case 2: gtk_text_buffer_apply_tag_by_name( + buffer, "quote2", &startquote, &endquote); break; } startq_offset = -1; @@ -4078,71 +4007,39 @@ colorize: gtk_text_buffer_get_iter_at_offset( buffer, &startnoquote, noq_offset); endnoquote = iter; - - if ((gtk_text_iter_has_tag(&startnoquote, compose->quote0_tag) - && gtk_text_iter_has_tag(&end_of_line, compose->quote0_tag)) || - (gtk_text_iter_has_tag(&startnoquote, compose->quote1_tag) - && gtk_text_iter_has_tag(&end_of_line, compose->quote1_tag)) || - (gtk_text_iter_has_tag(&startnoquote, compose->quote2_tag) - && gtk_text_iter_has_tag(&end_of_line, compose->quote2_tag))) { - gtk_text_buffer_remove_tag_by_name( - buffer, "quote0", &startnoquote, &endnoquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote1", &startnoquote, &endnoquote); - gtk_text_buffer_remove_tag_by_name( - buffer, "quote2", &startnoquote, &endnoquote); - modified = TRUE; - } + gtk_text_buffer_remove_tag_by_name( + buffer, "quote0", &startnoquote, &endnoquote); + gtk_text_buffer_remove_tag_by_name( + buffer, "quote1", &startnoquote, &endnoquote); + gtk_text_buffer_remove_tag_by_name( + buffer, "quote2", &startnoquote, &endnoquote); noq_offset = -1; } - if (uri_start != nouri_start && uri_stop != nouri_stop) { + /* always */ { GtkTextIter nouri_start_iter, nouri_end_iter; gtk_text_buffer_get_iter_at_offset( buffer, &nouri_start_iter, nouri_start); gtk_text_buffer_get_iter_at_offset( buffer, &nouri_end_iter, nouri_stop); - if (gtk_text_iter_has_tag(&nouri_start_iter, compose->uri_tag) && - gtk_text_iter_has_tag(&nouri_end_iter, compose->uri_tag)) { - gtk_text_buffer_remove_tag_by_name( - buffer, "link", &nouri_start_iter, &nouri_end_iter); - modified_before_remove = modified; - modified = TRUE; - removed = TRUE; - } + gtk_text_buffer_remove_tag_by_name( + buffer, "link", &nouri_start_iter, &nouri_end_iter); } if (uri_start > 0 && uri_stop > 0) { - GtkTextIter uri_start_iter, uri_end_iter, back; + GtkTextIter uri_start_iter, uri_end_iter; gtk_text_buffer_get_iter_at_offset( buffer, &uri_start_iter, uri_start); gtk_text_buffer_get_iter_at_offset( buffer, &uri_end_iter, uri_stop); - back = uri_end_iter; - gtk_text_iter_backward_char(&back); - if (!gtk_text_iter_has_tag(&uri_start_iter, compose->uri_tag) || - !gtk_text_iter_has_tag(&back, compose->uri_tag)) { - gtk_text_buffer_apply_tag_by_name( - buffer, "link", &uri_start_iter, &uri_end_iter); - modified = TRUE; - if (removed && !modified_before_remove) { - modified = FALSE; - } - } - } - if (!modified) { - debug_print("not modified, out after %d lines\n", lines); - goto end; + gtk_text_buffer_apply_tag_by_name( + buffer, "link", &uri_start_iter, &uri_end_iter); } } - debug_print("modified, out after %d lines\n", lines); -end: if (par_iter) *par_iter = iter; undo_wrapping(compose->undostruct, FALSE); compose->autowrap = prev_autowrap; - - return modified; } void compose_action_cb(void *data) @@ -4161,13 +4058,12 @@ static void compose_wrap_all_full(Compose *compose, gboolean force) GtkTextView *text = GTK_TEXT_VIEW(compose->text); GtkTextBuffer *buffer; GtkTextIter iter; - gboolean modified = TRUE; buffer = gtk_text_view_get_buffer(text); gtk_text_buffer_get_start_iter(buffer, &iter); - while (!gtk_text_iter_is_end(&iter) && modified) - modified = compose_beautify_paragraph(compose, &iter, force); + while (!gtk_text_iter_is_end(&iter)) + compose_beautify_paragraph(compose, &iter, force); } @@ -6264,6 +6160,32 @@ static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose) static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap, GdkAtom clip, GtkTextIter *insert_place); +#define BLOCK_WRAP() { \ + prev_autowrap = compose->autowrap; \ + buffer = gtk_text_view_get_buffer( \ + GTK_TEXT_VIEW(compose->text)); \ + compose->autowrap = FALSE; \ + \ + g_signal_handlers_block_by_func(G_OBJECT(buffer), \ + G_CALLBACK(compose_changed_cb), \ + compose); \ + g_signal_handlers_block_by_func(G_OBJECT(buffer), \ + G_CALLBACK(text_inserted), \ + compose); \ +} +#define UNBLOCK_WRAP() { \ + compose->autowrap = prev_autowrap; \ + if (compose->autowrap) \ + compose_wrap_all(compose); \ + \ + g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \ + G_CALLBACK(compose_changed_cb), \ + compose); \ + g_signal_handlers_unblock_by_func(G_OBJECT(buffer), \ + G_CALLBACK(text_inserted), \ + compose); \ +} + static gboolean text_clicked(GtkWidget *text, GdkEventButton *event, Compose *compose) @@ -9709,7 +9631,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter, gtk_text_buffer_get_iter_at_mark(buffer, iter, mark); gtk_text_buffer_place_cursor(buffer, iter); } else { - if (strcmp(text, "\n") || compose->automatic_break + if (strcmp(text, "\n") || automatic_break || gtk_text_iter_starts_line(iter)) gtk_text_buffer_insert(buffer, iter, text, len); else { diff --git a/src/compose.h b/src/compose.h index 13967ae92..4e21596be 100644 --- a/src/compose.h +++ b/src/compose.h @@ -215,12 +215,6 @@ struct _Compose GtkTextTag *no_wrap_tag; GtkTextTag *no_join_tag; - GtkTextTag *quote0_tag; - GtkTextTag *quote1_tag; - GtkTextTag *quote2_tag; - GtkTextTag *uri_tag; - - gboolean automatic_break; GMutex *mutex; gchar *orig_charset; gint set_cursor_pos;