[evolution/wip/webkit2] Bug 756218 - Current selection could be lost during autosave
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Bug 756218 - Current selection could be lost during autosave
- Date: Wed, 2 Mar 2016 13:13:40 +0000 (UTC)
commit a2b30a5cc74af45c288e01d58f012af762ec90fa
Author: Tomas Popela <tpopela redhat com>
Date: Wed Mar 2 13:14:16 2016 +0100
Bug 756218 - Current selection could be lost during autosave
composer/e-msg-composer.c | 8 ++++-
e-util/e-html-editor-view.c | 31 ++++++++++++++++++++
e-util/e-html-editor-view.h | 2 +
.../composer/e-html-editor-web-extension.c | 19 ++++++++++++
4 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index c669df0..7a337ef 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1233,6 +1233,7 @@ composer_build_message (EMsgComposer *composer,
}
if (flags & COMPOSER_FLAG_SAVE_DRAFT) {
+ gboolean selection_saved;
gchar *text;
EHTMLEditor *editor;
EHTMLEditorView *view;
@@ -1251,7 +1252,9 @@ composer_build_message (EMsgComposer *composer,
data = g_byte_array_new ();
e_html_editor_view_embed_styles (view);
- e_html_editor_view_save_selection (view);
+ selection_saved = e_html_editor_view_is_selection_saved (view);
+ if (!selection_saved)
+ e_html_editor_view_save_selection (view);
text = e_html_editor_view_get_text_html_for_drafts (view);
@@ -1259,6 +1262,9 @@ composer_build_message (EMsgComposer *composer,
e_html_editor_view_restore_selection (view);
e_html_editor_view_force_spell_check (view);
+ if (selection_saved)
+ e_html_editor_view_save_selection (view);
+
g_byte_array_append (data, (guint8 *) text, strlen (text));
g_free (text);
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 05bdf2f..2289004 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -3479,6 +3479,37 @@ e_html_editor_view_save_selection (EHTMLEditorView *view)
{
e_html_editor_view_call_simple_extension_function (view, "DOMSaveSelection");
}
+
+gboolean
+e_html_editor_view_is_selection_saved (EHTMLEditorView *view)
+{
+ GVariant *result;
+ gboolean selection_saved = FALSE;
+
+ g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), FALSE);
+
+ if (!view->priv->web_extension)
+ return FALSE;
+
+ result = g_dbus_proxy_call_sync (
+ view->priv->web_extension,
+ "DOMIsSelectionSaved",
+ g_variant_new (
+ "(t)",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+
+ if (result) {
+ g_variant_get (result, "(b)", &selection_saved);
+ g_variant_unref (result);
+ }
+
+ return selection_saved;
+}
+
/* FIXME WK2
Finish also changes from commit 59e3bb0 Bug 747510 - Add composer option "Inherit theme colors in HTML
mode"
static void
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index a4e4a18..4b21c99 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -215,6 +215,8 @@ void e_html_editor_view_restore_selection
(EHTMLEditorView *view);
void e_html_editor_view_save_selection
(EHTMLEditorView *view);
+gboolean e_html_editor_view_is_selection_saved
+ (EHTMLEditorView *view);
void e_html_editor_view_move_selection_on_point
(EHTMLEditorView *view,
gint x,
diff --git a/web-extensions/composer/e-html-editor-web-extension.c
b/web-extensions/composer/e-html-editor-web-extension.c
index 6a47af6..35f06e8 100644
--- a/web-extensions/composer/e-html-editor-web-extension.c
+++ b/web-extensions/composer/e-html-editor-web-extension.c
@@ -472,6 +472,10 @@ static const char introspection_xml[] =
" <method name='DOMRestoreSelection'>"
" <arg type='t' name='page_id' direction='in'/>"
" </method>"
+" <method name='DOMIsSelectionSaved'>"
+" <arg type='t' name='page_id' direction='in'/>"
+" <arg type='b' name='selection_saved' direction='out'/>"
+" </method>"
" <method name='DOMQuoteAndInsertTextIntoSelection'>"
" <arg type='t' name='page_id' direction='in'/>"
" <arg type='s' name='text' direction='in'/>"
@@ -1744,6 +1748,21 @@ handle_method_call (GDBusConnection *connection,
document = webkit_web_page_get_dom_document (web_page);
dom_selection_restore (document);
g_dbus_method_invocation_return_value (invocation, NULL);
+ } else if (g_strcmp0 (method_name, "DOMIsSelectionSaved") == 0) {
+ gboolean selection_saved = FALSE;
+ g_variant_get (parameters, "(t)", &page_id);
+
+ web_page = get_webkit_web_page_or_return_dbus_error (
+ invocation, web_extension, page_id);
+ if (!web_page)
+ goto error;
+
+ document = webkit_web_page_get_dom_document (web_page);
+ selection_saved = webkit_dom_document_get_element_by_id (
+ document, "-x-evo-selection-start-marker") != NULL;
+
+ g_dbus_method_invocation_return_value (
+ invocation, g_variant_new ("(b)", selection_saved));
} else if (g_strcmp0 (method_name, "DOMTurnSpellCheckOff") == 0) {
g_variant_get (parameters, "(t)", &page_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]