[evolution/wip/webkit-composer: 858/966] Bug# 725257 - [webkit-composer] Language change should redo spellchecking of the document



commit 5cd75e44b5e1d791b7e3d82b2e237bdca4fb233e
Author: Tomas Popela <tpopela redhat com>
Date:   Mon Mar 3 15:17:49 2014 +0100

    Bug# 725257 - [webkit-composer] Language change should redo spellchecking of the document
    
    Also we have to give current spell check languages to WebKit when
    creating new composer otherwise it will fallback to what
    gtk_get_default_language will return. When all languages are turned off
    we have to turn the spell checking off as well.

 composer/e-composer-private.c |    7 +++--
 e-util/e-editor-actions.c     |    4 +-
 e-util/e-editor-selection.c   |    6 ++--
 e-util/e-editor-widget.c      |   44 ++++++++++++++++++++++++++++++++++------
 e-util/e-editor-widget.h      |    4 ++-
 e-util/e-editor.c             |    5 ++++
 6 files changed, 54 insertions(+), 16 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 0864404..f56b397 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -854,7 +854,7 @@ composer_move_caret (EMsgComposer *composer)
                 * text mode (when switching to html mode, the underlined words are
                 * preserved */
                if (!html_mode)
-                       e_editor_widget_force_spellcheck (editor_widget);
+                       e_editor_widget_force_spell_check (editor_widget);
                return;
        }
 
@@ -921,7 +921,7 @@ composer_move_caret (EMsgComposer *composer)
                        e_editor_selection_restore_caret_position (editor_selection);
                        if (!html_mode)
                                e_editor_widget_quote_plain_text (editor_widget);
-                       e_editor_widget_force_spellcheck (editor_widget);
+                       e_editor_widget_force_spell_check (editor_widget);
 
                        input_start = webkit_dom_document_get_element_by_id (
                                document, "-x-evo-input-start");
@@ -967,10 +967,11 @@ composer_move_caret (EMsgComposer *composer)
                                        e_editor_widget_quote_plain_text (editor_widget);
                                        body = webkit_dom_document_get_body (document);
                                }
-                               e_editor_widget_force_spellcheck (editor_widget);
                        }
                }
 
+               e_editor_widget_force_spell_check (editor_widget);
+
                webkit_dom_range_select_node_contents (
                        new_range,
                        WEBKIT_DOM_NODE (
diff --git a/e-util/e-editor-actions.c b/e-util/e-editor-actions.c
index 7c2ca81..3c68d01 100644
--- a/e-util/e-editor-actions.c
+++ b/e-util/e-editor-actions.c
@@ -687,7 +687,7 @@ action_paste_cb (GtkAction *action,
                webkit_web_view_paste_clipboard (
                        WEBKIT_WEB_VIEW (widget));
 
-               e_editor_widget_force_spellcheck (widget);
+               e_editor_widget_force_spell_check (widget);
        }
 }
 
@@ -698,7 +698,7 @@ action_paste_quote_cb (GtkAction *action,
        e_editor_widget_paste_clipboard_quoted (
                e_editor_get_editor_widget (editor));
 
-       e_editor_widget_force_spellcheck (
+       e_editor_widget_force_spell_check (
                e_editor_get_editor_widget (editor));
 }
 
diff --git a/e-util/e-editor-selection.c b/e-util/e-editor-selection.c
index 43a9f8e..f304fb2 100644
--- a/e-util/e-editor-selection.c
+++ b/e-util/e-editor-selection.c
@@ -1771,7 +1771,7 @@ e_editor_selection_set_block_format (EEditorSelection *selection,
        }
 
        if (!has_selection)
-               e_editor_widget_force_spellcheck (editor_widget);
+               e_editor_widget_force_spell_check (editor_widget);
 
        g_object_unref (editor_widget);
 
@@ -2125,7 +2125,7 @@ e_editor_selection_indent (EEditorSelection *selection)
                e_editor_widget_exec_command (editor_widget, command, NULL);
        }
 
-       e_editor_widget_force_spellcheck (editor_widget);
+       e_editor_widget_force_spell_check (editor_widget);
 
        g_object_unref (editor_widget);
 
@@ -2294,7 +2294,7 @@ e_editor_selection_unindent (EEditorSelection *selection)
                e_editor_widget_exec_command (editor_widget, command, NULL);
        }
 
-       e_editor_widget_force_spellcheck (editor_widget);
+       e_editor_widget_force_spell_check (editor_widget);
 
        g_object_unref (editor_widget);
 
diff --git a/e-util/e-editor-widget.c b/e-util/e-editor-widget.c
index ee811e5..866dcc8 100644
--- a/e-util/e-editor-widget.c
+++ b/e-util/e-editor-widget.c
@@ -220,8 +220,9 @@ editor_widget_should_show_delete_interface_for_element (EEditorWidget *widget,
        return FALSE;
 }
 
