SF.net SVN: geany-plugins:[2037] trunk/geany-plugins/spellcheck/src
eht16 at users.sourceforge.net
eht16 at xxxxx
Sun Apr 17 14:39:51 UTC 2011
Revision: 2037
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2037&view=rev
Author: eht16
Date: 2011-04-17 14:39:50 +0000 (Sun, 17 Apr 2011)
Log Message:
-----------
Improve 'Check as you type' feature.
Instead of handling a global key release event signal, we use Scintilla's SCN_MODIFIED notification. This should not make a big difference in the behaviour but seems more clean.
A side effect is that this way we get also notified about pasted text and can also check it.
Modified Paths:
--------------
trunk/geany-plugins/spellcheck/src/gui.c
trunk/geany-plugins/spellcheck/src/gui.h
trunk/geany-plugins/spellcheck/src/scplugin.c
trunk/geany-plugins/spellcheck/src/scplugin.h
Modified: trunk/geany-plugins/spellcheck/src/gui.c
===================================================================
--- trunk/geany-plugins/spellcheck/src/gui.c 2011-04-17 13:54:58 UTC (rev 2036)
+++ trunk/geany-plugins/spellcheck/src/gui.c 2011-04-17 14:39:50 UTC (rev 2037)
@@ -396,53 +396,54 @@
}
-static gint sci_get_eol_mode(GeanyDocument *doc)
+static void check_line(GeanyDocument *doc, gint line_number)
{
- return scintilla_send_message(doc->editor->sci, SCI_GETEOLMODE, 0, 0);
+ gchar *line;
+
+ line = sci_get_line(doc->editor->sci, line_number);
+
+ indicator_clear_on_line(doc, line_number);
+ if (sc_speller_process_line(doc, line_number, line) != 0)
+ {
+ if (sc_info->use_msgwin)
+ msgwin_switch_tab(MSG_MESSAGE, FALSE);
+ }
+ g_free(line);
}
-/* Checks only the last word before the current cursor position -> check as you type. */
-gboolean sc_gui_key_release_cb(GtkWidget *widget, GdkEventKey *ev, gpointer data)
+static void check_on_text_changed(GeanyDocument *doc, gint position, gint lines_added)
{
gint line_number;
- gchar *line;
- GeanyDocument *doc;
- GtkWidget *focusw;
+ gint i;
- if (! sc_info->check_while_typing)
- return FALSE;
-
/* check only once in a while */
if (need_delay())
- return FALSE;
+ return;
- doc = document_get_current();
-
- if (ev->keyval == '\r' && sci_get_eol_mode(doc) == SC_EOL_CRLF)
- { /* prevent double line checking */
- return FALSE;
+ line_number = sci_get_line_from_position(doc->editor->sci, position);
+ /* Iterating over all lines which changed as indicated by lines_added. lines_added is 0
+ * if only a lines has changed, in this case set it to 1. Otherwise, iterating over all
+ * new lines makes spell checking work for pasted text. */
+ lines_added = MAX(1, lines_added);
+ for (i = 0; i < lines_added; i++)
+ {
+ check_line(doc, line_number + i);
}
+}
- /* bail out if we don't have a document or if we are not in the editor widget */
- focusw = gtk_window_get_focus(GTK_WINDOW(geany->main_widgets->window));
- if (doc == NULL || focusw != GTK_WIDGET(doc->editor->sci))
+
+gboolean sc_gui_editor_notify(GObject *object, GeanyEditor *editor,
+ SCNotification *nt, gpointer data)
+{
+ if (! sc_info->check_while_typing)
return FALSE;
- line_number = sci_get_current_line(doc->editor->sci);
- if (ev->keyval == '\n' || ev->keyval == '\r')
- line_number--; /* check previous line if we start a new one */
- line = sci_get_line(doc->editor->sci, line_number);
-
- indicator_clear_on_line(doc, line_number);
- if (sc_speller_process_line(doc, line_number, line) != 0)
+ if (nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
{
- if (sc_info->use_msgwin)
- msgwin_switch_tab(MSG_MESSAGE, FALSE);
+ check_on_text_changed(editor->document, nt->position, nt->linesAdded);
}
- g_free(line);
-
return FALSE;
}
Modified: trunk/geany-plugins/spellcheck/src/gui.h
===================================================================
--- trunk/geany-plugins/spellcheck/src/gui.h 2011-04-17 13:54:58 UTC (rev 2036)
+++ trunk/geany-plugins/spellcheck/src/gui.h 2011-04-17 14:39:50 UTC (rev 2037)
@@ -27,11 +27,6 @@
#define SC_GUI_H 1
-
-gboolean sc_gui_key_release_cb(GtkWidget *widget, GdkEventKey *ev, gpointer user_data);
-
-gboolean sc_gui_key_release_cb(GtkWidget *widget, GdkEventKey *ev, gpointer data);
-
void sc_gui_kb_run_activate_cb(guint key_id);
void sc_gui_kb_toggle_typing_activate_cb(guint key_id);
@@ -41,6 +36,9 @@
void sc_gui_update_editor_menu_cb(GObject *obj, const gchar *word, gint pos,
GeanyDocument *doc, gpointer user_data);
+gboolean sc_gui_editor_notify(GObject *object, GeanyEditor *editor,
+ SCNotification *nt, gpointer data);
+
void sc_gui_update_toolbar(void);
void sc_gui_update_menu(void);
Modified: trunk/geany-plugins/spellcheck/src/scplugin.c
===================================================================
--- trunk/geany-plugins/spellcheck/src/scplugin.c 2011-04-17 13:54:58 UTC (rev 2036)
+++ trunk/geany-plugins/spellcheck/src/scplugin.c 2011-04-17 14:39:50 UTC (rev 2037)
@@ -65,6 +65,7 @@
PluginCallback plugin_callbacks[] =
{
{ "update-editor-menu", (GCallback) &sc_gui_update_editor_menu_cb, FALSE, NULL },
+ { "editor-notify", (GCallback) &sc_gui_editor_notify, FALSE, NULL },
{ NULL, NULL, FALSE, NULL }
};
@@ -192,9 +193,6 @@
sc_gui_update_menu();
gtk_widget_show_all(sc_info->menu_item);
- sc_info->signal_id = g_signal_connect(geany->main_widgets->window,
- "key-release-event", G_CALLBACK(sc_gui_key_release_cb), NULL);
-
/* setup keybindings */
keybindings_set_item(plugin_key_group, KB_SPELL_CHECK, sc_gui_kb_run_activate_cb,
0, 0, "spell_check", _("Run Spell Check"), sc_info->submenu_item_default);
@@ -344,8 +342,6 @@
void plugin_cleanup(void)
{
- g_signal_handler_disconnect(geany->main_widgets->window, sc_info->signal_id);
-
gtk_widget_destroy(sc_info->edit_menu);
gtk_widget_destroy(sc_info->edit_menu_sep);
if (sc_info->toolbar_button != NULL)
Modified: trunk/geany-plugins/spellcheck/src/scplugin.h
===================================================================
--- trunk/geany-plugins/spellcheck/src/scplugin.h 2011-04-17 13:54:58 UTC (rev 2036)
+++ trunk/geany-plugins/spellcheck/src/scplugin.h 2011-04-17 14:39:50 UTC (rev 2037)
@@ -37,7 +37,6 @@
gboolean check_while_typing;
gboolean show_toolbar_item;
gboolean show_editor_menu_item;
- gulong signal_id;
GPtrArray *dicts;
GtkWidget *main_menu;
GtkWidget *menu_item;
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