[evolution/wip/webkit-composer] Bug 725242: [webkit-composer] 'Insert HTML file' issues
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit-composer] Bug 725242: [webkit-composer] 'Insert HTML file' issues
- Date: Fri, 28 Feb 2014 08:18:20 +0000 (UTC)
commit a99366494bd3b3db5b3ac4d244bb85a4e5396bf7
Author: Tomas Popela <tpopela redhat com>
Date: Fri Feb 28 09:15:59 2014 +0100
Bug 725242: [webkit-composer] 'Insert HTML file' issues
If composer is in plain text mode we have to convert given html to
plain text.
e-util/e-editor-actions.c | 2 +-
e-util/e-editor-selection.c | 7 +++-
e-util/e-editor-widget.c | 97 ++++++++++++++++++++++++++++++++++++-------
e-util/e-editor-widget.h | 3 +
4 files changed, 91 insertions(+), 18 deletions(-)
---
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index d5364a9..7c2ca81 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -65,7 +65,7 @@ insert_html_file_ready_cb (GFile *file,
}
selection = e_editor_widget_get_selection (
- e_editor_get_editor_widget (editor));
+ e_editor_get_editor_widget (editor));
e_editor_selection_insert_html (selection, contents);
g_free (contents);
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 4dc10c9..eb916e2 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -3175,7 +3175,12 @@ e_editor_selection_insert_html (EEditorSelection *selection,
g_return_if_fail (editor_widget != NULL);
command = E_EDITOR_WIDGET_COMMAND_INSERT_HTML;
- e_editor_widget_exec_command (editor_widget, command, html_text);
+ if (e_editor_widget_get_html_mode (editor_widget)) {
+ e_editor_widget_exec_command (editor_widget, command, html_text);
+ } else {
+ e_editor_widget_convert_and_insert_html_to_plain_text (
+ editor_widget, html_text);
+ }
g_object_unref (editor_widget);
}
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index 541766f..975f6f4 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -78,6 +78,8 @@ struct _EEditorWidgetPrivate {
GSettings *font_settings;
GSettings *aliasing_settings;
+ gboolean convertor_insert;
+
WebKitWebView *convertor_web_view;
};
@@ -2066,27 +2068,20 @@ create_text_markers_for_citations (WebKitDOMNodeList *citations)
}
static void
-html_plain_text_convertor_load_status_changed (WebKitWebView *web_view,
- GParamSpec *pspec,
- EEditorWidget *widget)
+editor_widget_process_document_from_convertor (EEditorWidget *widget,
+ WebKitDOMDocument *document_convertor)
{
EEditorSelection *selection = e_editor_widget_get_selection (widget);
gboolean start_bottom;
gchar *inner_text, *inner_html;
gint ii;
GSettings *settings;
- WebKitLoadStatus status;
- WebKitDOMDocument *document_convertor, *document;
+ WebKitDOMDocument *document;
WebKitDOMElement *paragraph, *new_blockquote, *top_signature;
WebKitDOMElement *cite_body, *signature;
WebKitDOMHTMLElement *body, *convertor_body;
WebKitDOMNodeList *list;
- status = webkit_web_view_get_load_status (web_view);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- document_convertor = webkit_web_view_get_dom_document (web_view);
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (widget));
settings = g_settings_new ("org.gnome.evolution.mail");
@@ -2145,8 +2140,7 @@ html_plain_text_convertor_load_status_changed (WebKitWebView *web_view,
create_text_markers_for_citations (list);
/* Get innertText from convertor */
- inner_text = webkit_dom_html_element_get_inner_text (
- webkit_dom_document_get_body (document_convertor));
+ inner_text = webkit_dom_html_element_get_inner_text (convertor_body);
cite_body = webkit_dom_document_query_selector (
document_convertor, "span.-x-evo-cite-body", NULL);
@@ -2273,6 +2267,63 @@ html_plain_text_convertor_load_status_changed (WebKitWebView *web_view,
}
static void
+editor_widget_insert_converted_html_into_selection (EEditorWidget *widget,
+ WebKitDOMDocument *document_convertor)
+{
+ gchar *inner_text, *inner_html;
+ WebKitDOMDocument *document;
+ WebKitDOMElement *element;
+ WebKitDOMHTMLElement *convertor_body;
+
+ document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (widget));
+
+ convertor_body = webkit_dom_document_get_body (document_convertor);
+
+ inner_text = webkit_dom_html_element_get_inner_text (convertor_body);
+ element = webkit_dom_document_create_element (document, "div", NULL);
+ webkit_dom_html_element_set_inner_text (
+ WEBKIT_DOM_HTML_ELEMENT (element), inner_text, NULL);
+ inner_html = webkit_dom_html_element_get_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (element));
+
+ parse_html_into_paragraphs (
+ widget, document, element, inner_html, FALSE);
+
+ g_free (inner_html);
+
+ inner_html = webkit_dom_html_element_get_inner_html (
+ WEBKIT_DOM_HTML_ELEMENT (element));
+
+ e_editor_widget_exec_command (
+ widget, E_EDITOR_WIDGET_COMMAND_INSERT_HTML, inner_html);
+
+ e_editor_widget_force_spellcheck (widget);
+
+ g_free (inner_html);
+ g_free (inner_text);
+}
+
+static void
+html_plain_text_convertor_load_status_changed (WebKitWebView *web_view,
+ GParamSpec *pspec,
+ EEditorWidget *widget)
+{
+ WebKitDOMDocument *document_convertor;
+
+ if (webkit_web_view_get_load_status (web_view) != WEBKIT_LOAD_FINISHED)
+ return;
+
+ document_convertor = webkit_web_view_get_dom_document (web_view);
+
+ if (widget->priv->convertor_insert)
+ editor_widget_insert_converted_html_into_selection (
+ widget, document_convertor);
+ else
+ editor_widget_process_document_from_convertor (
+ widget, document_convertor);
+}
+
+static void
e_editor_widget_init (EEditorWidget *editor)
{
WebKitWebSettings *settings;
@@ -2354,6 +2405,8 @@ e_editor_widget_init (EEditorWidget *editor)
e_editor_widget_update_fonts (editor);
+ editor->priv->convertor_insert = FALSE;
+
editor->priv->convertor_web_view =
g_object_ref_sink (WEBKIT_WEB_VIEW (webkit_web_view_new ()));
settings = webkit_web_view_get_settings (editor->priv->convertor_web_view);
@@ -4252,9 +4305,21 @@ e_editor_widget_get_text_plain (EEditorWidget *widget)
}
static void
-convert_html_to_plain_text (EEditorWidget *widget,
- const gchar *html)
+convert_and_load_html_to_plain_text (EEditorWidget *widget,
+ const gchar *html)
{
+ widget->priv->convertor_insert = FALSE;
+
+ webkit_web_view_load_string (
+ widget->priv->convertor_web_view, html, NULL, NULL, "file://");
+}
+
+void
+e_editor_widget_convert_and_insert_html_to_plain_text (EEditorWidget *widget,
+ const gchar *html)
+{
+ widget->priv->convertor_insert = TRUE;
+
webkit_web_view_load_string (
widget->priv->convertor_web_view, html, NULL, NULL, "file://");
}
@@ -4281,9 +4346,9 @@ e_editor_widget_set_text_html (EEditorWidget *widget,
WEBKIT_WEB_VIEW (widget), text, NULL, NULL, "file://");
return;
}
- convert_html_to_plain_text (widget, text);
+ convert_and_load_html_to_plain_text (widget, text);
} else {
- convert_html_to_plain_text (widget, text);
+ convert_and_load_html_to_plain_text (widget, text);
}
} else {
webkit_web_view_load_string (
diff --git a/e-util/e-editor-widget.h b/e-util/e-editor-widget.h
index 7a53608..565c5d5 100644
--- a/e-util/e-editor-widget.h
+++ b/e-util/e-editor-widget.h
@@ -107,6 +107,9 @@ gchar * e_editor_widget_get_text_html (EEditorWidget *widget);
gchar * e_editor_widget_get_text_html_for_drafts
(EEditorWidget *widget);
gchar * e_editor_widget_get_text_plain (EEditorWidget *widget);
+void e_editor_widget_convert_and_insert_html_to_plain_text
+ (EEditorWidget *widget,
+ const gchar *html);
void e_editor_widget_set_text_html (EEditorWidget *widget,
const gchar *text);
void e_editor_widget_set_text_plain (EEditorWidget *widget,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]