-void
-e_editor_widget_force_spellcheck (EEditorWidget *widget)
+static void
+refresh_spell_check (EEditorWidget *widget,
+                     gboolean enable_spell_check)
 {
        EEditorSelection *selection;
        WebKitDOMDocument *document;
@@ -235,10 +236,13 @@ e_editor_widget_force_spellcheck (EEditorWidget *widget)
        window = webkit_dom_document_get_default_view (document);
        dom_selection = webkit_dom_dom_window_get_selection (window);
 
-       /* Enable spellcheck in composer */
+       /* Enable/Disable spellcheck in composer */
        body = webkit_dom_document_get_body (document);
        webkit_dom_element_set_attribute (
-               WEBKIT_DOM_ELEMENT (body), "spellcheck", "true", NULL);
+               WEBKIT_DOM_ELEMENT (body),
+               "spellcheck",
+               enable_spell_check ? "true" : "false",
+               NULL);
 
        selection = e_editor_widget_get_selection (widget);
        e_editor_selection_save_caret_position (selection);
@@ -290,6 +294,18 @@ e_editor_widget_force_spellcheck (EEditorWidget *widget)
        e_editor_selection_restore_caret_position (selection);
 }
 
+void
+e_editor_widget_turn_spell_check_off (EEditorWidget *widget)
+{
+       refresh_spell_check (widget, FALSE);
+}
+
+void
+e_editor_widget_force_spell_check (EEditorWidget *widget)
+{
+       refresh_spell_check (widget, TRUE);
+}
+
 static void
 body_input_event_cb (WebKitDOMElement *element,
                      WebKitDOMEvent *event,
@@ -2307,7 +2323,7 @@ editor_widget_process_document_from_convertor (EEditorWidget *widget,
 
        body = WEBKIT_DOM_HTML_ELEMENT (e_editor_widget_quote_plain_text (widget));
        e_editor_selection_restore_caret_position (selection);
-       e_editor_widget_force_spellcheck (widget);
+       e_editor_widget_force_spell_check (widget);
 
        /* Register on input event that is called when the content (body) is modified */
        webkit_dom_event_target_add_event_listener (
@@ -2352,7 +2368,7 @@ editor_widget_insert_converted_html_into_selection (EEditorWidget *widget,
        e_editor_widget_exec_command (
                widget, E_EDITOR_WIDGET_COMMAND_INSERT_HTML, inner_html);
 
-       e_editor_widget_force_spellcheck (widget);
+       e_editor_widget_force_spell_check (widget);
 
        g_free (inner_html);
        g_free (inner_text);
@@ -2385,6 +2401,8 @@ e_editor_widget_init (EEditorWidget *editor)
        GSettings *g_settings;
        GSettingsSchema *settings_schema;
        ESpellChecker *checker;
+       gchar **languages;
+       gchar *comma_separated;
 
        editor->priv = E_EDITOR_WIDGET_GET_PRIVATE (editor);
 
@@ -2460,6 +2478,18 @@ e_editor_widget_init (EEditorWidget *editor)
 
        e_editor_widget_update_fonts (editor);
 
+       /* Give spell check languages to WebKit */
+       languages = e_spell_checker_list_active_languages (checker, NULL);
+       comma_separated = g_strjoinv (",", languages);
+       g_strfreev (languages);
+
+       g_object_set (
+               G_OBJECT (settings),
+               "spell-checking-languages", comma_separated,
+               NULL);
+
+       g_free (comma_separated);
+
        editor->priv->convertor_insert = FALSE;
 
        editor->priv->convertor_web_view =
@@ -4167,7 +4197,7 @@ convert_when_changing_composer_mode (EEditorWidget *widget)
        if (restore)
                e_editor_selection_restore_caret_position (selection);
 
-       e_editor_widget_force_spellcheck (widget);
+       e_editor_widget_force_spell_check (widget);
 }
 
 /**
diff --git a/e-util/e-editor-widget.h b/e-util/e-editor-widget.h
index 565c5d5..b2fc783 100644
--- a/e-util/e-editor-widget.h
+++ b/e-util/e-editor-widget.h
@@ -135,7 +135,9 @@ WebKitDOMElement *
                                                (EEditorWidget *widget);
 void           e_editor_widget_dequote_plain_text
                                                (EEditorWidget *widget);
-void           e_editor_widget_force_spellcheck
+void           e_editor_widget_turn_spell_check_off
+                                               (EEditorWidget *widget);
+void           e_editor_widget_force_spell_check
                                                (EEditorWidget *widget);
 void           e_editor_widget_add_inline_image_from_mime_part
                                                (EEditorWidget *widget,
diff --git a/e-util/e-editor.c b/e-util/e-editor.c
index 1a79ba3..144297f 100644
--- a/e-util/e-editor.c
+++ b/e-util/e-editor.c
@@ -487,6 +487,11 @@ editor_spell_languages_changed (EEditor *editor)
                        E_EDITOR_SPELL_CHECK_DIALOG (
                        editor->priv->spell_check_dialog));
 
+       if (*comma_separated)
+               e_editor_widget_force_spell_check (editor->priv->editor_widget);
+       else
+               e_editor_widget_turn_spell_check_off (editor->priv->editor_widget);
+
        g_free (comma_separated);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]