[gedit] spell-checker-dialog: use directly a SpellNavigator
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] spell-checker-dialog: use directly a SpellNavigator
- Date: Thu, 6 Aug 2015 12:14:09 +0000 (UTC)
commit 926d77913f7d9b134e20c8fab9f8745984455ea1
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Aug 6 13:14:11 2015 +0200
spell-checker-dialog: use directly a SpellNavigator
No need to send various signals, we can now use a SpellNavigator
directly.
plugins/spell/gedit-spell-checker-dialog.c | 519 ++++++++++++++++------------
plugins/spell/gedit-spell-checker-dialog.h | 23 +-
plugins/spell/gedit-spell-plugin.c | 106 +------
3 files changed, 306 insertions(+), 342 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-checker-dialog.c b/plugins/spell/gedit-spell-checker-dialog.c
index b89274a..c69d70e 100644
--- a/plugins/spell/gedit-spell-checker-dialog.c
+++ b/plugins/spell/gedit-spell-checker-dialog.c
@@ -21,12 +21,13 @@
#include "gedit-spell-checker-dialog.h"
#include <glib/gi18n.h>
+#include "gedit-spell-checker.h"
typedef struct _GeditSpellCheckerDialogPrivate GeditSpellCheckerDialogPrivate;
struct _GeditSpellCheckerDialogPrivate
{
- GeditSpellChecker *spell_checker;
+ GeditSpellNavigator *navigator;
gchar *misspelled_word;
@@ -44,15 +45,7 @@ struct _GeditSpellCheckerDialogPrivate
enum
{
PROP_0,
- PROP_SPELL_CHECKER,
-};
-
-enum
-{
- SIGNAL_CHANGE,
- SIGNAL_CHANGE_ALL,
- SIGNAL_GOTO_NEXT,
- LAST_SIGNAL
+ PROP_SPELL_NAVIGATOR,
};
enum
@@ -61,31 +54,216 @@ enum
N_COLUMNS
};
-static guint signals[LAST_SIGNAL] = { 0 };
-
G_DEFINE_TYPE_WITH_PRIVATE (GeditSpellCheckerDialog, gedit_spell_checker_dialog, GTK_TYPE_DIALOG)
static void
-set_spell_checker (GeditSpellCheckerDialog *dialog,
- GeditSpellChecker *checker)
+update_spell_checker (GeditSpellCheckerDialog *dialog)
{
GeditSpellCheckerDialogPrivate *priv;
+ GeditSpellChecker *checker;
GtkHeaderBar *header_bar;
const GeditSpellCheckerLanguage *lang;
priv = gedit_spell_checker_dialog_get_instance_private (dialog);
- g_return_if_fail (priv->spell_checker == NULL);
- priv->spell_checker = g_object_ref (checker);
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
+
+ g_return_if_fail (GEDIT_IS_SPELL_CHECKER (checker));
header_bar = GTK_HEADER_BAR (gtk_dialog_get_header_bar (GTK_DIALOG (dialog)));
- lang = gedit_spell_checker_get_language (priv->spell_checker);
+ lang = gedit_spell_checker_get_language (checker);
gtk_header_bar_set_subtitle (header_bar,
gedit_spell_checker_language_to_string (lang));
- g_object_notify (G_OBJECT (dialog), "spell-checker");
+ g_object_unref (checker);
+}
+
+static void
+spell_checker_notify_cb (GeditSpellNavigator *navigator,
+ GParamSpec *pspec,
+ GeditSpellCheckerDialog *dialog)
+{
+ update_spell_checker (dialog);
+}
+
+static void
+set_navigator (GeditSpellCheckerDialog *dialog,
+ GeditSpellNavigator *navigator)
+{
+ GeditSpellCheckerDialogPrivate *priv;
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ g_return_if_fail (priv->navigator == NULL);
+ priv->navigator = g_object_ref (navigator);
+
+ update_spell_checker (dialog);
+
+ g_signal_connect_object (priv->navigator,
+ "notify::spell-checker",
+ G_CALLBACK (spell_checker_notify_cb),
+ dialog,
+ 0);
+
+ g_object_notify (G_OBJECT (dialog), "spell-navigator");
+}
+
+static void
+clear_suggestions (GeditSpellCheckerDialog *dialog)
+{
+ GeditSpellCheckerDialogPrivate *priv;
+ GtkListStore *store;
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->suggestions_view));
+ gtk_list_store_clear (store);
+
+ gtk_tree_view_columns_autosize (priv->suggestions_view);
+}
+
+static void
+set_suggestions (GeditSpellCheckerDialog *dialog,
+ GSList *suggestions)
+{
+ GeditSpellCheckerDialogPrivate *priv;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+ const gchar *first_suggestion;
+ GSList *l;
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ clear_suggestions (dialog);
+
+ store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->suggestions_view));
+
+ if (suggestions == NULL)
+ {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ /* Translators: Displayed in the "Check Spelling"
+ * dialog if there are no suggestions for the current
+ * misspelled word.
+ */
+ COLUMN_SUGGESTION, _("(no suggested words)"),
+ -1);
+
+ gtk_entry_set_text (priv->word_entry, "");
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->suggestions_view), FALSE);
+ return;
+ }
+
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->suggestions_view), TRUE);
+
+ first_suggestion = suggestions->data;
+ gtk_entry_set_text (priv->word_entry, first_suggestion);
+
+ for (l = suggestions; l != NULL; l = l->next)
+ {
+ const gchar *suggestion = l->data;
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_SUGGESTION, suggestion,
+ -1);
+ }
+
+ selection = gtk_tree_view_get_selection (priv->suggestions_view);
+ gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
+ gtk_tree_selection_select_iter (selection, &iter);
+}
+
+static void
+set_misspelled_word (GeditSpellCheckerDialog *dialog,
+ const gchar *word)
+{
+ GeditSpellCheckerDialogPrivate *priv;
+ GeditSpellChecker *checker;
+ gchar *label;
+ GSList *suggestions;
+
+ g_assert (word != NULL);
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
+
+ g_return_if_fail (!gedit_spell_checker_check_word (checker, word, NULL));
+
+ g_free (priv->misspelled_word);
+ priv->misspelled_word = g_strdup (word);
+
+ label = g_strdup_printf("<b>%s</b>", word);
+ gtk_label_set_label (priv->misspelled_word_label, label);
+ g_free (label);
+
+ suggestions = gedit_spell_checker_get_suggestions (checker, priv->misspelled_word);
+
+ set_suggestions (dialog, suggestions);
+
+ g_object_unref (checker);
+ g_slist_free_full (suggestions, g_free);
+}
+
+static void
+set_completed (GeditSpellCheckerDialog *dialog)
+{
+ GeditSpellCheckerDialogPrivate *priv;
+ gchar *label;
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ label = g_strdup_printf ("<b>%s</b>", _("Completed spell checking"));
+ gtk_label_set_label (priv->misspelled_word_label, label);
+ g_free (label);
+
+ clear_suggestions (dialog);
+ gtk_entry_set_text (priv->word_entry, "");
+
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->word_entry), FALSE);
+ gtk_widget_set_sensitive (priv->check_word_button, FALSE);
+ gtk_widget_set_sensitive (priv->ignore_button, FALSE);
+ gtk_widget_set_sensitive (priv->ignore_all_button, FALSE);
+ gtk_widget_set_sensitive (priv->change_button, FALSE);
+ gtk_widget_set_sensitive (priv->change_all_button, FALSE);
+ gtk_widget_set_sensitive (priv->add_word_button, FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->suggestions_view), FALSE);
+}
+
+static void
+goto_next (GeditSpellCheckerDialog *dialog)
+{
+ GeditSpellCheckerDialogPrivate *priv;
+ gchar *word;
+ GError *error = NULL;
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ word = gedit_spell_navigator_goto_next (priv->navigator, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Spell checker dialog: %s", error->message);
+ g_error_free (error);
+ }
+
+ if (word != NULL)
+ {
+ set_misspelled_word (dialog, word);
+ g_free (word);
+ }
+ else
+ {
+ set_completed (dialog);
+ }
}
static void
@@ -100,8 +278,8 @@ gedit_spell_checker_dialog_get_property (GObject *object,
switch (prop_id)
{
- case PROP_SPELL_CHECKER:
- g_value_set_object (value, priv->spell_checker);
+ case PROP_SPELL_NAVIGATOR:
+ g_value_set_object (value, priv->navigator);
break;
default:
@@ -120,8 +298,8 @@ gedit_spell_checker_dialog_set_property (GObject *object,
switch (prop_id)
{
- case PROP_SPELL_CHECKER:
- set_spell_checker (dialog, g_value_get_object (value));
+ case PROP_SPELL_NAVIGATOR:
+ set_navigator (dialog, g_value_get_object (value));
break;
default:
@@ -137,7 +315,7 @@ gedit_spell_checker_dialog_dispose (GObject *object)
priv = gedit_spell_checker_dialog_get_instance_private (GEDIT_SPELL_CHECKER_DIALOG (object));
- g_clear_object (&priv->spell_checker);
+ g_clear_object (&priv->navigator);
G_OBJECT_CLASS (gedit_spell_checker_dialog_parent_class)->dispose (object);
}
@@ -155,6 +333,32 @@ gedit_spell_checker_dialog_finalize (GObject *object)
}
static void
+gedit_spell_checker_dialog_show (GtkWidget *widget)
+{
+ GeditSpellCheckerDialog *dialog = GEDIT_SPELL_CHECKER_DIALOG (widget);
+ GeditSpellCheckerDialogPrivate *priv;
+
+ priv = gedit_spell_checker_dialog_get_instance_private (dialog);
+
+ /* Chain-up */
+ if (GTK_WIDGET_CLASS (gedit_spell_checker_dialog_parent_class)->show != NULL)
+ {
+ GTK_WIDGET_CLASS (gedit_spell_checker_dialog_parent_class)->show (widget);
+ }
+
+ /* A typical implementation of a SpellNavigator is to select the
+ * misspelled word when goto_next() is called. Showing the dialog makes
+ * a focus change, which can unselect the buffer selection (e.g. in a
+ * GtkTextBuffer). So that's why goto_next() is called after the
+ * chain-up.
+ */
+ if (priv->misspelled_word == NULL)
+ {
+ goto_next (dialog);
+ }
+}
+
+static void
gedit_spell_checker_dialog_class_init (GeditSpellCheckerDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -165,46 +369,18 @@ gedit_spell_checker_dialog_class_init (GeditSpellCheckerDialogClass *klass)
object_class->dispose = gedit_spell_checker_dialog_dispose;
object_class->finalize = gedit_spell_checker_dialog_finalize;
+ widget_class->show = gedit_spell_checker_dialog_show;
+
g_object_class_install_property (object_class,
- PROP_SPELL_CHECKER,
- g_param_spec_object ("spell-checker",
- "Spell Checker",
+ PROP_SPELL_NAVIGATOR,
+ g_param_spec_object ("spell-navigator",
+ "Spell Navigator",
"",
- GEDIT_TYPE_SPELL_CHECKER,
+ GEDIT_TYPE_SPELL_NAVIGATOR,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
- signals[SIGNAL_CHANGE] =
- g_signal_new ("change",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditSpellCheckerDialogClass, change),
- NULL, NULL, NULL,
- G_TYPE_NONE,
- 2,
- G_TYPE_STRING,
- G_TYPE_STRING);
-
- signals[SIGNAL_CHANGE_ALL] =
- g_signal_new ("change-all",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditSpellCheckerDialogClass, change_all),
- NULL, NULL, NULL,
- G_TYPE_NONE,
- 2,
- G_TYPE_STRING,
- G_TYPE_STRING);
-
- signals[SIGNAL_GOTO_NEXT] =
- g_signal_new ("goto-next",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditSpellCheckerDialogClass, goto_next),
- NULL, NULL, NULL,
- G_TYPE_NONE, 0);
-
/* Bind class to template */
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/gedit/plugins/spell/ui/spell-checker.ui");
@@ -220,73 +396,6 @@ gedit_spell_checker_dialog_class_init (GeditSpellCheckerDialogClass *klass)
}
static void
-clear_suggestions (GeditSpellCheckerDialog *dialog)
-{
- GeditSpellCheckerDialogPrivate *priv;
- GtkListStore *store;
-
- priv = gedit_spell_checker_dialog_get_instance_private (dialog);
-
- store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->suggestions_view));
- gtk_list_store_clear (store);
-
- gtk_tree_view_columns_autosize (priv->suggestions_view);
-}
-
-static void
-set_suggestions (GeditSpellCheckerDialog *dialog,
- GSList *suggestions)
-{
- GeditSpellCheckerDialogPrivate *priv;
- GtkListStore *store;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
- const gchar *first_suggestion;
- GSList *l;
-
- priv = gedit_spell_checker_dialog_get_instance_private (dialog);
-
- clear_suggestions (dialog);
-
- store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->suggestions_view));
-
- if (suggestions == NULL)
- {
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- /* Translators: Displayed in the "Check Spelling"
- * dialog if there are no suggestions for the current
- * misspelled word.
- */
- COLUMN_SUGGESTION, _("(no suggested words)"),
- -1);
-
- gtk_entry_set_text (priv->word_entry, "");
- gtk_widget_set_sensitive (GTK_WIDGET (priv->suggestions_view), FALSE);
- return;
- }
-
- gtk_widget_set_sensitive (GTK_WIDGET (priv->suggestions_view), TRUE);
-
- first_suggestion = suggestions->data;
- gtk_entry_set_text (priv->word_entry, first_suggestion);
-
- for (l = suggestions; l != NULL; l = l->next)
- {
- const gchar *suggestion = l->data;
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_SUGGESTION, suggestion,
- -1);
- }
-
- selection = gtk_tree_view_get_selection (priv->suggestions_view);
- gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
- gtk_tree_selection_select_iter (selection, &iter);
-}
-
-static void
word_entry_changed_handler (GtkEntry *word_entry,
GeditSpellCheckerDialog *dialog)
{
@@ -332,6 +441,7 @@ check_word_button_clicked_handler (GtkButton *button,
GeditSpellCheckerDialog *dialog)
{
GeditSpellCheckerDialogPrivate *priv;
+ GeditSpellChecker *checker;
const gchar *word;
gboolean correctly_spelled;
GError *error = NULL;
@@ -340,15 +450,20 @@ check_word_button_clicked_handler (GtkButton *button,
g_return_if_fail (gtk_entry_get_text_length (priv->word_entry) > 0);
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
+
word = gtk_entry_get_text (priv->word_entry);
- correctly_spelled = gedit_spell_checker_check_word (priv->spell_checker, word, &error);
+ correctly_spelled = gedit_spell_checker_check_word (checker, word, &error);
if (error != NULL)
{
g_warning ("Spell checker dialog: %s", error->message);
g_error_free (error);
- return;
+ error = NULL;
+ goto out;
}
if (correctly_spelled)
@@ -375,12 +490,15 @@ check_word_button_clicked_handler (GtkButton *button,
{
GSList *suggestions;
- suggestions = gedit_spell_checker_get_suggestions (priv->spell_checker, word);
+ suggestions = gedit_spell_checker_get_suggestions (checker, word);
set_suggestions (dialog, suggestions);
g_slist_free_full (suggestions, g_free);
}
+
+out:
+ g_object_unref (checker);
}
static void
@@ -388,22 +506,28 @@ add_word_button_clicked_handler (GtkButton *button,
GeditSpellCheckerDialog *dialog)
{
GeditSpellCheckerDialogPrivate *priv;
+ GeditSpellChecker *checker;
priv = gedit_spell_checker_dialog_get_instance_private (dialog);
g_return_if_fail (priv->misspelled_word != NULL);
- gedit_spell_checker_add_word_to_personal (priv->spell_checker,
- priv->misspelled_word);
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_GOTO_NEXT], 0);
+ gedit_spell_checker_add_word_to_personal (checker, priv->misspelled_word);
+
+ goto_next (dialog);
+
+ g_object_unref (checker);
}
static void
ignore_button_clicked_handler (GtkButton *button,
GeditSpellCheckerDialog *dialog)
{
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_GOTO_NEXT], 0);
+ goto_next (dialog);
}
static void
@@ -411,15 +535,21 @@ ignore_all_button_clicked_handler (GtkButton *button,
GeditSpellCheckerDialog *dialog)
{
GeditSpellCheckerDialogPrivate *priv;
+ GeditSpellChecker *checker;
priv = gedit_spell_checker_dialog_get_instance_private (dialog);
g_return_if_fail (priv->misspelled_word != NULL);
- gedit_spell_checker_add_word_to_session (priv->spell_checker,
- priv->misspelled_word);
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
+
+ gedit_spell_checker_add_word_to_session (checker, priv->misspelled_word);
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_GOTO_NEXT], 0);
+ goto_next (dialog);
+
+ g_object_unref (checker);
}
static void
@@ -427,27 +557,31 @@ change_button_clicked_handler (GtkButton *button,
GeditSpellCheckerDialog *dialog)
{
GeditSpellCheckerDialogPrivate *priv;
- gchar *word;
- gchar *change;
+ GeditSpellChecker *checker;
+ gchar *change_to;
priv = gedit_spell_checker_dialog_get_instance_private (dialog);
g_return_if_fail (priv->misspelled_word != NULL);
- change = g_strdup (gtk_entry_get_text (priv->word_entry));
- g_return_if_fail (change != NULL);
- g_return_if_fail (*change != '\0');
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
- gedit_spell_checker_set_correction (priv->spell_checker,
+ change_to = g_strdup (gtk_entry_get_text (priv->word_entry));
+ g_return_if_fail (change_to != NULL);
+ g_return_if_fail (change_to[0] != '\0');
+
+ gedit_spell_checker_set_correction (checker,
priv->misspelled_word,
- change);
+ change_to);
+
+ gedit_spell_navigator_change (priv->navigator, priv->misspelled_word, change_to);
+ g_free (change_to);
- word = g_strdup (priv->misspelled_word);
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_CHANGE], 0, word, change);
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_GOTO_NEXT], 0);
+ goto_next (dialog);
- g_free (word);
- g_free (change);
+ g_object_unref (checker);
}
/* double click on one of the suggestions is like clicking on "change" */
@@ -469,27 +603,31 @@ change_all_button_clicked_handler (GtkButton *button,
GeditSpellCheckerDialog *dialog)
{
GeditSpellCheckerDialogPrivate *priv;
- gchar *word;
- gchar *change;
+ GeditSpellChecker *checker;
+ gchar *change_to;
priv = gedit_spell_checker_dialog_get_instance_private (dialog);
g_return_if_fail (priv->misspelled_word != NULL);
- change = g_strdup (gtk_entry_get_text (priv->word_entry));
- g_return_if_fail (change != NULL);
- g_return_if_fail (*change != '\0');
+ g_object_get (priv->navigator,
+ "spell-checker", &checker,
+ NULL);
- gedit_spell_checker_set_correction (priv->spell_checker,
+ change_to = g_strdup (gtk_entry_get_text (priv->word_entry));
+ g_return_if_fail (change_to != NULL);
+ g_return_if_fail (change_to[0] != '\0');
+
+ gedit_spell_checker_set_correction (checker,
priv->misspelled_word,
- change);
+ change_to);
+
+ gedit_spell_navigator_change_all (priv->navigator, priv->misspelled_word, change_to);
+ g_free (change_to);
- word = g_strdup (priv->misspelled_word);
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_CHANGE_ALL], 0, word, change);
- g_signal_emit (G_OBJECT (dialog), signals[SIGNAL_GOTO_NEXT], 0);
+ goto_next (dialog);
- g_free (word);
- g_free (change);
+ g_object_unref (checker);
}
static void
@@ -575,74 +713,17 @@ gedit_spell_checker_dialog_init (GeditSpellCheckerDialog *dialog)
}
GtkWidget *
-gedit_spell_checker_dialog_new (GtkWindow *parent,
- GeditSpellChecker *checker)
+gedit_spell_checker_dialog_new (GtkWindow *parent,
+ GeditSpellNavigator *navigator)
{
g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
- g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (checker), NULL);
+ g_return_val_if_fail (GEDIT_IS_SPELL_NAVIGATOR (navigator), NULL);
return g_object_new (GEDIT_TYPE_SPELL_CHECKER_DIALOG,
"transient-for", parent,
- "spell-checker", checker,
"use-header-bar", TRUE,
+ "spell-navigator", navigator,
NULL);
}
-void
-gedit_spell_checker_dialog_set_misspelled_word (GeditSpellCheckerDialog *dialog,
- const gchar *word)
-{
- GeditSpellCheckerDialogPrivate *priv;
- gchar *label;
- GSList *suggestions;
-
- g_return_if_fail (GEDIT_IS_SPELL_CHECKER_DIALOG (dialog));
- g_return_if_fail (word != NULL);
-
- priv = gedit_spell_checker_dialog_get_instance_private (dialog);
-
- g_return_if_fail (!gedit_spell_checker_check_word (priv->spell_checker, word, NULL));
-
- g_free (priv->misspelled_word);
- priv->misspelled_word = g_strdup (word);
-
- label = g_strdup_printf("<b>%s</b>", word);
- gtk_label_set_label (priv->misspelled_word_label, label);
- g_free (label);
-
- suggestions = gedit_spell_checker_get_suggestions (priv->spell_checker,
- priv->misspelled_word);
-
- set_suggestions (dialog, suggestions);
-
- g_slist_free_full (suggestions, g_free);
-}
-
-void
-gedit_spell_checker_dialog_set_completed (GeditSpellCheckerDialog *dialog)
-{
- GeditSpellCheckerDialogPrivate *priv;
- gchar *label;
-
- g_return_if_fail (GEDIT_IS_SPELL_CHECKER_DIALOG (dialog));
-
- priv = gedit_spell_checker_dialog_get_instance_private (dialog);
-
- label = g_strdup_printf ("<b>%s</b>", _("Completed spell checking"));
- gtk_label_set_label (priv->misspelled_word_label, label);
- g_free (label);
-
- clear_suggestions (dialog);
- gtk_entry_set_text (priv->word_entry, "");
-
- gtk_widget_set_sensitive (GTK_WIDGET (priv->word_entry), FALSE);
- gtk_widget_set_sensitive (priv->check_word_button, FALSE);
- gtk_widget_set_sensitive (priv->ignore_button, FALSE);
- gtk_widget_set_sensitive (priv->ignore_all_button, FALSE);
- gtk_widget_set_sensitive (priv->change_button, FALSE);
- gtk_widget_set_sensitive (priv->change_all_button, FALSE);
- gtk_widget_set_sensitive (priv->add_word_button, FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET (priv->suggestions_view), FALSE);
-}
-
/* ex:set ts=8 noet: */
diff --git a/plugins/spell/gedit-spell-checker-dialog.h b/plugins/spell/gedit-spell-checker-dialog.h
index 9a0994b..b207e37 100644
--- a/plugins/spell/gedit-spell-checker-dialog.h
+++ b/plugins/spell/gedit-spell-checker-dialog.h
@@ -3,6 +3,7 @@
* This file is part of gedit
*
* Copyright (C) 2002 Paolo Maggi
+ * Copyright (C) 2015 Sébastien Wilmet
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,7 +23,7 @@
#define __GEDIT_SPELL_CHECKER_DIALOG_H__
#include <gtk/gtk.h>
-#include "gedit-spell-checker.h"
+#include "gedit-spell-navigator.h"
G_BEGIN_DECLS
@@ -34,26 +35,10 @@ G_DECLARE_DERIVABLE_TYPE (GeditSpellCheckerDialog, gedit_spell_checker_dialog,
struct _GeditSpellCheckerDialogClass
{
GtkDialogClass parent_class;
-
- /* Signals */
- void (* change) (GeditSpellCheckerDialog *dialog,
- const gchar *word,
- const gchar *change_to);
-
- void (* change_all) (GeditSpellCheckerDialog *dialog,
- const gchar *word,
- const gchar *change_to);
-
- void (* goto_next) (GeditSpellCheckerDialog *dialog);
};
-GtkWidget * gedit_spell_checker_dialog_new (GtkWindow *parent,
- GeditSpellChecker *checker);
-
-void gedit_spell_checker_dialog_set_misspelled_word (GeditSpellCheckerDialog *dialog,
- const gchar *word);
-
-void gedit_spell_checker_dialog_set_completed (GeditSpellCheckerDialog *dialog);
+GtkWidget * gedit_spell_checker_dialog_new (GtkWindow *parent,
+ GeditSpellNavigator *navigator);
G_END_DECLS
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index 753dc12..ee380e5 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -47,7 +47,6 @@
#define SPELL_ENABLED_STR "1"
#define VIEW_DATA_KEY "GeditSpellPlugin-ViewData"
-#define NAVIGATOR_KEY "GeditSpellPlugin-Navigator"
static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
@@ -301,50 +300,6 @@ get_spell_checker_from_document (GeditDocument *doc)
}
static void
-goto_next_cb (GeditSpellCheckerDialog *dialog,
- GeditSpellNavigator *navigator)
-{
- gchar *word;
- GError *error = NULL;
-
- word = gedit_spell_navigator_goto_next (navigator, &error);
-
- if (error != NULL)
- {
- g_warning ("Spell checker plugin: %s", error->message);
- g_error_free (error);
- }
-
- if (word != NULL)
- {
- gedit_spell_checker_dialog_set_misspelled_word (dialog, word);
- g_free (word);
- }
- else
- {
- gedit_spell_checker_dialog_set_completed (dialog);
- }
-}
-
-static void
-change_cb (GeditSpellCheckerDialog *dialog,
- const gchar *word,
- const gchar *change_to,
- GeditSpellNavigator *navigator)
-{
- gedit_spell_navigator_change (navigator, word, change_to);
-}
-
-static void
-change_all_cb (GeditSpellCheckerDialog *dialog,
- const gchar *word,
- const gchar *change_to,
- GeditSpellNavigator *navigator)
-{
- gedit_spell_navigator_change_all (navigator, word, change_to);
-}
-
-static void
language_dialog_response (GtkDialog *dialog,
gint response_id,
GeditSpellChecker *checker)
@@ -429,10 +384,6 @@ spell_cb (GSimpleAction *action,
GeditSpellChecker *checker;
GeditSpellNavigator *navigator;
GtkWidget *dialog;
- gchar *word;
- GtkTextIter start;
- GtkTextIter end;
- GError *error = NULL;
gedit_debug (DEBUG_PLUGINS);
@@ -459,64 +410,11 @@ spell_cb (GSimpleAction *action,
}
navigator = gedit_spell_navigator_gtv_new (GTK_TEXT_VIEW (view), checker);
-
- word = gedit_spell_navigator_goto_next (navigator, &error);
-
- if (error != NULL)
- {
- g_warning ("Spell checker plugin: %s", error->message);
- g_error_free (error);
- error = NULL;
- }
-
- if (word == NULL)
- {
- GtkWidget *statusbar;
-
- statusbar = gedit_window_get_statusbar (priv->window);
- gedit_statusbar_flash_message (GEDIT_STATUSBAR (statusbar),
- priv->statusbar_context_id,
- _("No misspelled words"));
-
- g_object_unref (navigator);
- return;
- }
-
- dialog = gedit_spell_checker_dialog_new (GTK_WINDOW (priv->window), checker);
+ dialog = gedit_spell_checker_dialog_new (GTK_WINDOW (priv->window), navigator);
+ g_object_unref (navigator);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- g_object_set_data_full (G_OBJECT (dialog),
- NAVIGATOR_KEY,
- navigator,
- g_object_unref);
-
- g_signal_connect (dialog,
- "change",
- G_CALLBACK (change_cb),
- navigator);
-
- g_signal_connect (dialog,
- "change-all",
- G_CALLBACK (change_all_cb),
- navigator);
-
- g_signal_connect (dialog,
- "goto-next",
- G_CALLBACK (goto_next_cb),
- navigator);
-
- gedit_spell_checker_dialog_set_misspelled_word (GEDIT_SPELL_CHECKER_DIALOG (dialog), word);
- g_free (word);
-
- gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end);
-
gtk_widget_show (dialog);
-
- /* Restore selection. Showing the dialog makes a focus change, which
- * unselects the GtkTextBuffer selection.
- */
- gtk_text_buffer_select_range (GTK_TEXT_BUFFER (doc), &start, &end);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]