SF.net SVN: geany-plugins:[512] trunk/spellcheck
eht16 at users.sourceforge.net
eht16 at xxxxx
Fri Feb 27 20:30:13 UTC 2009
Revision: 512
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=512&view=rev
Author: eht16
Date: 2009-02-27 20:30:12 +0000 (Fri, 27 Feb 2009)
Log Message:
-----------
Revert back the changes to use the "editor-notify" signal as it makes things worse than before. Instead use the old code to connect to the global "key-press-event" signal but reduce the delay to half a second to make checking while typing smoother.
Modified Paths:
--------------
trunk/spellcheck/ChangeLog
trunk/spellcheck/src/gui.c
trunk/spellcheck/src/gui.h
trunk/spellcheck/src/scplugin.c
trunk/spellcheck/src/scplugin.h
trunk/spellcheck/src/speller.c
trunk/spellcheck/src/speller.h
Modified: trunk/spellcheck/ChangeLog
===================================================================
--- trunk/spellcheck/ChangeLog 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/ChangeLog 2009-02-27 20:30:12 UTC (rev 512)
@@ -1,3 +1,13 @@
+2009-02-27 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+
+ * src/gui.c, src/gui.h, src/scplugin.c, src/scplugin.h, src/speller.c,
+ src/speller.h:
+ Revert back the changes to use the "editor-notify" signal as it
+ makes things worse than before. Instead use the old code to connect
+ to the global "key-press-event" signal but reduce the delay
+ to half a second to make checking while typing smoother.
+
+
2009-02-26 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Makefile.am:
Modified: trunk/spellcheck/src/gui.c
===================================================================
--- trunk/spellcheck/src/gui.c 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/src/gui.c 2009-02-27 20:30:12 UTC (rev 512)
@@ -318,42 +318,81 @@
}
-static void indicator_clear_on_range(GeanyEditor *editor, gint start, gint len)
+static void indicator_clear_on_line(GeanyDocument *doc, gint line_number)
{
- sci_indicator_set(editor->sci, GEANY_INDICATOR_ERROR);
- sci_indicator_clear(editor->sci, start, len);
+ gint start_pos, length;
+
+ g_return_if_fail(doc != NULL);
+
+ start_pos = sci_get_position_from_line(doc->editor->sci, line_number);
+ length = sci_get_line_length(doc->editor->sci, line_number);
+
+ sci_indicator_clear(doc->editor->sci, start_pos, length);
}
-gboolean sc_gui_editor_notify_cb(GObject *obj, GeanyEditor *editor, SCNotification *nt, gpointer data)
+static gboolean need_delay(void)
{
- gint start_pos, end_pos, pos;
- gchar *word;
+ static gint64 time_prev = 0; /* time in microseconds */
+ gint64 time_now;
+ GTimeVal t;
- if (! sc_info->check_while_typing || nt->nmhdr.code != SCN_MODIFIED ||
- ! (nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)))
- {
+ g_get_current_time(&t);
+
+ time_now = ((gint64) t.tv_sec * G_USEC_PER_SEC) + t.tv_usec;
+
+ /* delay keypresses for 0.5 seconds */
+ if (time_now < (time_prev + 500000))
+ return TRUE;
+
+ /* set current time for the next key press */
+ time_prev = time_now;
+
+ return FALSE;
+}
+
+
+/* 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)
+{
+ gint line_number;
+ gchar *line;
+ GeanyDocument *doc;
+ GtkWidget *focusw;
+
+ if (! sc_info->check_while_typing)
return FALSE;
- }
- pos = nt->position;
+ /* check only once in a while */
+ if (need_delay())
+ return FALSE;
- /* retrieve the word at the position */
- word = editor_get_word_at_pos(editor, pos, GEANY_WORDCHARS);
- if (word == NULL)
+ doc = document_get_current();
+
+ if (ev->keyval == '\r' &&
+ scintilla_send_message(doc->editor->sci, SCI_GETEOLMODE, 0, 0) == SC_EOL_CRLF)
+ { /* prevent double line checking */
return FALSE;
+ }
- start_pos = scintilla_send_message(editor->sci, SCI_WORDSTARTPOSITION, pos, 0);
- end_pos = start_pos + strlen(word);
+ /* 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))
+ return FALSE;
- indicator_clear_on_range(editor, start_pos, end_pos - start_pos);
- if (sc_speller_check_word(editor->document, -1, word, start_pos, end_pos) != 0)
+ 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 (sc_info->use_msgwin)
msgwin_switch_tab(MSG_MESSAGE, FALSE);
}
- g_free(word);
+ g_free(line);
return FALSE;
}
Modified: trunk/spellcheck/src/gui.h
===================================================================
--- trunk/spellcheck/src/gui.h 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/src/gui.h 2009-02-27 20:30:12 UTC (rev 512)
@@ -33,8 +33,7 @@
gboolean sc_gui_key_release_cb(GtkWidget *widget, GdkEventKey *ev, gpointer user_data);
-gboolean sc_gui_editor_notify_cb(GObject *obj, GeanyEditor *editor,
- SCNotification *nt, gpointer data);
+gboolean sc_gui_key_release_cb(GtkWidget *widget, GdkEventKey *ev, gpointer data);
void sc_gui_kb_run_activate_cb(guint key_id);
Modified: trunk/spellcheck/src/scplugin.c
===================================================================
--- trunk/spellcheck/src/scplugin.c 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/src/scplugin.c 2009-02-27 20:30:12 UTC (rev 512)
@@ -79,7 +79,6 @@
PluginCallback plugin_callbacks[] =
{
{ "update-editor-menu", (GCallback) &sc_gui_update_editor_menu_cb, FALSE, NULL },
- { "editor-notify", (GCallback) &sc_gui_editor_notify_cb, TRUE, NULL },
{ NULL, NULL, FALSE, NULL }
};
@@ -192,6 +191,9 @@
sp_item = sc_gui_create_menu(sc_info->menu_item);
gtk_widget_show_all(sp_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);
@@ -282,6 +284,8 @@
}
g_ptr_array_free(sc_info->dicts, TRUE);
+ 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/spellcheck/src/scplugin.h
===================================================================
--- trunk/spellcheck/src/scplugin.h 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/src/scplugin.h 2009-02-27 20:30:12 UTC (rev 512)
@@ -35,6 +35,7 @@
gboolean use_msgwin;
gboolean check_while_typing;
gboolean show_toolbar_item;
+ gulong signal_id;
GPtrArray *dicts;
GtkWidget *menu_item;
GtkWidget *submenu_item_default;
Modified: trunk/spellcheck/src/speller.c
===================================================================
--- trunk/spellcheck/src/speller.c 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/src/speller.c 2009-02-27 20:30:12 UTC (rev 512)
@@ -59,7 +59,7 @@
}
-gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gchar *word,
+static gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gchar *word,
gint start_pos, gint end_pos)
{
gsize n_suggs = 0;
@@ -119,7 +119,7 @@
}
-static gint speller_process_line(GeanyDocument *doc, gint line_number, const gchar *line)
+gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *line)
{
gint pos_start, pos_end;
gint wstart, wend;
@@ -210,7 +210,7 @@
{
line = sci_get_line(doc->editor->sci, i);
- suggestions_found += speller_process_line(doc, i, line);
+ suggestions_found += sc_speller_process_line(doc, i, line);
/* process other GTK events to keep the GUI being responsive */
while (g_main_context_iteration(NULL, FALSE));
Modified: trunk/spellcheck/src/speller.h
===================================================================
--- trunk/spellcheck/src/speller.h 2009-02-26 00:40:58 UTC (rev 511)
+++ trunk/spellcheck/src/speller.h 2009-02-27 20:30:12 UTC (rev 512)
@@ -27,8 +27,7 @@
#define SC_SPELLER_H 1
-gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gchar *word,
- gint start_pos, gint end_pos);
+gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *line);
void sc_speller_check_document(GeanyDocument *doc);
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