SF.net SVN: geany-plugins:[298] trunk/spellcheck/src
eht16 at users.sourceforge.net
eht16 at xxxxx
Sat Nov 15 17:17:33 UTC 2008
Revision: 298
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=298&view=rev
Author: eht16
Date: 2008-11-15 17:17:33 +0000 (Sat, 15 Nov 2008)
Log Message:
-----------
When replacing a misspelled word with a suggestion, add this replacement to the spell checker to remember it in further checks.
Modified Paths:
--------------
trunk/spellcheck/src/gui.c
trunk/spellcheck/src/speller.c
trunk/spellcheck/src/speller.h
Modified: trunk/spellcheck/src/gui.c
===================================================================
--- trunk/spellcheck/src/gui.c 2008-11-14 01:37:06 UTC (rev 297)
+++ trunk/spellcheck/src/gui.c 2008-11-15 17:17:33 UTC (rev 298)
@@ -139,6 +139,7 @@
{
gchar *sugg = gdata;
gint startword, endword;
+ ScintillaObject *sci = clickinfo.doc->editor->sci;
if (clickinfo.doc == NULL || clickinfo.pos == -1)
{
@@ -146,20 +147,30 @@
return;
}
- startword = p_sci->send_message(
- clickinfo.doc->editor->sci, SCI_WORDSTARTPOSITION, clickinfo.pos, 0);
- endword = p_sci->send_message(
- clickinfo.doc->editor->sci, SCI_WORDENDPOSITION, clickinfo.pos, 0);
+ startword = p_sci->send_message(sci, SCI_WORDSTARTPOSITION, clickinfo.pos, 0);
+ endword = p_sci->send_message(sci, SCI_WORDENDPOSITION, clickinfo.pos, 0);
if (startword != endword)
{
- p_sci->set_selection_start(clickinfo.doc->editor->sci, startword);
- p_sci->set_selection_end(clickinfo.doc->editor->sci, endword);
- p_sci->replace_sel(clickinfo.doc->editor->sci, sugg);
+ gchar *word;
+
+ p_sci->set_selection_start(sci, startword);
+ p_sci->set_selection_end(sci, endword);
+
+ /* retrieve the old text */
+ word = g_malloc(p_sci->get_selected_text_length(sci) + 1);
+ p_sci->get_selected_text(sci, word);
+
+ /* replace the misspelled word with the chosen suggestion */
+ p_sci->replace_sel(sci, sugg);
- /** TODO replace word */
+ /* store the replacement for future checks */
+ speller_store_replacement(word, sugg);
- p_sci->indicator_clear(clickinfo.doc->editor->sci, startword, endword - startword);
+ /* remove indicator */
+ p_sci->indicator_clear(sci, startword, endword - startword);
+
+ g_free(word);
}
}
Modified: trunk/spellcheck/src/speller.c
===================================================================
--- trunk/spellcheck/src/speller.c 2008-11-14 01:37:06 UTC (rev 297)
+++ trunk/spellcheck/src/speller.c 2008-11-15 17:17:33 UTC (rev 298)
@@ -122,10 +122,16 @@
{
gint pos_start, pos_end;
gint wstart, wend;
- GString *str = g_string_sized_new(256);
+ GString *str;
gint suggestions_found = 0;
gchar c;
+ g_return_val_if_fail(speller_dict != NULL, 0);
+ g_return_val_if_fail(doc != NULL, 0);
+ g_return_val_if_fail(line != NULL, 0);
+
+ str = g_string_sized_new(256);
+
pos_start = p_sci->get_position_from_line(doc->editor->sci, line_number);
/* TODO use SCI_GETLINEENDPOSITION */
pos_end = p_sci->get_position_from_line(doc->editor->sci, line_number + 1);
@@ -169,6 +175,7 @@
gint suggestions_found = 0;
g_return_if_fail(speller_dict != NULL);
+ g_return_if_fail(doc != NULL);
enchant_dict_describe(speller_dict, dict_describe, &dict_string);
@@ -349,12 +356,16 @@
void speller_add_word(const gchar *word)
{
+ g_return_if_fail(speller_dict != NULL);
+ g_return_if_fail(word != NULL);
+
enchant_dict_add_to_pwl(speller_dict, clickinfo.word, -1);
}
gboolean speller_dict_check(const gchar *word)
{
g_return_val_if_fail(speller_dict != NULL, FALSE);
+ g_return_val_if_fail(word != NULL, FALSE);
return enchant_dict_check(speller_dict, word, -1);
}
@@ -363,6 +374,7 @@
gchar **speller_dict_suggest(const gchar *word, gsize *n_suggs)
{
g_return_val_if_fail(speller_dict != NULL, NULL);
+ g_return_val_if_fail(word != NULL, NULL);
return enchant_dict_suggest(speller_dict, word, -1, n_suggs);
}
@@ -371,11 +383,22 @@
void speller_add_word_to_session(const gchar *word)
{
g_return_if_fail(speller_dict != NULL);
+ g_return_if_fail(word != NULL);
enchant_dict_add_to_session(speller_dict, word, -1);
}
+void speller_store_replacement(const gchar *old_word, const gchar *new_word)
+{
+ g_return_if_fail(speller_dict != NULL);
+ g_return_if_fail(old_word != NULL);
+ g_return_if_fail(new_word != NULL);
+
+ enchant_dict_store_replacement(speller_dict, old_word, -1, new_word, -1);
+}
+
+
void speller_init(void)
{
speller_broker = enchant_broker_init();
Modified: trunk/spellcheck/src/speller.h
===================================================================
--- trunk/spellcheck/src/speller.h 2008-11-14 01:37:06 UTC (rev 297)
+++ trunk/spellcheck/src/speller.h 2008-11-15 17:17:33 UTC (rev 298)
@@ -47,6 +47,8 @@
void speller_add_word_to_session(const gchar *word);
+void speller_store_replacement(const gchar *old_word, const gchar *new_word);
+
void speller_init(void);
void speller_free(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Plugins-Commits
mailing list