[gedit/wip/spell-checking: 11/13] auto-spell: don't depend on GeditDocument
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/spell-checking: 11/13] auto-spell: don't depend on GeditDocument
- Date: Fri, 17 Jul 2015 11:18:32 +0000 (UTC)
commit 42dfa73e0748a8f2637575e0e96e23697a363f59
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jul 17 13:03:51 2015 +0200
auto-spell: don't depend on GeditDocument
Depend only on GtkSourceBuffer, so the code is more easily reusable
outside gedit.
plugins/spell/gedit-automatic-spell-checker.c | 112 ++++++++++++------------
plugins/spell/gedit-automatic-spell-checker.h | 6 +-
plugins/spell/gedit-spell-plugin.c | 8 +-
3 files changed, 63 insertions(+), 63 deletions(-)
---
diff --git a/plugins/spell/gedit-automatic-spell-checker.c b/plugins/spell/gedit-automatic-spell-checker.c
index 96b24ca..256642e 100644
--- a/plugins/spell/gedit-automatic-spell-checker.c
+++ b/plugins/spell/gedit-automatic-spell-checker.c
@@ -35,7 +35,7 @@
struct _GeditAutomaticSpellChecker
{
- GeditDocument *doc;
+ GtkSourceBuffer *buffer;
GSList *views;
GtkTextMark *mark_insert_start;
@@ -68,11 +68,11 @@ check_word (GeditAutomaticSpellChecker *spell,
{
gchar *word;
- word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), start, end, FALSE);
+ word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->buffer), start, end, FALSE);
if (!gedit_spell_checker_check_word (spell->spell_checker, word, -1))
{
- gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (spell->buffer),
spell->tag_highlight,
start,
end);
@@ -124,9 +124,9 @@ check_range (GeditAutomaticSpellChecker *spell,
GtkTextIter word_start;
gboolean highlight;
- gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->buffer),
&cursor,
- gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (spell->doc)));
+ gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (spell->buffer)));
precursor = cursor;
gtk_text_iter_backward_char (&precursor);
@@ -138,7 +138,7 @@ check_range (GeditAutomaticSpellChecker *spell,
end_adjusted = *end;
adjust_iters_at_word_boundaries (&start_adjusted, &end_adjusted);
- gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->buffer),
spell->tag_highlight,
&start_adjusted,
&end_adjusted);
@@ -211,10 +211,10 @@ check_deferred_range (GeditAutomaticSpellChecker *spell,
{
GtkTextIter start, end;
- gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->buffer),
&start,
spell->mark_insert_start);
- gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (spell->buffer),
&end,
spell->mark_insert_end);
@@ -308,7 +308,7 @@ remove_tag_to_word (GeditAutomaticSpellChecker *spell,
gboolean found;
- gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (spell->doc), &iter, 0);
+ gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (spell->buffer), &iter, 0);
found = TRUE;
@@ -326,7 +326,7 @@ remove_tag_to_word (GeditAutomaticSpellChecker *spell,
if (gtk_text_iter_starts_word (&match_start) &&
gtk_text_iter_ends_word (&match_end))
{
- gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->buffer),
spell->tag_highlight,
&match_start,
&match_end);
@@ -345,9 +345,9 @@ add_to_dictionary (GtkWidget *menuitem,
GtkTextIter start, end;
- get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click);
+ get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->buffer), &start, &end, spell->mark_click);
- word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc),
+ word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->buffer),
&start,
&end,
FALSE);
@@ -365,9 +365,9 @@ ignore_all (GtkWidget *menuitem,
GtkTextIter start, end;
- get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click);
+ get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->buffer), &start, &end, spell->mark_click);
- word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc),
+ word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->buffer),
&start,
&end,
FALSE);
@@ -386,19 +386,19 @@ replace_word (GtkWidget *menuitem,
GtkTextIter start, end;
- get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click);
+ get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->buffer), &start, &end, spell->mark_click);
- oldword = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE);
+ oldword = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->buffer), &start, &end, FALSE);
newword = g_object_get_data (G_OBJECT (menuitem), SUGGESTION_KEY);
g_return_if_fail (newword != NULL);
- gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (spell->doc));
+ gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (spell->buffer));
- gtk_text_buffer_delete (GTK_TEXT_BUFFER (spell->doc), &start, &end);
- gtk_text_buffer_insert (GTK_TEXT_BUFFER (spell->doc), &start, newword, -1);
+ gtk_text_buffer_delete (GTK_TEXT_BUFFER (spell->buffer), &start, &end);
+ gtk_text_buffer_insert (GTK_TEXT_BUFFER (spell->buffer), &start, newword, -1);
- gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (spell->doc));
+ gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (spell->buffer));
gedit_spell_checker_set_correction (spell->spell_checker,
oldword, strlen (oldword),
@@ -543,7 +543,7 @@ populate_popup (GtkTextView *textview,
char *word;
/* we need to figure out if they picked a misspelled word. */
- get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->doc), &start, &end, spell->mark_click);
+ get_word_extents_from_mark (GTK_TEXT_BUFFER (spell->buffer), &start, &end, spell->mark_click);
/* if our highlight algorithm ever messes up,
* this isn't correct, either. */
@@ -558,7 +558,7 @@ populate_popup (GtkTextView *textview,
/* then, on top of it, the suggestions menu. */
mi = gtk_menu_item_new_with_mnemonic (_("_Spelling Suggestions..."));
- word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->doc), &start, &end, FALSE);
+ word = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (spell->buffer), &start, &end, FALSE);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi),
build_suggestion_menu (spell, word));
g_free(word);
@@ -574,7 +574,7 @@ gedit_automatic_spell_checker_recheck_all (GeditAutomaticSpellChecker *spell)
g_return_if_fail (spell != NULL);
- gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->doc), &start, &end);
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->buffer), &start, &end);
check_range (spell, &start, &end, TRUE);
}
@@ -713,47 +713,47 @@ spell_tag_destroyed (GeditAutomaticSpellChecker *spell,
}
GeditAutomaticSpellChecker *
-gedit_automatic_spell_checker_new (GeditDocument *doc,
+gedit_automatic_spell_checker_new (GtkSourceBuffer *buffer,
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 (GTK_SOURCE_IS_BUFFER (buffer), 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,
+ g_return_val_if_fail ((spell = gedit_automatic_spell_checker_get_from_buffer (buffer)) == NULL,
spell);
/* attach to the widget */
spell = g_new0 (GeditAutomaticSpellChecker, 1);
- spell->doc = doc;
+ spell->buffer = buffer;
spell->spell_checker = g_object_ref (checker);
- g_object_set_data_full (G_OBJECT (doc),
+ g_object_set_data_full (G_OBJECT (buffer),
AUTOMATIC_SPELL_CHECKER_KEY,
spell,
(GDestroyNotify) gedit_automatic_spell_checker_free_internal);
- g_signal_connect (doc,
+ g_signal_connect (buffer,
"insert-text",
G_CALLBACK (insert_text_before),
spell);
- g_signal_connect_after (doc,
+ g_signal_connect_after (buffer,
"insert-text",
G_CALLBACK (insert_text_after),
spell);
- g_signal_connect_after (doc,
+ g_signal_connect_after (buffer,
"delete-range",
G_CALLBACK (delete_range_after),
spell);
- g_signal_connect (doc,
+ g_signal_connect (buffer,
"mark-set",
G_CALLBACK (mark_set),
spell);
- g_signal_connect (doc,
+ g_signal_connect (buffer,
"highlight-updated",
G_CALLBACK (highlight_updated),
spell);
@@ -776,7 +776,7 @@ gedit_automatic_spell_checker_new (GeditDocument *doc,
spell);
spell->tag_highlight = gtk_text_buffer_create_tag (
- GTK_TEXT_BUFFER (doc),
+ GTK_TEXT_BUFFER (buffer),
"gtkspell-misspelled",
"underline", PANGO_UNDERLINE_ERROR,
NULL);
@@ -785,7 +785,7 @@ gedit_automatic_spell_checker_new (GeditDocument *doc,
(GWeakNotify)spell_tag_destroyed,
spell);
- tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (doc));
+ tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer));
gtk_text_tag_set_priority (spell->tag_highlight,
gtk_text_tag_table_get_size (tag_table) - 1);
@@ -805,58 +805,58 @@ gedit_automatic_spell_checker_new (GeditDocument *doc,
/* 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);
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
- spell->mark_insert_start = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
+ spell->mark_insert_start = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (buffer),
"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),
+ gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer),
"gedit-automatic-spell-checker-insert-start",
&start,
TRUE);
}
else
{
- gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
+ gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (buffer),
spell->mark_insert_start,
&start);
}
- spell->mark_insert_end = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
+ spell->mark_insert_end = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (buffer),
"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),
+ gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer),
"gedit-automatic-spell-checker-insert-end",
&start,
TRUE);
}
else
{
- gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
+ gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (buffer),
spell->mark_insert_end,
&start);
}
- spell->mark_click = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (doc),
+ spell->mark_click = gtk_text_buffer_get_mark (GTK_TEXT_BUFFER (buffer),
"gedit-automatic-spell-checker-click");
if (spell->mark_click == NULL)
{
spell->mark_click =
- gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc),
+ gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer),
"gedit-automatic-spell-checker-click",
&start,
TRUE);
}
else
{
- gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc),
+ gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (buffer),
spell->mark_click,
&start);
}
@@ -867,20 +867,20 @@ gedit_automatic_spell_checker_new (GeditDocument *doc,
}
GeditAutomaticSpellChecker *
-gedit_automatic_spell_checker_get_from_document (const GeditDocument *doc)
+gedit_automatic_spell_checker_get_from_buffer (GtkSourceBuffer *buffer)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
- return g_object_get_data (G_OBJECT (doc), AUTOMATIC_SPELL_CHECKER_KEY);
+ return g_object_get_data (G_OBJECT (buffer), AUTOMATIC_SPELL_CHECKER_KEY);
}
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);
+ g_return_if_fail (gedit_automatic_spell_checker_get_from_buffer (spell->buffer) == spell);
- g_object_set_data (G_OBJECT (spell->doc), AUTOMATIC_SPELL_CHECKER_KEY, NULL);
+ g_object_set_data (G_OBJECT (spell->buffer), AUTOMATIC_SPELL_CHECKER_KEY, NULL);
}
static void
@@ -892,14 +892,14 @@ gedit_automatic_spell_checker_free_internal (GeditAutomaticSpellChecker *spell)
g_return_if_fail (spell != NULL);
- table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (spell->doc));
+ table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (spell->buffer));
if (table != NULL && spell->tag_highlight != NULL)
{
- gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (spell->buffer),
&start,
&end);
- gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->doc),
+ gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (spell->buffer),
spell->tag_highlight,
&start,
&end);
@@ -912,7 +912,7 @@ gedit_automatic_spell_checker_free_internal (GeditAutomaticSpellChecker *spell)
gtk_text_tag_table_remove (table, spell->tag_highlight);
}
- g_signal_handlers_disconnect_matched (G_OBJECT (spell->doc),
+ g_signal_handlers_disconnect_matched (G_OBJECT (spell->buffer),
G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL,
spell);
@@ -955,7 +955,7 @@ gedit_automatic_spell_checker_attach_view (GeditAutomaticSpellChecker *spell,
g_return_if_fail (GEDIT_IS_VIEW (view));
g_return_if_fail (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)) ==
- GTK_TEXT_BUFFER (spell->doc));
+ GTK_TEXT_BUFFER (spell->buffer));
g_signal_connect (view,
"button-press-event",
@@ -985,7 +985,7 @@ gedit_automatic_spell_checker_detach_view (GeditAutomaticSpellChecker *spell,
g_return_if_fail (GEDIT_IS_VIEW (view));
g_return_if_fail (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)) ==
- GTK_TEXT_BUFFER (spell->doc));
+ GTK_TEXT_BUFFER (spell->buffer));
g_return_if_fail (spell->views != NULL);
g_signal_handlers_disconnect_matched (G_OBJECT (view),
diff --git a/plugins/spell/gedit-automatic-spell-checker.h b/plugins/spell/gedit-automatic-spell-checker.h
index 8b11d8a..8c50960 100644
--- a/plugins/spell/gedit-automatic-spell-checker.h
+++ b/plugins/spell/gedit-automatic-spell-checker.h
@@ -27,7 +27,7 @@
#ifndef __GEDIT_AUTOMATIC_SPELL_CHECKER_H__
#define __GEDIT_AUTOMATIC_SPELL_CHECKER_H__
-#include <gedit/gedit-document.h>
+#include <gtksourceview/gtksource.h>
#include <gedit/gedit-view.h>
#include "gedit-spell-checker.h"
@@ -35,11 +35,11 @@
typedef struct _GeditAutomaticSpellChecker GeditAutomaticSpellChecker;
GeditAutomaticSpellChecker *
- gedit_automatic_spell_checker_new (GeditDocument *doc,
+ gedit_automatic_spell_checker_new (GtkSourceBuffer *buffer,
GeditSpellChecker *checker);
GeditAutomaticSpellChecker *
- gedit_automatic_spell_checker_get_from_document (const GeditDocument *doc);
+ gedit_automatic_spell_checker_get_from_buffer (GtkSourceBuffer *buffer);
void gedit_automatic_spell_checker_free (GeditAutomaticSpellChecker *spell);
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index 4b6e145..cecd71f 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -874,13 +874,13 @@ set_auto_spell (GeditWindow *window,
spell = get_spell_checker_from_document (doc);
g_return_if_fail (spell != NULL);
- autospell = gedit_automatic_spell_checker_get_from_document (doc);
+ autospell = gedit_automatic_spell_checker_get_from_buffer (GTK_SOURCE_BUFFER (doc));
if (active)
{
if (autospell == NULL)
{
- autospell = gedit_automatic_spell_checker_new (doc, spell);
+ autospell = gedit_automatic_spell_checker_new (GTK_SOURCE_BUFFER (doc), spell);
gedit_automatic_spell_checker_attach_view (autospell, view);
gedit_automatic_spell_checker_recheck_all (autospell);
}
@@ -1003,7 +1003,7 @@ update_ui (GeditSpellPlugin *plugin)
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);
+ gedit_automatic_spell_checker_get_from_buffer (GTK_SOURCE_BUFFER (doc)) != NULL);
/* If the document is loading we can't get the metadata so we
endup with an useless speller */
@@ -1080,7 +1080,7 @@ on_document_saved (GeditDocument *doc,
const gchar *key;
/* Make sure to save the metadata here too */
- autospell = gedit_automatic_spell_checker_get_from_document (doc);
+ autospell = gedit_automatic_spell_checker_get_from_buffer (GTK_SOURCE_BUFFER (doc));
spell = GEDIT_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id));
if (spell != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]