[evolution/wip/webkit2] Enable spell-checking in composer
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Enable spell-checking in composer
- Date: Wed, 9 Mar 2016 16:23:44 +0000 (UTC)
commit 4220198a0c7e58de47ef3c5e69b6eb048c8d672a
Author: Milan Crha <mcrha redhat com>
Date: Wed Mar 9 17:22:46 2016 +0100
Enable spell-checking in composer
composer/e-composer-private.c | 6 +-
e-util/e-html-editor-actions.c | 15 +--
e-util/e-html-editor-spell-check-dialog.c | 91 ++++++++++-------
e-util/e-html-editor-view.c | 86 ++++++++--------
e-util/e-html-editor.c | 64 ++++--------
e-util/e-spell-checker.c | 107 ++++++++++++++++++++
e-util/e-spell-checker.h | 8 ++
...-html-editor-spell-check-dialog-dom-functions.c | 48 ++++------
...-html-editor-spell-check-dialog-dom-functions.h | 10 ++-
.../composer/e-html-editor-view-dom-functions.c | 4 +
.../composer/e-html-editor-web-extension.c | 45 ++++++--
.../composer/e-html-editor-web-extension.h | 4 +
12 files changed, 307 insertions(+), 181 deletions(-)
---
diff --git a/composer/e-composer-private.c b/composer/e-composer-private.c
index 73f20a1..35d0e69 100644
--- a/composer/e-composer-private.c
+++ b/composer/e-composer-private.c
@@ -90,8 +90,7 @@ e_composer_private_constructed (EMsgComposer *composer)
{
EMsgComposerPrivate *priv = composer->priv;
EFocusTracker *focus_tracker;
-/* FIXME WK2
- EComposerHeader *header;*/
+ EComposerHeader *header;
EShell *shell;
EClientCache *client_cache;
EHTMLEditor *editor;
@@ -209,14 +208,13 @@ e_composer_private_constructed (EMsgComposer *composer)
priv->header_table = g_object_ref (widget);
gtk_widget_show (widget);
-/* FIXME WK2
header = e_composer_header_table_get_header (
E_COMPOSER_HEADER_TABLE (widget),
E_COMPOSER_HEADER_SUBJECT);
e_binding_bind_property (
view, "spell-checker",
header->input_widget, "spell-checker",
- G_BINDING_SYNC_CREATE);*/
+ G_BINDING_SYNC_CREATE);
/* Construct the editing toolbars. We'll have to reparent
* the embedded EHTMLEditorView a little further down. */
diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c
index b43e8c1..fb9f342 100644
--- a/e-util/e-html-editor-actions.c
+++ b/e-util/e-html-editor-actions.c
@@ -203,10 +203,8 @@ action_context_spell_add_cb (GtkAction *action,
selection = e_html_editor_view_get_selection (editor->priv->html_editor_view);
word = e_html_editor_selection_get_caret_word (selection);
- /* FIXME WK2
- if (word && *word) {
+ if (word && *word)
e_spell_checker_learn_word (spell_checker, word);
- } */
}
static void
@@ -222,10 +220,8 @@ action_context_spell_ignore_cb (GtkAction *action,
selection = e_html_editor_view_get_selection (editor->priv->html_editor_view);
word = e_html_editor_selection_get_caret_word (selection);
- /* FIXME WK2
- if (word && *word) {
+ if (word && *word)
e_spell_checker_ignore_word (spell_checker, word);
- }*/
}
static void
@@ -418,8 +414,7 @@ action_language_cb (GtkToggleAction *toggle_action,
language_code = gtk_action_get_name (GTK_ACTION (toggle_action));
active = gtk_toggle_action_get_active (toggle_action);
- /* FIXME WK2
- e_spell_checker_set_language_active (checker, language_code, active);*/
+ e_spell_checker_set_language_active (checker, language_code, active);
/* Update "Add Word To" context menu item visibility. */
action_name = g_strdup_printf ("context-spell-add-%s", language_code);
@@ -1518,7 +1513,6 @@ static GtkActionEntry spell_context_entries[] = {
static void
editor_actions_setup_languages_menu (EHTMLEditor *editor)
{
-#if 0
ESpellChecker *checker;
EHTMLEditorView *view;
GtkUIManager *manager;
@@ -1578,13 +1572,11 @@ editor_actions_setup_languages_menu (EHTMLEditor *editor)
}
g_list_free (list);
-#endif
}
static void
editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
{
-#if 0
ESpellChecker *checker;
GtkUIManager *manager;
GtkActionGroup *action_group;
@@ -1664,7 +1656,6 @@ editor_actions_setup_spell_check_menu (EHTMLEditor *editor)
}
g_list_free (available_dicts);
-#endif
}
void
diff --git a/e-util/e-html-editor-spell-check-dialog.c b/e-util/e-html-editor-spell-check-dialog.c
index 491401e..5d21b2d 100644
--- a/e-util/e-html-editor-spell-check-dialog.c
+++ b/e-util/e-html-editor-spell-check-dialog.c
@@ -79,7 +79,6 @@ webkit_find_controller_found_text_cb (WebKitFindController *find_controller,
E_HTML_EDITOR_VIEW (webkit_find_controller_get_web_view (find_controller)),
dialog->priv->replacement);
webkit_find_controller_search_next (find_controller);
-
}
static void
@@ -91,7 +90,7 @@ html_editor_spell_check_dialog_set_word (EHTMLEditorSpellCheckDialog *dialog,
GtkTreeView *tree_view;
GtkListStore *store;
gchar *markup;
- GList *list = NULL, *link;
+ GList *list, *link;
gboolean empty;
if (word == NULL)
@@ -110,9 +109,9 @@ html_editor_spell_check_dialog_set_word (EHTMLEditorSpellCheckDialog *dialog,
tree_view = GTK_TREE_VIEW (dialog->priv->tree_view);
store = GTK_LIST_STORE (gtk_tree_view_get_model (tree_view));
gtk_list_store_clear (store);
-/* FIXME WK2
+
list = e_spell_dictionary_get_suggestions (
- dialog->priv->current_dict, word, -1);*/
+ dialog->priv->current_dict, word, -1);
empty = list == NULL;
@@ -156,6 +155,7 @@ move_to_another_word (EHTMLEditorSpellCheckDialog *dialog,
EHTMLEditorView *view;
GDBusProxy *web_extension;
GVariant *result;
+ gchar **active_languages;
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
@@ -163,21 +163,28 @@ move_to_another_word (EHTMLEditorSpellCheckDialog *dialog,
if (!web_extension)
return FALSE;
+ active_languages = e_spell_checker_list_active_languages (
+ e_html_editor_view_get_spell_checker (view), NULL);
+ if (!active_languages)
+ return FALSE;
+
result = g_dbus_proxy_call_sync (
web_extension,
dom_function,
g_variant_new (
- "(ts)",
+ "(ts^as)",
webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
- dialog->priv->word),
+ dialog->priv->word ? dialog->priv->word : "",
+ active_languages),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL);
+ g_strfreev (active_languages);
+
if (result) {
const gchar *next_word;
- gsize length;
g_variant_get (result, "(&s)", &next_word);
if (next_word && *next_word) {
@@ -206,6 +213,19 @@ html_editor_spell_check_dialog_prev (EHTMLEditorSpellCheckDialog *dialog)
return move_to_another_word (dialog, "EHTMLEditorSpellCheckDialogPrev");
}
+static gboolean
+html_editor_spell_check_dialog_next_idle_cb (gpointer user_data)
+{
+ EHTMLEditorSpellCheckDialog *dialog = user_data;
+
+ g_return_val_if_fail (E_IS_HTML_EDITOR_SPELL_CHECK_DIALOG (dialog), FALSE);
+
+ html_editor_spell_check_dialog_next (dialog);
+ g_object_unref (dialog);
+
+ return FALSE;
+}
+
static void
html_editor_spell_check_dialog_replace (EHTMLEditorSpellCheckDialog *dialog)
{
@@ -227,7 +247,8 @@ html_editor_spell_check_dialog_replace (EHTMLEditorSpellCheckDialog *dialog)
e_html_editor_view_insert_html (view, replacement);
g_free (replacement);
- html_editor_spell_check_dialog_next (dialog);
+
+ g_idle_add (html_editor_spell_check_dialog_next_idle_cb, g_object_ref (dialog));
}
static void
@@ -258,7 +279,7 @@ html_editor_spell_check_dialog_replace_all (EHTMLEditorSpellCheckDialog *dialog)
WEBKIT_FIND_OPTIONS_WRAP_AROUND,
G_MAXUINT);
- html_editor_spell_check_dialog_next (dialog);
+ g_idle_add (html_editor_spell_check_dialog_next_idle_cb, g_object_ref (dialog));
}
static void
@@ -266,10 +287,9 @@ html_editor_spell_check_dialog_ignore (EHTMLEditorSpellCheckDialog *dialog)
{
if (dialog->priv->word == NULL)
return;
-/* FIXME WK2
e_spell_dictionary_ignore_word (
dialog->priv->current_dict, dialog->priv->word, -1);
-*/
+
html_editor_spell_check_dialog_next (dialog);
}
@@ -278,9 +298,8 @@ html_editor_spell_check_dialog_learn (EHTMLEditorSpellCheckDialog *dialog)
{
if (dialog->priv->word == NULL)
return;
-/* FIXME WK2
- e_spell_dictionary_learn_word (
- dialog->priv->current_dict, dialog->priv->word, -1); */
+
+ e_spell_dictionary_learn_word (dialog->priv->current_dict, dialog->priv->word, -1);
html_editor_spell_check_dialog_next (dialog);
}
@@ -370,11 +389,27 @@ static void
html_editor_spell_check_dialog_constructed (GObject *object)
{
EHTMLEditorSpellCheckDialog *dialog;
+ EHTMLEditor *editor;
+ EHTMLEditorView *view;
+ WebKitFindController *find_controller;
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_html_editor_spell_check_dialog_parent_class)->constructed (object);
dialog = E_HTML_EDITOR_SPELL_CHECK_DIALOG (object);
+
+ editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+ view = e_html_editor_get_view (editor);
+
+ find_controller = webkit_web_view_get_find_controller (WEBKIT_WEB_VIEW (view));
+
+ dialog->priv->found_text_handler_id = g_signal_connect (
+ find_controller, "found-text",
+ G_CALLBACK (webkit_find_controller_found_text_cb), dialog);
+
+ dialog->priv->find_controller = find_controller;
+ dialog->priv->replacement = NULL;
+
e_html_editor_spell_check_dialog_update_dictionaries (dialog);
}
@@ -400,14 +435,11 @@ e_html_editor_spell_check_dialog_class_init (EHTMLEditorSpellCheckDialogClass *c
static void
e_html_editor_spell_check_dialog_init (EHTMLEditorSpellCheckDialog *dialog)
{
- EHTMLEditor *editor;
- EHTMLEditorView *view;
GtkWidget *widget;
GtkGrid *main_layout;
GtkListStore *store;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
- WebKitFindController *find_controller;
dialog->priv = E_HTML_EDITOR_SPELL_CHECK_DIALOG_GET_PRIVATE (dialog);
@@ -523,19 +555,6 @@ e_html_editor_spell_check_dialog_init (EHTMLEditorSpellCheckDialog *dialog)
widget, "clicked",
G_CALLBACK (html_editor_spell_check_dialog_learn), dialog);
- editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
- view = e_html_editor_get_view (editor);
-
- find_controller =
- webkit_web_view_get_find_controller (WEBKIT_WEB_VIEW (view));
-
- dialog->priv->found_text_handler_id = g_signal_connect (
- find_controller, "found-text",
- G_CALLBACK (webkit_find_controller_found_text_cb), dialog);
-
- dialog->priv->find_controller = find_controller;
- dialog->priv->replacement = NULL;
-
gtk_widget_show_all (GTK_WIDGET (main_layout));
}
@@ -558,7 +577,7 @@ e_html_editor_spell_check_dialog_update_dictionaries (EHTMLEditorSpellCheckDialo
GtkComboBox *combo_box;
GtkListStore *store = NULL;
GQueue queue = G_QUEUE_INIT;
- gchar **languages = NULL;
+ gchar **languages;
guint n_languages = 0;
guint ii;
@@ -567,7 +586,7 @@ e_html_editor_spell_check_dialog_update_dictionaries (EHTMLEditorSpellCheckDialo
editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
view = e_html_editor_get_view (editor);
spell_checker = e_html_editor_view_get_spell_checker (view);
-/* FIXME WK2
+
languages = e_spell_checker_list_active_languages (
spell_checker, &n_languages);
for (ii = 0; ii < n_languages; ii++) {
@@ -583,22 +602,20 @@ e_html_editor_spell_check_dialog_update_dictionaries (EHTMLEditorSpellCheckDialo
G_STRFUNC, languages[ii]);
}
g_strfreev (languages);
-*/
+
/* Populate a list store for the combo box. */
-#if 0 /* FIXME WK2 */
store = gtk_list_store_new (
NUM_COLUMNS,
G_TYPE_STRING, /* COLUMN_NAME */
E_TYPE_SPELL_DICTIONARY); /* COLUMN_DICTIONARY */
-#endif
+
while (!g_queue_is_empty (&queue)) {
ESpellDictionary *dictionary;
GtkTreeIter iter;
const gchar *name = NULL;
dictionary = g_queue_pop_head (&queue);
- /* FIXME WK2
- name = e_spell_dictionary_get_name (dictionary);*/
+ name = e_spell_dictionary_get_name (dictionary);
gtk_list_store_append (store, &iter);
gtk_list_store_set (
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 5c57100..a2c0225 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -97,6 +97,8 @@ struct _EHTMLEditorViewPrivate {
gulong owner_change_primary_cb_id;
gulong owner_change_clipboard_cb_id;
+
+ ESpellChecker *spell_checker;
};
enum {
@@ -649,6 +651,8 @@ html_editor_view_finalize (GObject *object)
priv->post_reload_operations = NULL;
}
+ g_clear_object (&priv->spell_checker);
+
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_html_editor_view_parent_class)->finalize (object);
}
@@ -656,26 +660,35 @@ html_editor_view_finalize (GObject *object)
static void
html_editor_view_constructed (GObject *object)
{
- e_extensible_load_extensions (E_EXTENSIBLE (object));
+ WebKitWebContext *web_context;
+ WebKitSettings *web_settings;
+ WebKitWebView *web_view;
+ EHTMLEditorView *view;
+ gchar **languages;
+
+ view = E_HTML_EDITOR_VIEW (object);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_html_editor_view_parent_class)->constructed (object);
- webkit_web_view_set_editable (WEBKIT_WEB_VIEW (object), TRUE);
+ e_extensible_load_extensions (E_EXTENSIBLE (view));
- e_html_editor_view_update_fonts (E_HTML_EDITOR_VIEW (object));
+ web_view = WEBKIT_WEB_VIEW (view);
-/* FIXME WK2
- WebKitSettings *web_settings;
+ /* Give spell check languages to WebKit */
+ languages = e_spell_checker_list_active_languages (view->priv->spell_checker, NULL);
- web_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (object));
+ web_context = webkit_web_view_get_context (web_view);
+ webkit_web_context_set_spell_checking_enabled (web_context, TRUE);
+ webkit_web_context_set_spell_checking_languages (web_context, (const gchar * const *) languages);
+ webkit_web_view_set_editable (web_view, TRUE);
- g_object_set (
- G_OBJECT (web_settings),
- "enable-dom-paste", TRUE,
- "enable-file-access-from-file-uris", TRUE,
- "enable-spell-checking", TRUE,
- NULL);*/
+ e_html_editor_view_update_fonts (view);
+
+ g_strfreev (languages);
+
+ web_settings = webkit_web_view_get_settings (web_view);
+ webkit_settings_set_allow_file_access_from_file_urls (web_settings, TRUE);
/* Make WebKit think we are displaying a local file, so that it
* does not block loading resources from file:// protocol */
@@ -887,6 +900,11 @@ web_extension_proxy_created_cb (GDBusProxy *proxy,
set_web_extension_boolean_property (view, "MagicSmileys", view->priv->magic_smileys);
set_web_extension_boolean_property (view, "MagicLinks", view->priv->magic_links);
set_web_extension_boolean_property (view, "InlineSpelling", view->priv->inline_spelling);
+
+ if (view->priv->inline_spelling)
+ e_html_editor_view_force_spell_check (view);
+ else
+ e_html_editor_view_turn_spell_check_off (view);
}
static void
@@ -1260,7 +1278,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
"inline-spelling",
"Inline Spelling",
"Check your spelling as you type",
- TRUE,
+ FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
@@ -1317,7 +1335,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
-#if 0 /* FIXME WK2 */
+
/**
* EHTMLEditorView:spell-checker:
*
@@ -1333,7 +1351,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
E_TYPE_SPELL_CHECKER,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
-#endif
+
/**
* EHTMLEditorView:popup-event
*
@@ -1348,6 +1366,7 @@ e_html_editor_view_class_init (EHTMLEditorViewClass *class)
e_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
/**
* EHTMLEditorView:paste-primary-clipboad
*
@@ -1701,25 +1720,15 @@ html_editor_view_copy_cut_clipboard_cb (EHTMLEditorView *view)
static void
e_html_editor_view_init (EHTMLEditorView *view)
{
- WebKitSettings *settings;
GSettings *g_settings;
GSettingsSchema *settings_schema;
-/* FIXME WK2
- ESpellChecker *checker;
- gchar **languages;
- gchar *comma_separated;
-*/
+
view->priv = E_HTML_EDITOR_VIEW_GET_PRIVATE (view);
- settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (view));
+ view->priv->spell_checker = e_spell_checker_new ();
view->priv->old_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)
g_variant_unref);
- /* Override the spell-checker, use our own */
/* FIXME WK2
- checker = e_spell_checker_new ();
- webkit_set_text_checker (G_OBJECT (checker));
- g_object_unref (checker);
-
g_signal_connect (
view, "selection-changed",
G_CALLBACK (html_editor_view_selection_changed_cb), NULL);*/
@@ -1764,19 +1773,6 @@ e_html_editor_view_init (EHTMLEditorView *view)
view->priv->aliasing_settings = g_settings;
}
- /* Give spell check languages to WebKit */
-/* FIXME WK2
- 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);
-*/
view->priv->body_input_event_removed = TRUE;
view->priv->is_editting_message = TRUE;
view->priv->is_message_from_draft = FALSE;
@@ -1856,12 +1852,12 @@ e_html_editor_view_set_inline_spelling (EHTMLEditorView *view,
view->priv->inline_spelling = inline_spelling;
set_web_extension_boolean_property (view, "InlineSpelling", view->priv->inline_spelling);
-/* FIXME WK2
+
if (inline_spelling)
e_html_editor_view_force_spell_check (view);
else
e_html_editor_view_turn_spell_check_off (view);
-*/
+
g_object_notify (G_OBJECT (view), "inline-spelling");
}
@@ -2029,9 +2025,9 @@ e_html_editor_view_set_unicode_smileys (EHTMLEditorView *view,
ESpellChecker *
e_html_editor_view_get_spell_checker (EHTMLEditorView *view)
{
-/* FIXME WK2
- return E_SPELL_CHECKER (webkit_get_text_checker ());*/
- return NULL;
+ g_return_val_if_fail (E_IS_HTML_EDITOR_VIEW (view), NULL);
+
+ return view->priv->spell_checker;
}
static gchar *
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index e19ba24..208ef12 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -109,13 +109,13 @@ action_context_spell_suggest_cb (GtkAction *action,
e_html_editor_selection_replace_caret_word (selection, word);
}
-#if 0 /* FIXME WK2 */
+
static void
html_editor_inline_spelling_suggestions (EHTMLEditor *editor)
{
EHTMLEditorView *view;
EHTMLEditorSelection *selection;
- WebKitSpellChecker *checker;
+ ESpellChecker *spell_checker;
GtkActionGroup *action_group;
GtkUIManager *manager;
gchar **suggestions;
@@ -130,13 +130,13 @@ html_editor_inline_spelling_suggestions (EHTMLEditor *editor)
view = e_html_editor_get_view (editor);
selection = e_html_editor_view_get_selection (view);
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());*/
+ spell_checker = e_html_editor_view_get_spell_checker (view);
word = e_html_editor_selection_get_caret_word (selection);
if (word == NULL || *word == '\0')
return;
- suggestions = webkit_spell_checker_get_guesses_for_word (checker, word, NULL);
+ suggestions = e_spell_checker_get_guesses_for_word (spell_checker, word);
path = "/context-menu/context-spell-suggest/";
manager = e_html_editor_get_ui_manager (editor);
@@ -207,7 +207,7 @@ html_editor_inline_spelling_suggestions (EHTMLEditor *editor)
g_free (word);
g_strfreev (suggestions);
}
-#endif
+
/* Helper for html_editor_update_actions() */
static void
html_editor_spell_checkers_foreach (EHTMLEditor *editor,
@@ -232,14 +232,13 @@ html_editor_spell_checkers_foreach (EHTMLEditor *editor,
word = e_html_editor_selection_get_caret_word (selection);
if (word == NULL || *word == '\0')
return;
-/* FIXME WK2
+
dictionary = e_spell_checker_ref_dictionary (
- spell_checker, language_code);*/
+ spell_checker, language_code);
if (dictionary != NULL) {
- /* FIXME WK2
list = e_spell_dictionary_get_suggestions (
dictionary, word, -1);
- g_object_unref (dictionary);*/
+ g_object_unref (dictionary);
} else {
list = NULL;
}
@@ -315,22 +314,19 @@ e_html_editor_update_spell_actions (EHTMLEditor *editor)
view = e_html_editor_get_view (editor);
checker = e_html_editor_view_get_spell_checker (view);
- count = 0;
-/* FIXME WK2
- count = e_spell_checker_count_active_languages (checker);*/
+ count = e_spell_checker_count_active_languages (checker);
gtk_action_set_visible (ACTION (CONTEXT_SPELL_ADD), count == 1);
gtk_action_set_visible (ACTION (CONTEXT_SPELL_ADD_MENU), count > 1);
gtk_action_set_visible (ACTION (CONTEXT_SPELL_IGNORE), count > 0);
- gtk_action_set_visible (ACTION (SPELL_CHECK), count > 0);
- gtk_action_set_visible (ACTION (LANGUAGE_MENU), count > 0);
+ gtk_action_set_sensitive (ACTION (SPELL_CHECK), count > 0);
+ gtk_action_set_sensitive (ACTION (LANGUAGE_MENU), e_spell_checker_count_available_dicts (checker) >
0);
}
static void
html_editor_update_actions (EHTMLEditor *editor)
{
-// WebKitSpellChecker *checker;
EHTMLEditorSelection *selection;
EHTMLEditorView *view;
GDBusProxy *web_extension;
@@ -342,7 +338,6 @@ html_editor_update_actions (EHTMLEditor *editor)
guint ii, n_languages;
gboolean visible;
guint merge_id;
- gint loc, len;
guint flags = 0;
view = e_html_editor_get_view (editor);
@@ -424,20 +419,16 @@ html_editor_update_actions (EHTMLEditor *editor)
list = g_list_delete_link (list, list);
}
-#if 0 /* FIXME WK2 */
languages = e_spell_checker_list_active_languages (
spell_checker, &n_languages);
/* Decide if we should show spell checking items. */
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
selection = e_html_editor_view_get_selection (view);
visible = FALSE;
if ((n_languages > 0) && e_html_editor_selection_has_text (selection)) {
gchar *word = e_html_editor_selection_get_caret_word (selection);
if (word && *word) {
- webkit_spell_checker_check_spelling_of_string (
- checker, word, &loc, &len);
- visible = (loc > -1);
+ visible = !e_spell_checker_check_word (spell_checker, word, -1);
} else {
visible = FALSE;
}
@@ -468,50 +459,42 @@ html_editor_update_actions (EHTMLEditor *editor)
/* Add actions and context menu content for active languages. */
for (ii = 0; ii < n_languages; ii++)
html_editor_spell_checkers_foreach (editor, languages[ii]);
-#endif
+
g_strfreev (languages);
e_html_editor_update_spell_actions (editor);
}
-#if 0 /* FIXME WK2 */
+
static void
html_editor_spell_languages_changed (EHTMLEditor *editor)
{
EHTMLEditorView *view;
ESpellChecker *spell_checker;
- WebKitSettings *settings;
- gchar *comma_separated;
+ WebKitWebContext *web_context;
gchar **languages;
view = e_html_editor_get_view (editor);
spell_checker = e_html_editor_view_get_spell_checker (view);
languages = e_spell_checker_list_active_languages (spell_checker, NULL);
- comma_separated = g_strjoinv (",", languages);
- g_strfreev (languages);
/* Set the languages for webview to highlight misspelled words */
- settings = webkit_web_view_get_settings (
- WEBKIT_WEB_VIEW (editor->priv->html_editor_view));
-
- g_object_set (
- G_OBJECT (settings),
- "spell-checking-languages", comma_separated,
- NULL);
+ web_context = webkit_web_view_get_context (WEBKIT_WEB_VIEW (view));
+ webkit_web_context_set_spell_checking_languages (web_context, (const gchar * const *) languages);
if (editor->priv->spell_check_dialog != NULL)
e_html_editor_spell_check_dialog_update_dictionaries (
E_HTML_EDITOR_SPELL_CHECK_DIALOG (
editor->priv->spell_check_dialog));
- if (*comma_separated)
- e_html_editor_view_force_spell_check (editor->priv->html_editor_view);
+ if (languages && *languages)
+ e_html_editor_view_force_spell_check (view);
else
- e_html_editor_view_turn_spell_check_off (editor->priv->html_editor_view);
+ e_html_editor_view_turn_spell_check_off (view);
- g_free (comma_separated);
+ g_strfreev (languages);
}
-#endif
+
static gboolean
html_editor_context_menu_cb (WebKitWebView *webkit_web_view,
WebKitContextMenu *context_menu,
@@ -840,8 +823,7 @@ e_html_editor_class_init (EHTMLEditorClass *class)
widget_class->parent_set = html_editor_parent_changed;
class->update_actions = html_editor_update_actions;
-/* FIXME WK2
- class->spell_languages_changed = html_editor_spell_languages_changed; */
+ class->spell_languages_changed = html_editor_spell_languages_changed;
g_object_class_install_property (
object_class,
diff --git a/e-util/e-spell-checker.c b/e-util/e-spell-checker.c
index 5b02795..dbdd895 100644
--- a/e-util/e-spell-checker.c
+++ b/e-util/e-spell-checker.c
@@ -321,6 +321,25 @@ e_spell_checker_list_available_dicts (ESpellChecker *checker)
}
/**
+ * e_spell_checker_count_available_dicts:
+ * @checker: An #ESpellChecker
+ *
+ * Returns: Count of available dictionaries.
+ **/
+guint
+e_spell_checker_count_available_dicts (ESpellChecker *checker)
+{
+ g_return_val_if_fail (E_IS_SPELL_CHECKER (checker), 0);
+
+ if (g_hash_table_size (checker->priv->dictionaries_cache) == 0) {
+ e_spell_checker_init_global_memory ();
+ g_hash_table_foreach (global_language_tags, copy_enchant_dicts, checker);
+ }
+
+ return g_hash_table_size (checker->priv->dictionaries_cache);
+}
+
+/**
* e_spell_checker_ref_dictionary:
* @checker: an #ESpellChecker
* @language_code: (allow-none): language code of a dictionary, or %NULL
@@ -451,6 +470,42 @@ e_spell_checker_set_language_active (ESpellChecker *checker,
}
/**
+ * e_spell_checker_set_active_languages:
+ * @checker: An #ESpellChecker
+ * @languages: A list of languages to have activated
+ *
+ * Activates only the languages from @languages, all others will
+ * be deactivated after this function is finished.
+ **/
+void
+e_spell_checker_set_active_languages (ESpellChecker *checker,
+ const gchar * const *languages)
+{
+ gint ii;
+
+ g_return_if_fail (E_IS_SPELL_CHECKER (checker));
+
+ g_object_freeze_notify (G_OBJECT (checker));
+
+ for (ii = 0; languages && languages[ii]; ii++) {
+ e_spell_checker_set_language_active (checker, languages[ii], TRUE);
+ }
+
+ if (ii == g_hash_table_size (checker->priv->active_dictionaries)) {
+ g_object_thaw_notify (G_OBJECT (checker));
+ return;
+ }
+
+ g_hash_table_remove_all (checker->priv->active_dictionaries);
+ for (ii = 0; languages && languages[ii]; ii++) {
+ e_spell_checker_set_language_active (checker, languages[ii], TRUE);
+ }
+
+ g_object_notify (G_OBJECT (checker), "active-languages");
+ g_object_thaw_notify (G_OBJECT (checker));
+}
+
+/**
* e_spell_checker_list_active_languages:
* @checker: an #ESpellChecker
* @n_languages: return location for the number of active languages, or %NULL
@@ -615,3 +670,55 @@ e_spell_checker_learn_word (ESpellChecker *checker,
g_list_free (list);
}
+
+/**
+ * e_spell_checker_get_guesses_for_word:
+ * @checker: an #ESpellChecker
+ * @word: word to get guesses for
+ *
+ * Returns: a NULL-terminated array of guesses for the @word. Free the returned
+ * pointer with g_strfreev() when done with it.
+ **/
+gchar **
+e_spell_checker_get_guesses_for_word (ESpellChecker *checker,
+ const gchar *word)
+{
+ GHashTable *active_dictionaries;
+ GList *list, *link;
+ gchar **guesses;
+ gint ii = 0;
+
+ g_return_val_if_fail (E_IS_SPELL_CHECKER (checker), NULL);
+ g_return_val_if_fail (word != NULL, NULL);
+
+ guesses = g_new0 (gchar *, MAX_SUGGESTIONS + 1);
+
+ active_dictionaries = checker->priv->active_dictionaries;
+ list = g_hash_table_get_keys (active_dictionaries);
+
+ for (link = list; link != NULL; link = g_list_next (link)) {
+ ESpellDictionary *dictionary;
+ GList *suggestions;
+
+ dictionary = E_SPELL_DICTIONARY (link->data);
+ suggestions = e_spell_dictionary_get_suggestions (
+ dictionary, word, -1);
+
+ while (suggestions != NULL && ii < MAX_SUGGESTIONS) {
+ guesses[ii++] = suggestions->data;
+ suggestions->data = NULL;
+
+ suggestions = g_list_delete_link (
+ suggestions, suggestions);
+ }
+
+ g_list_free_full (suggestions, (GDestroyNotify) g_free);
+
+ if (ii >= MAX_SUGGESTIONS)
+ break;
+ }
+
+ g_list_free (list);
+
+ return guesses;
+}
diff --git a/e-util/e-spell-checker.h b/e-util/e-spell-checker.h
index d986e84..690401b 100644
--- a/e-util/e-spell-checker.h
+++ b/e-util/e-spell-checker.h
@@ -66,6 +66,8 @@ void e_spell_checker_free_global_memory
ESpellChecker * e_spell_checker_new (void);
GList * e_spell_checker_list_available_dicts
(ESpellChecker *checker);
+guint e_spell_checker_count_available_dicts
+ (ESpellChecker *checker);
ESpellDictionary *
e_spell_checker_ref_dictionary (ESpellChecker *checker,
const gchar *language_code);
@@ -79,6 +81,9 @@ void e_spell_checker_set_language_active
(ESpellChecker *checker,
const gchar *language_code,
gboolean active);
+void e_spell_checker_set_active_languages
+ (ESpellChecker *checker,
+ const gchar * const *languages);
gchar ** e_spell_checker_list_active_languages
(ESpellChecker *checker,
guint *n_languages);
@@ -91,6 +96,9 @@ void e_spell_checker_learn_word (ESpellChecker *checker,
const gchar *word);
void e_spell_checker_ignore_word (ESpellChecker *checker,
const gchar *word);
+gchar ** e_spell_checker_get_guesses_for_word
+ (ESpellChecker *checker,
+ const gchar *word);
G_END_DECLS
diff --git a/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.c
b/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.c
index 5426d77..5a0005c 100644
--- a/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.c
@@ -57,7 +57,9 @@ select_next_word (WebKitDOMDOMSelection *dom_selection)
gchar *
e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
- const gchar *word)
+ EHTMLEditorWebExtension *extension,
+ const gchar *from_word,
+ const gchar * const *languages)
{
gulong start_offset = 0, end_offset = 0;
WebKitDOMDOMSelection *dom_selection;
@@ -68,7 +70,7 @@ e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
- if (!word) {
+ if (!from_word || !*from_word) {
webkit_dom_dom_selection_modify (
dom_selection, "move", "left", "documentboundary");
} else {
@@ -79,28 +81,22 @@ e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
end_offset = webkit_dom_dom_selection_get_focus_offset (dom_selection);
}
-#if 0 /* FIXME WK2 */
while (select_next_word (dom_selection)) {
WebKitDOMRange *range;
- WebKitSpellChecker *checker;
- gint loc, len;
gchar *word;
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
word = webkit_dom_range_get_text (range);
g_object_unref (range);
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
- webkit_spell_checker_check_spelling_of_string (
- checker, word, &loc, &len);
-
- /* Found misspelled word! */
- if (loc != -1)
+ if (!e_html_editor_web_extension_check_word_spelling (extension, word, languages)) {
+ /* Found misspelled word! */
return word;
+ }
g_free (word);
}
-#endif
+
/* Restore the selection to contain the last misspelled word. This is
* reached only when we reach the end of the document */
if (start && end)
@@ -109,7 +105,7 @@ e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
g_object_unref (dom_selection);
- return FALSE;
+ return NULL;
}
static gboolean
@@ -142,7 +138,9 @@ select_previous_word (WebKitDOMDOMSelection *dom_selection)
gchar *
e_html_editor_spell_check_dialog_prev (WebKitDOMDocument *document,
- const gchar *word)
+ EHTMLEditorWebExtension *extension,
+ const gchar *from_word,
+ const gchar * const *languages)
{
gulong start_offset = 0, end_offset = 0;
WebKitDOMDOMSelection *dom_selection;
@@ -153,7 +151,7 @@ e_html_editor_spell_check_dialog_prev (WebKitDOMDocument *document,
dom_selection = webkit_dom_dom_window_get_selection (dom_window);
g_object_unref (dom_window);
- if (!word) {
+ if (!from_word || !*from_word) {
webkit_dom_dom_selection_modify (
dom_selection, "move", "right", "documentboundary");
webkit_dom_dom_selection_modify (
@@ -165,36 +163,28 @@ e_html_editor_spell_check_dialog_prev (WebKitDOMDocument *document,
start_offset = webkit_dom_dom_selection_get_anchor_offset (dom_selection);
end_offset = webkit_dom_dom_selection_get_focus_offset (dom_selection);
}
-#if 0 /* FIXME WK2 */
+
while (select_previous_word (dom_selection)) {
WebKitDOMRange *range;
- WebKitSpellChecker *checker;
- gint loc, len;
gchar *word;
range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
word = webkit_dom_range_get_text (range);
g_object_unref (range);
- checker = WEBKIT_SPELL_CHECKER (webkit_get_text_checker ());
- webkit_spell_checker_check_spelling_of_string (
- checker, word, &loc, &len);
-
- /* Found misspelled word! */
- if (loc != -1) {
- html_editor_spell_check_dialog_set_word (dialog, word);
- g_free (word);
- return TRUE;
+ if (!e_html_editor_web_extension_check_word_spelling (extension, word, languages)) {
+ /* Found misspelled word! */
+ return word;
}
g_free (word);
}
-#endif
+
/* Restore the selection to contain the last misspelled word. This is
* reached only when we reach the beginning of the document */
if (start && end)
webkit_dom_dom_selection_set_base_and_extent (
dom_selection, start, start_offset, end, end_offset, NULL);
- return FALSE;
+ return NULL;
}
diff --git a/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.h
b/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.h
index 86334e7..af472ad 100644
--- a/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.h
+++ b/web-extensions/composer/e-html-editor-spell-check-dialog-dom-functions.h
@@ -21,13 +21,19 @@
#include <webkitdom/webkitdom.h>
+#include "e-html-editor-web-extension.h"
+
G_BEGIN_DECLS
gchar * e_html_editor_spell_check_dialog_prev (WebKitDOMDocument *document,
- const gchar *word);
+ EHTMLEditorWebExtension *extension,
+ const gchar *from_word,
+ const gchar * const *languages);
gchar * e_html_editor_spell_check_dialog_next (WebKitDOMDocument *document,
- const gchar *word);
+ EHTMLEditorWebExtension *extension,
+ const gchar *from_word,
+ const gchar * const *languages);
G_END_DECLS
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.c
b/web-extensions/composer/e-html-editor-view-dom-functions.c
index db3d096..78dbd91 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -137,6 +137,7 @@ perform_spell_check (WebKitDOMDOMSelection *dom_selection,
{
WebKitDOMRange *actual = start_range;
+ /* FIXME WK2: this doesn't work, the cursor is moved, but the spellcheck is not updated */
/* Go through all words to spellcheck them. To avoid this we have to wait for
* http://www.w3.org/html/wg/drafts/html/master/editing.html#dom-forcespellcheck */
/* We are moving forward word by word until we hit the text on the end. */
@@ -255,6 +256,9 @@ refresh_spell_check (WebKitDOMDocument *document,
"spellcheck",
enable_spell_check ? "true" : "false",
NULL);
+ webkit_dom_html_element_set_spellcheck (body, FALSE);
+ webkit_dom_html_element_set_spellcheck (body, enable_spell_check);
+ return;
dom_selection_save (document);
diff --git a/web-extensions/composer/e-html-editor-web-extension.c
b/web-extensions/composer/e-html-editor-web-extension.c
index cbaa2a6..f0160af 100644
--- a/web-extensions/composer/e-html-editor-web-extension.c
+++ b/web-extensions/composer/e-html-editor-web-extension.c
@@ -104,6 +104,7 @@ struct _EHTMLEditorWebExtensionPrivate {
guint node_under_mouse_click_flags;
EHTMLEditorUndoRedoManager *undo_redo_manager;
+ ESpellChecker *spell_checker;
};
static CamelDataCache *emd_global_http_cache = NULL;
@@ -363,11 +364,13 @@ static const char introspection_xml[] =
" <method name='EHTMLEditorSpellCheckDialogNext'>"
" <arg type='t' name='page_id' direction='in'/>"
" <arg type='s' name='word' direction='in'/>"
+" <arg type='as' name='languages' direction='in'/>"
" <arg type='s' name='next_word' direction='out'/>"
" </method>"
" <method name='EHTMLEditorSpellCheckDialogPrev'>"
" <arg type='t' name='page_id' direction='in'/>"
" <arg type='s' name='word' direction='in'/>"
+" <arg type='as' name='languages' direction='in'/>"
" <arg type='s' name='prev_word' direction='out'/>"
" </method>"
"<!-- ********************************************************* -->"
@@ -1406,10 +1409,11 @@ handle_method_call (GDBusConnection *connection,
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "EHTMLEditorSpellCheckDialogNext") == 0) {
- const gchar *word;
+ const gchar *from_word = NULL;
+ const gchar * const *languages = NULL;
gchar *value = NULL;
- g_variant_get (parameters, "(t&s)", &page_id, &word);
+ g_variant_get (parameters, "(t&s^as)", &page_id, &from_word, &languages);
web_page = get_webkit_web_page_or_return_dbus_error (
invocation, web_extension, page_id);
@@ -1417,7 +1421,7 @@ handle_method_call (GDBusConnection *connection,
goto error;
document = webkit_web_page_get_dom_document (web_page);
- value = e_html_editor_spell_check_dialog_next (document, word);
+ value = e_html_editor_spell_check_dialog_next (document, extension, from_word, languages);
g_dbus_method_invocation_return_value (
invocation,
@@ -1426,10 +1430,11 @@ handle_method_call (GDBusConnection *connection,
g_variant_new_take_string (
value ? value : g_strdup (""))));
} else if (g_strcmp0 (method_name, "EHTMLEditorSpellCheckDialogPrev") == 0) {
- const gchar *word;
+ const gchar *from_word = NULL;
+ const gchar * const *languages = NULL;
gchar *value = NULL;
- g_variant_get (parameters, "(t&s)", &page_id, &word);
+ g_variant_get (parameters, "(t&s^as)", &page_id, &from_word, &languages);
web_page = get_webkit_web_page_or_return_dbus_error (
invocation, web_extension, page_id);
@@ -1437,7 +1442,7 @@ handle_method_call (GDBusConnection *connection,
goto error;
document = webkit_web_page_get_dom_document (web_page);
- value = e_html_editor_spell_check_dialog_prev (document, word);
+ value = e_html_editor_spell_check_dialog_prev (document, extension, from_word, languages);
g_dbus_method_invocation_return_value (
invocation,
@@ -1779,6 +1784,7 @@ handle_method_call (GDBusConnection *connection,
if (!web_page)
goto error;
+ extension->priv->inline_spelling = FALSE;
document = webkit_web_page_get_dom_document (web_page);
dom_turn_spell_check_off (document, extension);
g_dbus_method_invocation_return_value (invocation, NULL);
@@ -1842,6 +1848,7 @@ handle_method_call (GDBusConnection *connection,
goto error;
document = webkit_web_page_get_dom_document (web_page);
+ extension->priv->inline_spelling = TRUE;
dom_force_spell_check (document, extension);
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "DOMCheckMagicLinks") == 0) {
@@ -2688,6 +2695,10 @@ handle_set_property (GDBusConnection *connection,
goto exit;
extension->priv->inline_spelling = value;
+ /*if (extension->priv->inline_spelling)
+ dom_force_spell_check (document, extension);
+ else
+ dom_turn_spell_check_off (document, extension);*/
g_variant_builder_add (builder,
"{sv}",
@@ -2974,6 +2985,7 @@ e_html_editor_web_extension_dispose (GObject *object)
}
g_clear_object (&extension->priv->wk_extension);
+ g_clear_object (&extension->priv->spell_checker);
g_hash_table_remove_all (extension->priv->inline_images);
@@ -3061,6 +3073,7 @@ e_html_editor_web_extension_init (EHTMLEditorWebExtension *extension)
(GDestroyNotify) g_free);
extension->priv->selection_changed_callbacks_blocked = FALSE;
+ extension->priv->spell_checker = e_spell_checker_new ();
}
static gpointer
@@ -3621,11 +3634,6 @@ e_html_editor_web_extension_set_inline_spelling (EHTMLEditorWebExtension *extens
return;
extension->priv->inline_spelling = value;
-/* FIXME WK2
- if (inline_spelling)
- e_html_editor_view_force_spell_check (view);
- else
- e_html_editor_view_turn_spell_check_off (view);*/
}
gboolean
@@ -3635,6 +3643,21 @@ e_html_editor_web_extension_get_inline_spelling_enabled (EHTMLEditorWebExtension
}
gboolean
+e_html_editor_web_extension_check_word_spelling (EHTMLEditorWebExtension *extension,
+ const gchar *word,
+ const gchar * const *languages)
+{
+ g_return_val_if_fail (E_IS_HTML_EDITOR_WEB_EXTENSION (extension), TRUE);
+
+ if (!word || !languages || !*languages)
+ return TRUE;
+
+ e_spell_checker_set_active_languages (extension->priv->spell_checker, languages);
+
+ return e_spell_checker_check_word (extension->priv->spell_checker, word, -1);
+}
+
+gboolean
e_html_editor_web_extension_get_body_input_event_removed (EHTMLEditorWebExtension *extension)
{
return extension->priv->body_input_event_removed;
diff --git a/web-extensions/composer/e-html-editor-web-extension.h
b/web-extensions/composer/e-html-editor-web-extension.h
index 9e4a832..31fbac1 100644
--- a/web-extensions/composer/e-html-editor-web-extension.h
+++ b/web-extensions/composer/e-html-editor-web-extension.h
@@ -172,6 +172,10 @@ void e_html_editor_web_extension_set_inline_spelling
gboolean e_html_editor_web_extension_get_inline_spelling_enabled
(EHTMLEditorWebExtension *extension);
+gboolean e_html_editor_web_extension_check_word_spelling
+ (EHTMLEditorWebExtension *extension,
+ const gchar *word,
+ const gchar * const *languages);
gboolean e_html_editor_web_extension_get_body_input_event_removed
(EHTMLEditorWebExtension *extension);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]