static void set_auto_spell (GeditWindow *window, GeditDocument *doc, gboolean active) { GeditAutomaticSpellChecker *autospell; GeditSpellChecker *spell; spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); autospell = gedit_automatic_spell_checker_get_from_document (doc); if (active) { if (autospell == NULL) { GeditView *active_view; active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view != NULL); autospell = gedit_automatic_spell_checker_new (doc, spell); gedit_automatic_spell_checker_attach_view (autospell, active_view); gedit_automatic_spell_checker_recheck_all (autospell); } } else { if (autospell != NULL) gedit_automatic_spell_checker_free (autospell); } }
static void set_auto_spell (GeditWindow *window, GeditView *view, gboolean active) { GeditAutomaticSpellChecker *autospell; GeditSpellChecker *spell; GeditDocument *doc; doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); autospell = gedit_automatic_spell_checker_get_from_document (doc); if (active) { if (autospell == NULL) { autospell = gedit_automatic_spell_checker_new (doc, spell); gedit_automatic_spell_checker_attach_view (autospell, view); gedit_automatic_spell_checker_recheck_all (autospell); } } else { if (autospell != NULL) gedit_automatic_spell_checker_free (autospell); } }
static void on_document_saved (GeditDocument *doc, GeditSpellPlugin *plugin) { GeditAutomaticSpellChecker *autospell; GeditSpellChecker *spell; const gchar *key; /* Make sure to save the metadata here too */ autospell = gedit_automatic_spell_checker_get_from_document (doc); spell = GEDIT_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id)); if (spell != NULL) { key = gedit_spell_checker_language_to_key (gedit_spell_checker_get_language (spell)); } else { key = NULL; } gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED, autospell != NULL ? "1" : NULL, GEDIT_METADATA_ATTRIBUTE_SPELL_LANGUAGE, key, NULL); }
static void update_ui (GeditSpellPlugin *plugin) { GeditSpellPluginPrivate *priv; GeditView *view; GAction *check_spell_action; GAction *config_spell_action; GAction *auto_spell_action; gedit_debug (DEBUG_PLUGINS); priv = plugin->priv; view = gedit_window_get_active_view (priv->window); check_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window), "check-spell"); g_simple_action_set_enabled (G_SIMPLE_ACTION (check_spell_action), (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); config_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window), "config-spell"); g_simple_action_set_enabled (G_SIMPLE_ACTION (config_spell_action), (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); auto_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window), "auto-spell"); g_simple_action_set_enabled (G_SIMPLE_ACTION (auto_spell_action), (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); if (view != NULL) { GeditDocument *doc; GeditTab *tab; GeditTabState state; gboolean autospell; doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); tab = gedit_window_get_active_tab (priv->window); state = gedit_tab_get_state (tab); autospell = (doc != NULL && gedit_automatic_spell_checker_get_from_document (doc) != NULL); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == GEDIT_TAB_STATE_NORMAL) { g_action_change_state (auto_spell_action, g_variant_new_boolean (autospell)); } g_simple_action_set_enabled (G_SIMPLE_ACTION (check_spell_action), gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) > 0); } }
void gedit_automatic_spell_checker_free (GeditAutomaticSpellChecker *spell) { g_return_if_fail (spell != NULL); g_return_if_fail (gedit_automatic_spell_checker_get_from_document (spell->doc) == spell); if (automatic_spell_checker_id == 0) return; g_object_set_qdata (G_OBJECT (spell->doc), automatic_spell_checker_id, NULL); }
static void update_ui_real (GeditWindow *window, WindowData *data) { GeditDocument *doc; GeditView *view; gboolean autospell; GtkAction *action; gedit_debug (DEBUG_PLUGINS); doc = gedit_window_get_active_document (window); view = gedit_window_get_active_view (window); autospell = (doc != NULL && gedit_automatic_spell_checker_get_from_document (doc) != NULL); if (doc != NULL) { GeditTab *tab; GeditTabState state; tab = gedit_window_get_active_tab (window); state = gedit_tab_get_state (tab); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == GEDIT_TAB_STATE_NORMAL) { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, window); set_auto_spell (window, doc, autospell); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); g_signal_handlers_unblock_by_func (action, auto_spell_cb, window); } } gtk_action_group_set_sensitive (data->action_group, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); }
GeditAutomaticSpellChecker * gedit_automatic_spell_checker_new (GeditDocument *doc, GeditSpellChecker *checker) { GeditAutomaticSpellChecker *spell; GtkTextTagTable *tag_table; GtkTextIter start, end; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (checker), NULL); g_return_val_if_fail ((spell = gedit_automatic_spell_checker_get_from_document (doc)) == NULL, spell); /* attach to the widget */ spell = g_new0 (GeditAutomaticSpellChecker, 1); spell->doc = doc; spell->spell_checker = g_object_ref (checker); if (automatic_spell_checker_id == 0) { automatic_spell_checker_id = g_quark_from_string ("GeditAutomaticSpellCheckerID"); } if (suggestion_id == 0) { suggestion_id = g_quark_from_string ("GeditAutoSuggestionID"); } g_object_set_qdata_full (G_OBJECT (doc), automatic_spell_checker_id, spell, (GDestroyNotify)gedit_automatic_spell_checker_free_internal); g_signal_connect (doc, "insert-text", G_CALLBACK (insert_text_before), spell); g_signal_connect_after (doc, "insert-text", G_CALLBACK (insert_text_after), spell); g_signal_connect_after (doc, "delete-range", G_CALLBACK (delete_range_after), spell); g_signal_connect (doc, "mark-set", G_CALLBACK (mark_set), spell); g_signal_connect (doc, "highlight-updated", G_CALLBACK (highlight_updated), spell); g_signal_connect (spell->spell_checker, "add_word_to_session", G_CALLBACK (add_word_signal_cb), spell); g_signal_connect (spell->spell_checker, "add_word_to_personal", G_CALLBACK (add_word_signal_cb), spell); g_signal_connect (spell->spell_checker, "clear_session", G_CALLBACK (clear_session_cb), spell); g_signal_connect (spell->spell_checker, "set_language", G_CALLBACK (set_language_cb), spell); spell->tag_highlight = gtk_text_buffer_create_tag ( GTK_TEXT_BUFFER (doc), "gtkspell-misspelled", "underline", PANGO_UNDERLINE_ERROR, NULL); g_object_weak_ref (G_OBJECT (spell->tag_highlight), (GWeakNotify)spell_tag_destroyed, spell); tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (doc)); gtk_text_tag_set_priority (spell->tag_highlight, gtk_text_tag_table_get_size (tag_table) - 1); g_signal_connect (tag_table, "tag-added", G_CALLBACK (tag_added_or_removed), spell); g_signal_connect (tag_table, "tag-removed", G_CALLBACK (tag_added_or_removed), spell); g_signal_connect (tag_table, "tag-changed", G_CALLBACK (tag_changed), spell); /* we create the mark here, but we don't use it until text is * inserted, so we don't really care where iter points. */ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); spell->mark_insert_start = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), "gedit-automatic-spell-checker-insert-start"); if (spell->mark_insert_start == NULL) { spell->mark_insert_start = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), "gedit-automatic-spell-checker-insert-start", &start, TRUE); } else { gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), spell->mark_insert_start, &start); } spell->mark_insert_end = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), "gedit-automatic-spell-checker-insert-end"); if (spell->mark_insert_end == NULL) { spell->mark_insert_end = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), "gedit-automatic-spell-checker-insert-end", &start, TRUE); } else { gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), spell->mark_insert_end, &start); } spell->mark_click = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc), "gedit-automatic-spell-checker-click"); if (spell->mark_click == NULL) { spell->mark_click = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), "gedit-automatic-spell-checker-click", &start, TRUE); } else { gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), spell->mark_click, &start); } spell->deferred_check = FALSE; return spell; }