[geany/geany-plugins] 1ea550: Merge pull request #353 from b4n/spellcheck/less-deprecated
Enrico Tröger
git-noreply at xxxxx
Sun Feb 21 13:59:45 UTC 2016
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger at uvena.de>
Committer: Enrico Tröger <enrico.troeger at uvena.de>
Date: Sun, 21 Feb 2016 13:59:45 UTC
Commit: 1ea550bc9d12884b3f90d7b49da9b943c6633672
https://github.com/geany/geany-plugins/commit/1ea550bc9d12884b3f90d7b49da9b943c6633672
Log Message:
-----------
Merge pull request #353 from b4n/spellcheck/less-deprecated
Spellcheck: Less deprecated stuff and various improvements on the way
Modified Paths:
--------------
spellcheck/src/gui.c
spellcheck/src/scplugin.c
spellcheck/src/speller.c
spellcheck/src/speller.h
Modified: spellcheck/src/gui.c
31 lines changed, 12 insertions(+), 19 deletions(-)
===================================================================
@@ -156,8 +156,7 @@ static void menu_suggestion_item_activate_cb(GtkMenuItem *menuitem, gpointer gda
sci_set_selection_end(sci, endword);
/* retrieve the old text */
- word = g_malloc(sci_get_selected_text_length(sci) + 1);
- sci_get_selected_text(sci, word);
+ word = sci_get_selection_contents(sci);
/* retrieve the new text */
sugg = gtk_label_get_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))));
@@ -180,8 +179,8 @@ static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
{
gint startword, endword, i, doc_len;
ScintillaObject *sci;
- GString *str;
gboolean ignore = GPOINTER_TO_INT(gdata);
+ gint click_word_len;
if (clickinfo.doc == NULL || clickinfo.word == NULL || clickinfo.pos == -1)
return;
@@ -196,7 +195,7 @@ static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
/* Remove all indicators on the added/ignored word */
sci = clickinfo.doc->editor->sci;
- str = g_string_sized_new(256);
+ click_word_len = (gint) strlen(clickinfo.word);
doc_len = sci_get_length(sci);
for (i = 0; i < doc_len; i++)
{
@@ -207,17 +206,18 @@ static void menu_addword_item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
if (startword == endword)
continue;
- if (str->len < (guint)(endword - startword + 1))
- str = g_string_set_size(str, endword - startword + 1);
- sci_get_text_range(sci, startword, endword, str->str);
+ if (click_word_len == endword - startword)
+ {
+ const gchar *ptr = (const gchar *) scintilla_send_message(sci,
+ SCI_GETRANGEPOINTER, startword, endword - startword);
- if (strcmp(str->str, clickinfo.word) == 0)
- sci_indicator_clear(sci, startword, endword - startword);
+ if (strncmp(ptr, clickinfo.word, click_word_len) == 0)
+ sci_indicator_clear(sci, startword, endword - startword);
+ }
i = endword;
}
}
- g_string_free(str, TRUE);
}
@@ -420,11 +420,7 @@ void sc_gui_update_editor_menu_cb(GObject *obj, const gchar *word, gint pos,
/* if we have a selection, prefer it over the current word */
if (sci_has_selection(doc->editor->sci))
- {
- gint len = sci_get_selected_text_length(doc->editor->sci);
- search_word = g_malloc(len + 1);
- sci_get_selected_text(doc->editor->sci, search_word);
- }
+ search_word = sci_get_selection_contents(doc->editor->sci);
else
search_word = g_strdup(word);
@@ -502,21 +498,18 @@ static gboolean check_lines(gpointer data)
/* since we're in an timeout callback, the document may have been closed */
if (DOC_VALID (doc))
{
- gchar *line;
gint line_number = check_line_data.line_number;
gint line_count = check_line_data.line_count;
gint i;
for (i = 0; i < line_count; i++)
{
- 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_speller_process_line(doc, line_number) != 0)
{
if (sc_info->use_msgwin)
msgwin_switch_tab(MSG_MESSAGE, FALSE);
}
- g_free(line);
line_number++;
}
}
Modified: spellcheck/src/scplugin.c
11 lines changed, 6 insertions(+), 5 deletions(-)
===================================================================
@@ -61,7 +61,6 @@ enum
KB_SPELL_TOOGLE_TYPING,
KB_COUNT
};
-PLUGIN_KEY_GROUP(spellcheck, KB_COUNT)
@@ -173,6 +172,7 @@ static void configure_response_cb(GtkDialog *dialog, gint response, gpointer use
void plugin_init(GeanyData *data)
{
+ GeanyKeyGroup *key_group;
GKeyFile *config = g_key_file_new();
gchar *default_lang;
@@ -214,9 +214,10 @@ void plugin_init(GeanyData *data)
gtk_widget_show_all(sc_info->menu_item);
/* setup keybindings */
- keybindings_set_item(plugin_key_group, KB_SPELL_CHECK, sc_gui_kb_run_activate_cb,
+ key_group = plugin_set_key_group(geany_plugin, "spellcheck", KB_COUNT, NULL);
+ keybindings_set_item(key_group, KB_SPELL_CHECK, sc_gui_kb_run_activate_cb,
0, 0, "spell_check", _("Run Spell Check"), sc_info->submenu_item_default);
- keybindings_set_item(plugin_key_group, KB_SPELL_TOOGLE_TYPING,
+ keybindings_set_item(key_group, KB_SPELL_TOOGLE_TYPING,
sc_gui_kb_toggle_typing_activate_cb, 0, 0, "spell_toggle_typing",
_("Toggle Check While Typing"), NULL);
}
@@ -327,7 +328,7 @@ GtkWidget *plugin_configure(GtkDialog *dialog)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_type), sc_info->check_while_typing);
check_on_open = gtk_check_button_new_with_label(_("Check spelling when opening a document"));
- ui_widget_set_tooltip_text(check_on_open,
+ gtk_widget_set_tooltip_text(check_on_open,
_("Enabling this option will check every document after it is opened in Geany. "
"Reloading a document will also trigger a re-check."));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_on_open), sc_info->check_on_document_open);
@@ -350,7 +351,7 @@ GtkWidget *plugin_configure(GtkDialog *dialog)
entry_dir = gtk_entry_new();
ui_entry_add_clear_icon(GTK_ENTRY(entry_dir));
gtk_label_set_mnemonic_widget(GTK_LABEL(label_dir), entry_dir);
- ui_widget_set_tooltip_text(entry_dir,
+ gtk_widget_set_tooltip_text(entry_dir,
_("Read additional dictionary files from this directory. "
"For now, this only works with myspell dictionaries."));
if (! EMPTY(sc_info->dictionary_dir))
Modified: spellcheck/src/speller.c
34 lines changed, 11 insertions(+), 23 deletions(-)
===================================================================
@@ -95,7 +95,7 @@ static gchar *strip_word(const gchar *word_to_check, gint *result_offset)
g_memmove(word_start, word, new_word_len);
word = word_start;
word[new_word_len] = '\0';
- if (! NZV(word))
+ if (EMPTY(word))
{
g_free(word);
return NULL;
@@ -146,7 +146,7 @@ static gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gc
/* strip punctuation and white space */
word_to_check = strip_word(word, &offset);
- if (! NZV(word_to_check))
+ if (EMPTY(word_to_check))
{
g_free(word_to_check);
return 0;
@@ -199,18 +199,16 @@ static gint sc_speller_check_word(GeanyDocument *doc, gint line_number, const gc
}
-gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *line)
+gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
{
gint pos_start, pos_end;
gint wstart, wend;
gint suggestions_found = 0;
gint wordchars_len;
gchar *wordchars;
- GString *str;
g_return_val_if_fail(sc_speller_dict != NULL, 0);
g_return_val_if_fail(doc != NULL, 0);
- g_return_val_if_fail(line != NULL, 0);
/* add ' (single quote) temporarily to wordchars
* to be able to check for "doesn't", "isn't" and similar */
@@ -224,27 +222,25 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *
scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
}
- str = g_string_sized_new(256);
-
pos_start = sci_get_position_from_line(doc->editor->sci, line_number);
pos_end = sci_get_position_from_line(doc->editor->sci, line_number + 1);
while (pos_start < pos_end)
{
+ gchar *word;
+
wstart = scintilla_send_message(doc->editor->sci, SCI_WORDSTARTPOSITION, pos_start, TRUE);
wend = scintilla_send_message(doc->editor->sci, SCI_WORDENDPOSITION, wstart, FALSE);
if (wstart == wend)
break;
- /* ensure the string has enough allocated memory */
- if (str->len < (guint)(wend - wstart))
- g_string_set_size(str, wend - wstart);
-
- sci_get_text_range(doc->editor->sci, wstart, wend, str->str);
+ word = sci_get_contents_range(doc->editor->sci, wstart, wend);
- suggestions_found += sc_speller_check_word(doc, line_number, str->str, wstart, wend);
+ suggestions_found += sc_speller_check_word(doc, line_number, word, wstart, wend);
pos_start = wend + 1;
+
+ g_free(word);
}
/* reset wordchars for the current document */
@@ -252,14 +248,12 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *
scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
g_free(wordchars);
- g_string_free(str, TRUE);
return suggestions_found;
}
void sc_speller_check_document(GeanyDocument *doc)
{
- gchar *line;
gint i;
gint first_line, last_line;
gchar *dict_string = NULL;
@@ -299,22 +293,16 @@ void sc_speller_check_document(GeanyDocument *doc)
if (first_line == last_line)
{
- line = sci_get_selection_contents(doc->editor->sci);
- suggestions_found += sc_speller_process_line(doc, first_line, line);
- g_free(line);
+ suggestions_found += sc_speller_process_line(doc, first_line);
}
else
{
for (i = first_line; i < last_line; i++)
{
- line = sci_get_line(doc->editor->sci, i);
-
- suggestions_found += sc_speller_process_line(doc, i, line);
+ suggestions_found += sc_speller_process_line(doc, i);
/* process other GTK events to keep the GUI being responsive */
while (g_main_context_iteration(NULL, FALSE));
-
- g_free(line);
}
}
if (suggestions_found == 0 && sc_info->use_msgwin)
Modified: spellcheck/src/speller.h
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -27,7 +27,7 @@
#define SC_SPELLER_H 1
-gint sc_speller_process_line(GeanyDocument *doc, gint line_number, const gchar *line);
+gint sc_speller_process_line(GeanyDocument *doc, gint line_number);
void sc_speller_check_document(GeanyDocument *doc);
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list