[evolution/wip/webkit-composer] Fix combinations of "start_bottom" and "top_signature" composer settings
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer] Fix combinations of "start_bottom" and "top_signature" composer settings
- Date: Thu, 23 Jan 2014 13:48:04 +0000 (UTC)
commit 6362125b10c716867633b4ff656962c21eb79374
Author: Tomas Popela <tpopela redhat com>
Date: Thu Jan 23 14:26:36 2014 +0100
Fix combinations of "start_bottom" and "top_signature" composer settings
composer/e-composer-private.c | 184 +++++++++++++++++++++++------------------
composer/e-msg-composer.c | 18 ++--
e-util/e-editor-widget.c | 5 +-
3 files changed, 118 insertions(+), 89 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index a3ab824..aad1a31 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -771,10 +771,32 @@ composer_size_allocate_cb (GtkWidget *widget,
}
static void
+insert_paragraph_with_input (WebKitDOMElement *paragraph,
+ WebKitDOMElement *body)
+{
+ WebKitDOMNode *node = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
+
+ if (node) {
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (paragraph),
+ node,
+ NULL);
+ } else {
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (paragraph),
+ NULL);
+ }
+}
+
+static void
composer_move_caret (EMsgComposer *composer)
{
- WebKitDOMHTMLElement *body;
- WebKitDOMRange *new_range;
+ GSettings *settings;
+ gboolean start_bottom;
+ gboolean top_signature;
+ gboolean has_paragraphs_in_body = TRUE;
EEditor *editor;
EEditorWidget *editor_widget;
EEditorSelection *editor_selection;
@@ -782,12 +804,12 @@ composer_move_caret (EMsgComposer *composer)
WebKitDOMDOMWindow *window;
WebKitDOMDOMSelection *dom_selection;
WebKitDOMElement *input_start;
+ WebKitDOMElement *element;
+ WebKitDOMElement *signature;
+ WebKitDOMHTMLElement *body;
WebKitDOMNodeList *list;
WebKitDOMNodeList *blockquotes;
- WebKitDOMElement *element;
- GSettings *settings;
- gboolean start_bottom;
- gboolean has_paragraphs_in_body = TRUE;
+ WebKitDOMRange *new_range;
/* When there is an option composer-reply-start-bottom set we have
* to move the caret between reply and signature. */
@@ -795,6 +817,11 @@ composer_move_caret (EMsgComposer *composer)
start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
g_object_unref (settings);
+ top_signature =
+ use_top_signature (composer) &&
+ !composer->priv->is_from_message &&
+ !composer->priv->is_from_new_message;
+
editor = e_msg_composer_get_editor (composer);
editor_widget = e_editor_get_editor_widget (editor);
editor_selection = e_editor_widget_get_selection (editor_widget);
@@ -818,12 +845,19 @@ composer_move_caret (EMsgComposer *composer)
return;
}
+ /* If editing message as new don't handle with caret */
+ if (composer->priv->is_from_message) {
+ e_editor_selection_restore_caret_position (editor_selection);
+ e_editor_widget_quote_plain_text (editor_widget);
+ e_editor_widget_force_spellcheck (editor_widget);
+
+ return;
+ }
+
list = webkit_dom_document_get_elements_by_class_name (document, "-x-evo-paragraph");
+ signature = webkit_dom_document_query_selector (document, ".-x-evolution-signature", NULL);
/* Situation when wrapped paragraph is just in signature and not in message body */
if (webkit_dom_node_list_get_length (list) == 1) {
- WebKitDOMElement *signature;
-
- signature = webkit_dom_document_query_selector (document, ".-x-evolution-signature", NULL);
if (signature && webkit_dom_element_query_selector (signature, ".-x-evo-paragraph", NULL))
has_paragraphs_in_body = FALSE;
}
@@ -856,12 +890,22 @@ composer_move_caret (EMsgComposer *composer)
if (start_bottom) {
if (webkit_dom_node_list_get_length (blockquotes) != 0) {
if (!has_paragraphs_in_body) {
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- webkit_dom_node_get_next_sibling (
- webkit_dom_node_list_item (blockquotes, 0)),
- NULL);
+ if (!top_signature) {
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (element),
+ signature ?
+ webkit_dom_node_get_parent_node (
+ WEBKIT_DOM_NODE (signature)) :
+ webkit_dom_node_get_next_sibling (
+ webkit_dom_node_list_item (blockquotes, 0)),
+ NULL);
+ } else {
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (element),
+ NULL);
+ }
}
e_editor_selection_restore_caret_position (editor_selection);
@@ -874,20 +918,8 @@ composer_move_caret (EMsgComposer *composer)
webkit_dom_range_collapse (new_range, FALSE, NULL);
} else {
- if (!has_paragraphs_in_body) {
- if (webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))) {
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)),
- NULL);
- } else {
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- NULL);
- }
- }
+ if (!has_paragraphs_in_body)
+ insert_paragraph_with_input (element, body);
webkit_dom_range_select_node_contents (new_range,
WEBKIT_DOM_NODE (
@@ -902,22 +934,9 @@ composer_move_caret (EMsgComposer *composer)
} else {
/* Move caret on the beginning of message */
if (!has_paragraphs_in_body) {
- if (webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))) {
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)),
- NULL);
- } else {
- webkit_dom_node_append_child (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (element),
- NULL);
- }
+ insert_paragraph_with_input (element, body);
if (webkit_dom_node_list_get_length (blockquotes) != 0) {
- WebKitDOMElement *br = webkit_dom_document_create_element (document, "BR",
NULL);
-
if (!e_editor_widget_get_html_mode (editor_widget)) {
WebKitDOMNode *blockquote;
@@ -931,14 +950,8 @@ composer_move_caret (EMsgComposer *composer)
e_editor_selection_restore_caret_position (editor_selection);
e_editor_widget_quote_plain_text (editor_widget);
e_editor_widget_force_spellcheck (editor_widget);
+ body = webkit_dom_document_get_body (document);
}
-
- webkit_dom_node_insert_before (
- WEBKIT_DOM_NODE (body),
- WEBKIT_DOM_NODE (br),
- webkit_dom_node_get_next_sibling (
- webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body))),
- NULL);
}
}
@@ -969,9 +982,9 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
EEditorWidget *editor_widget;
WebKitDOMDocument *document;
WebKitDOMNodeList *signatures;
- WebKitDOMDOMWindow *window;
- WebKitDOMDOMSelection *dom_selection;
gulong list_length, ii;
+ GSettings *settings;
+ gboolean start_bottom;
e_mail_signature_combo_box_load_selected_finish (
combo_box, result, &contents, &length, &is_html, &error);
@@ -987,7 +1000,12 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
* Always put the signature at the bottom for that case. */
top_signature =
use_top_signature (composer) &&
- !composer->priv->is_from_message;
+ !composer->priv->is_from_message &&
+ !composer->priv->is_from_new_message;
+
+ settings = g_settings_new ("org.gnome.evolution.mail");
+ start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
+ g_object_unref (settings);
if (contents == NULL)
goto insert;
@@ -1049,9 +1067,6 @@ composer_load_signature_cb (EMailSignatureComboBox *combo_box,
if (!is_html)
g_string_append (html_buffer, "</PRE>\n");
- if (top_signature)
- g_string_append (html_buffer, "<BR>");
-
g_string_append (html_buffer, "</SPAN>");
g_free (contents);
@@ -1062,8 +1077,6 @@ insert:
editor_widget = e_editor_get_editor_widget (editor);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (editor_widget));
- window = webkit_dom_document_get_default_view (document);
- dom_selection = webkit_dom_dom_window_get_selection (window);
signatures = webkit_dom_document_get_elements_by_class_name (
document, "-x-evolution-signature");
@@ -1109,25 +1122,6 @@ insert:
g_free (id);
}
- if (top_signature) {
- WebKitDOMElement *citation;
-
- citation = webkit_dom_document_get_element_by_id (
- document, "-x-evolution-reply-citation");
- if (citation == NULL) {
- webkit_dom_dom_selection_modify (
- dom_selection, "move", "forward",
- "documentBoundary");
- } else {
- webkit_dom_dom_selection_set_base_and_extent (
- dom_selection, WEBKIT_DOM_NODE (citation), 0,
- WEBKIT_DOM_NODE (citation), 0, NULL);
- }
- } else {
- webkit_dom_dom_selection_modify (
- dom_selection, "move", "forward", "documentBoundary");
- }
-
if (html_buffer != NULL) {
if (*html_buffer->str) {
WebKitDOMElement *element;
@@ -1136,8 +1130,40 @@ insert:
body = webkit_dom_document_get_body (document);
element = webkit_dom_document_create_element (document, "DIV", NULL);
- webkit_dom_html_element_set_inner_html (WEBKIT_DOM_HTML_ELEMENT (element),
html_buffer->str, NULL);
- webkit_dom_node_append_child (WEBKIT_DOM_NODE (body), WEBKIT_DOM_NODE (element),
NULL);
+ webkit_dom_html_element_set_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (element), html_buffer->str, NULL);
+
+ if (top_signature) {
+ WebKitDOMNode *child =
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
+
+ if (start_bottom) {
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (element),
+ child,
+ NULL);
+ } else {
+ WebKitDOMElement *input_start =
+ webkit_dom_document_get_element_by_id (
+ document, "-x-evo-input-start");
+ /* When we are using signature on top the caret
+ * should be before the signature */
+ webkit_dom_node_insert_before (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (element),
+ input_start ?
+ webkit_dom_node_get_next_sibling (
+ WEBKIT_DOM_NODE (input_start)) :
+ child,
+ NULL);
+ }
+ } else {
+ webkit_dom_node_append_child (
+ WEBKIT_DOM_NODE (body),
+ WEBKIT_DOM_NODE (element),
+ NULL);
+ }
}
g_string_free (html_buffer, TRUE);
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 7429f2a..6cbdc52 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1577,7 +1577,6 @@ set_editor_text (EMsgComposer *composer,
const gchar *text,
gboolean set_signature)
{
- gchar *body = NULL;
EEditor *editor;
EEditorWidget *editor_widget;
@@ -1600,22 +1599,23 @@ set_editor_text (EMsgComposer *composer,
/* "Edit as New Message" sets "priv->is_from_message".
* Always put the signature at the bottom for that case. */
+
+ editor = e_msg_composer_get_editor (composer);
+ editor_widget = e_editor_get_editor_widget (editor);
+
if (!composer->priv->is_from_message && use_top_signature (composer)) {
+ gchar *body;
/* put marker to the top */
- body = g_strdup_printf ("<BR>" NO_SIGNATURE_TEXT "%s", text);
+ body = g_strdup_printf ("<BR>%s", text);
+ e_editor_widget_set_text_html (editor_widget, body);
+ g_free (body);
} else {
- /* no marker => to the bottom */
- body = g_strdup_printf ("%s<BR>", text);
+ e_editor_widget_set_text_html (editor_widget, text);
}
- editor = e_msg_composer_get_editor (composer);
- editor_widget = e_editor_get_editor_widget (editor);
- e_editor_widget_set_text_html (editor_widget, body);
-
if (set_signature)
e_composer_update_signature (composer);
- g_free (body);
}
/* Miscellaneous callbacks. */
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index 66893fb..b2ad57d 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -1960,7 +1960,10 @@ quote_plain_text_recursive (WebKitDOMDocument *document,
* e_editor_widget_quote_plain_text:
* @widget: an #EEditorWidget
*
- * Quote plain text in editor.
+ * Quote text inside citation blockquotes in plain text mode.
+ *
+ * As this function is cloning and replacing all citation blockquotes keep on
+ * mind that any pointers to nodes inside these blockquotes will be invalidated.
*/
void
e_editor_widget_quote_plain_text (EEditorWidget *widget)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]