static void spell_cb (GtkAction *action, ActionData *action_data) { GeditView *view; GeditDocument *doc; GeditSpellChecker *spell; GtkWidget *dlg; GtkTextIter start, end; gchar *word; gchar *data_dir; gedit_debug (DEBUG_PLUGINS); view = gedit_window_get_active_view (action_data->window); g_return_if_fail (view != NULL); doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { WindowData *data; GtkWidget *statusbar; data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), WINDOW_DATA_KEY); g_return_if_fail (data != NULL); statusbar = gedit_window_get_statusbar (action_data->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), data->message_cid, _("The document is empty.")); return; } if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end)) { /* no selection, get the whole doc */ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); } set_check_range (doc, &start, &end); word = get_next_misspelled_word (view); if (word == NULL) { WindowData *data; GtkWidget *statusbar; data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), WINDOW_DATA_KEY); g_return_if_fail (data != NULL); statusbar = gedit_window_get_statusbar (action_data->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), data->message_cid, _("No misspelled words")); return; } data_dir = gedit_plugin_get_data_dir (action_data->plugin); dlg = gedit_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (action_data->window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view); g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view); g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view); gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg), word, -1); g_free (word); gtk_widget_show (dlg); }
static void spell_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data); GeditSpellPluginPrivate *priv; GeditView *view; GeditDocument *doc; GeditSpellChecker *spell; GtkWidget *dlg; GtkTextIter start, end; gchar *word; gchar *data_dir; gedit_debug (DEBUG_PLUGINS); priv = plugin->priv; view = gedit_window_get_active_view (priv->window); g_return_if_fail (view != NULL); doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { GtkWidget *statusbar; statusbar = gedit_window_get_statusbar (priv->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), priv->message_cid, _("The document is empty.")); return; } if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end)) { /* no selection, get the whole doc */ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc), &start, &end); } set_check_range (doc, &start, &end); word = get_next_misspelled_word (view); if (word == NULL) { GtkWidget *statusbar; statusbar = gedit_window_get_statusbar (priv->window); gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar), priv->message_cid, _("No misspelled words")); return; } data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); dlg = gedit_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (priv->window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "change", G_CALLBACK (change_cb), view); g_signal_connect (dlg, "change_all", G_CALLBACK (change_all_cb), view); g_signal_connect (dlg, "add_word_to_personal", G_CALLBACK (add_word_cb), view); gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dlg), word, -1); g_free (word); gtk_widget_show (dlg); }