[evolution] Bug 740476 - Blockquote paragraph format indents in Plain Text
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 740476 - Blockquote paragraph format indents in Plain Text
- Date: Sun, 15 Mar 2015 19:26:07 +0000 (UTC)
commit c60e7351de653dfa9ddbb8062939292a00956613
Author: Tomas Popela <tpopela redhat com>
Date: Fri Mar 13 22:15:03 2015 +0100
Bug 740476 - Blockquote paragraph format indents in Plain Text
With this change the Blockquote format will quote the current paragraph
instead of just indenting it.
e-util/e-html-editor-selection.c | 129 +++++++++++++++++++++++++++-----------
e-util/e-html-editor-view.c | 86 +++++++++++++++++++++-----
e-util/e-html-editor-view.h | 5 ++
3 files changed, 168 insertions(+), 52 deletions(-)
---
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index b8cfdb3..190762a 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -2020,11 +2020,12 @@ is_citation_node (WebKitDOMNode *node)
static gboolean
process_block_to_block (EHTMLEditorSelection *selection,
EHTMLEditorView *view,
- WebKitDOMDocument *document,
+ WebKitDOMDocument *document,
EHTMLEditorSelectionBlockFormat format,
- const gchar *value,
+ const gchar *value,
WebKitDOMNode *block,
WebKitDOMNode *end_block,
+ WebKitDOMNode *blockquote,
gboolean html_mode)
{
gboolean after_selection_end = FALSE;
@@ -2049,6 +2050,7 @@ process_block_to_block (EHTMLEditorSelection *selection,
value,
webkit_dom_node_get_first_child (block),
end_block,
+ blockquote,
html_mode);
if (finished)
@@ -2072,7 +2074,8 @@ process_block_to_block (EHTMLEditorSelection *selection,
next_block = webkit_dom_node_get_next_sibling (block);
- if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH)
+ if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH ||
+ format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE)
element = e_html_editor_selection_get_paragraph_element (
selection, document, -1, 0);
else
@@ -2122,10 +2125,15 @@ process_block_to_block (EHTMLEditorSelection *selection,
block = next_block;
- if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH && !html_mode) {
+ if (!html_mode &&
+ (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH ||
+ format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE)) {
gint citation_level, quote;
- citation_level = get_citation_level (WEBKIT_DOM_NODE (element));
+ if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE)
+ citation_level = 1;
+ else
+ citation_level = get_citation_level (WEBKIT_DOM_NODE (element));
quote = citation_level ? citation_level * 2 : 0;
if (citation_level > 0)
@@ -2133,8 +2141,14 @@ process_block_to_block (EHTMLEditorSelection *selection,
selection, element, selection->priv->word_wrap_length - quote);
}
- if (quoted)
- e_html_editor_view_quote_plain_text_element (view, element);
+ if (blockquote && format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE) {
+ webkit_dom_node_append_child (
+ blockquote, WEBKIT_DOM_NODE (element), NULL);
+ if (!html_mode)
+ e_html_editor_view_quote_plain_text_element_after_wrapping (document,
element, 1);
+ } else
+ if (!html_mode && quoted)
+ e_html_editor_view_quote_plain_text_element (view, element);
}
return after_selection_end;
@@ -2230,9 +2244,8 @@ format_change_block_to_block (EHTMLEditorSelection *selection,
{
gboolean html_mode;
WebKitDOMElement *selection_start_marker, *selection_end_marker;
- WebKitDOMNode *block, *end_block;
+ WebKitDOMNode *block, *end_block, *blockquote = NULL;
- e_html_editor_selection_save (selection);
selection_start_marker = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-start-marker", NULL);
selection_end_marker = webkit_dom_document_query_selector (
@@ -2256,16 +2269,29 @@ format_change_block_to_block (EHTMLEditorSelection *selection,
block = get_parent_block_node_from_child (
WEBKIT_DOM_NODE (selection_start_marker));
+ html_mode = e_html_editor_view_get_html_mode (view);
+
+ if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE) {
+ blockquote = WEBKIT_DOM_NODE (
+ webkit_dom_document_create_element (document, "BLOCKQUOTE", NULL));
+
+ webkit_dom_element_set_attribute (WEBKIT_DOM_ELEMENT (blockquote), "type", "cite", NULL);
+ if (!html_mode)
+ webkit_dom_element_set_attribute (
+ WEBKIT_DOM_ELEMENT (blockquote), "class", "-x-evo-plaintext-quoted", NULL);
+ webkit_dom_node_insert_before (
+ webkit_dom_node_get_parent_node (block),
+ blockquote,
+ block,
+ NULL);
+ }
+
end_block = get_parent_block_node_from_child (
WEBKIT_DOM_NODE (selection_end_marker));
- html_mode = e_html_editor_view_get_html_mode (view);
-
/* Process all blocks that are in the selection one by one */
process_block_to_block (
- selection, view, document, format, value, block, end_block, html_mode);
-
- e_html_editor_selection_restore (selection);
+ selection, view, document, format, value, block, end_block, blockquote, html_mode);
}
static void
@@ -2279,8 +2305,6 @@ format_change_block_to_list (EHTMLEditorSelection *selection,
WebKitDOMElement *selection_start_marker, *selection_end_marker, *item, *list;
WebKitDOMNode *block, *next_block;
- e_html_editor_selection_save (selection);
-
selection_start_marker = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-start-marker", NULL);
selection_end_marker = webkit_dom_document_query_selector (
@@ -2410,8 +2434,6 @@ format_change_block_to_list (EHTMLEditorSelection *selection,
}
merge_lists_if_possible (WEBKIT_DOM_NODE (list));
-
- e_html_editor_selection_restore (selection);
}
static void
@@ -2426,8 +2448,6 @@ format_change_list_to_list (EHTMLEditorSelection *selection,
WebKitDOMElement *selection_start_marker, *selection_end_marker;
WebKitDOMNode *prev_list, *current_list, *next_list;
- e_html_editor_selection_save (selection);
-
selection_start_marker = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-start-marker", NULL);
selection_end_marker = webkit_dom_document_query_selector (
@@ -2456,7 +2476,7 @@ format_change_list_to_list (EHTMLEditorSelection *selection,
if (!prev_list || !next_list || indented) {
format_change_list_from_list (selection, document, format, html_mode);
- goto out;
+ return;
}
if (webkit_dom_node_is_same_node (prev_list, next_list)) {
@@ -2470,7 +2490,7 @@ format_change_list_to_list (EHTMLEditorSelection *selection,
WEBKIT_DOM_NODE (selection_end_marker))));
if (!prev_list || !next_list) {
format_change_list_from_list (selection, document, format, html_mode);
- goto out;
+ return;
}
}
@@ -2492,11 +2512,9 @@ format_change_list_to_list (EHTMLEditorSelection *selection,
}
if (done)
- goto out;
+ return;
format_change_list_from_list (selection, document, format, html_mode);
-out:
- e_html_editor_selection_restore (selection);
}
static void
@@ -2509,8 +2527,6 @@ format_change_list_to_block (EHTMLEditorSelection *selection,
WebKitDOMElement *selection_start, *element, *selection_end;
WebKitDOMNode *source_list, *next_item, *item, *source_list_clone;
- e_html_editor_selection_save (selection);
-
selection_start = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-start-marker", NULL);
selection_end = webkit_dom_document_query_selector (
@@ -2536,6 +2552,8 @@ format_change_list_to_block (EHTMLEditorSelection *selection,
tmp = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (next_item));
if (!after_end) {
+ WebKitDOMNode *node;
+
if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_PARAGRAPH)
element = e_html_editor_selection_get_paragraph_element (
selection, document, -1, 0);
@@ -2545,12 +2563,9 @@ format_change_list_to_block (EHTMLEditorSelection *selection,
after_end = webkit_dom_node_contains (next_item, WEBKIT_DOM_NODE (selection_end));
- while (webkit_dom_node_get_first_child (next_item)) {
- WebKitDOMNode *node = webkit_dom_node_get_first_child (next_item);
-
+ while ((node = webkit_dom_node_get_first_child (next_item)))
webkit_dom_node_append_child (
WEBKIT_DOM_NODE (element), node, NULL);
- }
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (source_list),
@@ -2571,8 +2586,6 @@ format_change_list_to_block (EHTMLEditorSelection *selection,
remove_node_if_empty (source_list_clone);
remove_node_if_empty (source_list);
-
- e_html_editor_selection_restore (selection);
}
/**
@@ -2668,9 +2681,14 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
return;
}
+ e_html_editor_selection_save (selection);
+
if (!e_html_editor_view_is_undo_redo_in_progress (view)) {
ev = g_new0 (EHTMLEditorViewHistoryEvent, 1);
- ev->type = HISTORY_BLOCK_FORMAT;
+ if (format != E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE)
+ ev->type = HISTORY_BLOCK_FORMAT;
+ else
+ ev->type = HISTORY_BLOCKQUOTE;
e_html_editor_selection_get_selection_coordinates (
selection,
@@ -2678,8 +2696,38 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
&ev->before.start.y,
&ev->before.end.x,
&ev->before.end.y);
- ev->data.style.from = current_format;
- ev->data.style.to = format;
+
+ if (format != E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE) {
+ ev->data.style.from = current_format;
+ ev->data.style.to = format;
+ } else {
+ WebKitDOMDocumentFragment *fragment;
+ WebKitDOMElement *element;
+ WebKitDOMNode *block;
+
+ fragment = webkit_dom_range_clone_contents (range, NULL);
+
+ element = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+ block = get_parent_block_node_from_child (WEBKIT_DOM_NODE (element));
+ webkit_dom_node_replace_child (
+ WEBKIT_DOM_NODE (fragment),
+ webkit_dom_node_clone_node (block, TRUE),
+ webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (fragment)),
+ NULL);
+
+ if (!webkit_dom_range_get_collapsed (range, NULL)) {
+ element = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-end-marker");
+ block = get_parent_block_node_from_child (WEBKIT_DOM_NODE (element));
+ webkit_dom_node_replace_child (
+ WEBKIT_DOM_NODE (fragment),
+ webkit_dom_node_clone_node (block, TRUE),
+ webkit_dom_node_get_last_child (WEBKIT_DOM_NODE (fragment)),
+ NULL);
+ }
+ ev->data.fragment = fragment;
+ }
}
if (from_list && to_list)
@@ -2688,12 +2736,19 @@ e_html_editor_selection_set_block_format (EHTMLEditorSelection *selection,
if (!from_list && !to_list)
format_change_block_to_block (selection, format, view, value, document);
- if (from_list && !to_list)
+ if (from_list && !to_list) {
format_change_list_to_block (selection, format, value, document);
+ if (format == E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE) {
+ e_html_editor_selection_restore (selection);
+ format_change_block_to_block (selection, format, view, value, document);
+ }
+ }
if (!from_list && to_list)
format_change_block_to_list (selection, format, view, document);
+ e_html_editor_selection_restore (selection);
+
e_html_editor_view_force_spell_check_for_current_paragraph (view);
/* When changing the format we need to re-set the alignment */
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 601e9cf..b974a5f 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -266,7 +266,8 @@ print_history_event (EHTMLEditorViewHistoryEvent *event)
case HISTORY_SMILEY:
case HISTORY_IMAGE:
case HISTORY_CITATION_SPLIT:
- print_fragment_inner_html (event->data.fragment);
+ case HISTORY_BLOCKQUOTE:
+ print_node_inner_html (WEBKIT_DOM_NODE (event->data.fragment));
break;
case HISTORY_ALIGNMENT:
case HISTORY_BLOCK_FORMAT:
@@ -796,10 +797,10 @@ get_quotation_for_level (gint quote_level)
return g_string_free (output, FALSE);
}
-static void
-quote_plain_text_element_after_wrapping (WebKitDOMDocument *document,
- WebKitDOMElement *element,
- gint quote_level)
+void
+e_html_editor_view_quote_plain_text_element_after_wrapping (WebKitDOMDocument *document,
+ WebKitDOMElement *element,
+ gint quote_level)
{
WebKitDOMNodeList *list;
WebKitDOMNode *quoted_node;
@@ -1064,7 +1065,7 @@ insert_new_line_into_citation (EHTMLEditorView *view,
remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (node));
node = WEBKIT_DOM_NODE (e_html_editor_selection_wrap_paragraph_length (
selection, WEBKIT_DOM_ELEMENT (node), length));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (node), citation_level);
}
@@ -2664,7 +2665,7 @@ body_input_event_cb (WebKitDOMElement *element,
block = e_html_editor_selection_wrap_paragraph_length (
selection, block, length);
webkit_dom_node_normalize (WEBKIT_DOM_NODE (block));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (block), citation_level);
selection_start_marker = webkit_dom_document_query_selector (
document, "span#-x-evo-selection-start-marker", NULL);
@@ -2871,7 +2872,7 @@ body_keyup_event_cb (WebKitDOMElement *element,
selection, block, length);
webkit_dom_node_normalize (WEBKIT_DOM_NODE (block));
}
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, block, level);
}
}
@@ -3206,6 +3207,7 @@ free_history_event_content (EHTMLEditorViewHistoryEvent *event)
case HISTORY_IMAGE:
case HISTORY_SMILEY:
case HISTORY_REMOVE_LINK:
+ case HISTORY_BLOCKQUOTE:
if (event->data.fragment != NULL)
g_object_unref (event->data.fragment);
break;
@@ -3623,7 +3625,7 @@ change_quoted_block_to_normal (EHTMLEditorView *view)
block = e_html_editor_selection_wrap_paragraph_length (
selection, block, length);
webkit_dom_node_normalize (WEBKIT_DOM_NODE (block));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, block, citation_level - 1);
}
@@ -5977,7 +5979,7 @@ quote_plain_text_elements_after_wrapping_in_document (WebKitDOMDocument *documen
child = webkit_dom_node_list_item (list, ii);
citation_level = get_citation_level (child, TRUE);
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (child), citation_level);
g_object_unref (child);
}
@@ -6443,7 +6445,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
e_html_editor_selection_wrap_paragraph_length (
selection, WEBKIT_DOM_ELEMENT (parent), length));
webkit_dom_node_normalize (parent);
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (parent), citation_level);
goto delete;
@@ -6509,7 +6511,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)))) {
child = WEBKIT_DOM_NODE (e_html_editor_selection_wrap_paragraph_length (
selection, WEBKIT_DOM_ELEMENT (child), length));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (child), citation_level);
webkit_dom_node_insert_before (
webkit_dom_node_get_parent_node (last_paragraph),
@@ -6523,7 +6525,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
last_paragraph = WEBKIT_DOM_NODE (
e_html_editor_selection_wrap_paragraph_length (
selection, WEBKIT_DOM_ELEMENT (last_paragraph), length));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (last_paragraph), citation_level);
remove_quoting_from_element (WEBKIT_DOM_ELEMENT (parent));
@@ -6533,7 +6535,7 @@ html_editor_view_insert_converted_html_into_selection (EHTMLEditorView *view,
WEBKIT_DOM_NODE (selection_start_marker));
parent = WEBKIT_DOM_NODE (e_html_editor_selection_wrap_paragraph_length (
selection, WEBKIT_DOM_ELEMENT (parent), length));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (parent), citation_level);
/* If the pasted text begun or ended with a new line we have to
@@ -10827,6 +10829,8 @@ undo_redo_hrule_dialog (EHTMLEditorView *view,
if (undo)
restore_selection_to_history_event_state (view, event->before);
+ else
+ e_html_editor_selection_restore (selection);
}
static void
@@ -10878,6 +10882,8 @@ undo_redo_image_dialog (EHTMLEditorView *view,
if (undo)
restore_selection_to_history_event_state (view, event->before);
+ else
+ e_html_editor_selection_restore (selection);
}
static void
@@ -10941,6 +10947,8 @@ undo_redo_table_dialog (EHTMLEditorView *view,
if (undo)
restore_selection_to_history_event_state (view, event->before);
+ else
+ e_html_editor_selection_restore (selection);
}
static void
@@ -11346,7 +11354,7 @@ undo_redo_citation_split (EHTMLEditorView *view,
/* We need to re-wrap and re-quote the block. */
last_child = WEBKIT_DOM_NODE (e_html_editor_selection_wrap_paragraph_length (
view->priv->selection, WEBKIT_DOM_ELEMENT (last_child), length));
- quote_plain_text_element_after_wrapping (
+ e_html_editor_view_quote_plain_text_element_after_wrapping (
document, WEBKIT_DOM_ELEMENT (last_child), citation_level);
remove_node (child);
@@ -11370,6 +11378,48 @@ undo_redo_citation_split (EHTMLEditorView *view,
}
}
+static void
+undo_redo_blockquote (EHTMLEditorView *view,
+ EHTMLEditorViewHistoryEvent *event,
+ gboolean undo)
+{
+ EHTMLEditorSelection *selection;
+ WebKitDOMDocument *document;
+ WebKitDOMElement *element;
+
+ selection = e_html_editor_view_get_selection (view);
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
+
+ if (undo)
+ restore_selection_to_history_event_state (view, event->after);
+
+ e_html_editor_selection_save (selection);
+ element = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker");
+
+ if (undo) {
+ WebKitDOMNode *node;
+ WebKitDOMElement *parent;
+
+ parent = get_parent_block_element (WEBKIT_DOM_NODE (element));
+ node = webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent));
+
+ webkit_dom_node_replace_child (
+ webkit_dom_node_get_parent_node (node),
+ WEBKIT_DOM_NODE (event->data.fragment),
+ node,
+ NULL);
+ } else {
+ e_html_editor_selection_set_block_format (
+ selection, E_HTML_EDITOR_SELECTION_BLOCK_FORMAT_BLOCKQUOTE);
+ }
+
+ if (undo)
+ restore_selection_to_history_event_state (view, event->before);
+ else
+ e_html_editor_selection_restore (selection);
+}
+
void
e_html_editor_view_redo (EHTMLEditorView *view)
{
@@ -11443,6 +11493,9 @@ e_html_editor_view_redo (EHTMLEditorView *view)
case HISTORY_REPLACE_ALL:
undo_redo_replace_all (view, event, FALSE);
break;
+ case HISTORY_BLOCKQUOTE:
+ undo_redo_blockquote (view, event, FALSE);
+ break;
default:
return;
}
@@ -11543,6 +11596,9 @@ e_html_editor_view_undo (EHTMLEditorView *view)
case HISTORY_REPLACE_ALL:
undo_redo_replace_all (view, event, TRUE);
break;
+ case HISTORY_BLOCKQUOTE:
+ undo_redo_blockquote (view, event, TRUE);
+ break;
default:
return;
}
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index a61fd08..2eae05c 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -78,6 +78,7 @@ struct _EHTMLEditorViewClass {
enum EHTMLEditorViewHistoryEventType {
HISTORY_ALIGNMENT,
HISTORY_BLOCK_FORMAT,
+ HISTORY_BLOCKQUOTE,
HISTORY_BOLD,
HISTORY_CELL_DIALOG,
HISTORY_DELETE, /* BackSpace, Delete, with and without selection */
@@ -233,6 +234,10 @@ void e_html_editor_view_force_spell_check_for_current_paragraph
(EHTMLEditorView *view);
void e_html_editor_view_force_spell_check
(EHTMLEditorView *view);
+void e_html_editor_view_quote_plain_text_element_after_wrapping
+ (WebKitDOMDocument *document,
+ WebKitDOMElement *element,
+ gint quote_level);
void e_html_editor_view_add_inline_image_from_mime_part
(EHTMLEditorView *view,
CamelMimePart *part);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]