Skip to content

Commit

Permalink
Add option to perform a spell check on document open (closes SF #137)
Browse files Browse the repository at this point in the history
  • Loading branch information
eht16 committed Sep 28, 2014
1 parent f59d60f commit 5a94d95
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spellcheck/src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ static void perform_spell_check_cb(GtkWidget *menu_item, GeanyDocument *doc)
}


static gboolean perform_check_delayed_cb(gpointer doc)
{
perform_check((GeanyDocument*)doc);
return FALSE;
}


void sc_gui_document_open_cb(GObject *obj, GeanyDocument *doc, gpointer user_data)
{
if (sc_info->check_on_document_open && main_is_realized())
g_idle_add(perform_check_delayed_cb, doc);
}


void sc_gui_update_editor_menu_cb(GObject *obj, const gchar *word, gint pos,
GeanyDocument *doc, gpointer user_data)
{
Expand Down
2 changes: 2 additions & 0 deletions spellcheck/src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void sc_gui_update_editor_menu_cb(GObject *obj, const gchar *word, gint pos,
gboolean sc_gui_editor_notify(GObject *object, GeanyEditor *editor,
SCNotification *nt, gpointer data);

void sc_gui_document_open_cb(GObject *obj, GeanyDocument *doc, gpointer user_data);

void sc_gui_update_toolbar(void);

void sc_gui_update_menu(void);
Expand Down
21 changes: 19 additions & 2 deletions spellcheck/src/scplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ PLUGIN_KEY_GROUP(spellcheck, KB_COUNT)
PluginCallback plugin_callbacks[] =
{
{ "update-editor-menu", (GCallback) &sc_gui_update_editor_menu_cb, FALSE, NULL },
{ "editor-notify", (GCallback) &sc_gui_editor_notify, FALSE, NULL },
{ "document-open", (GCallback) &sc_gui_document_open_cb, FALSE, NULL },
{ "document-reload", (GCallback) &sc_gui_document_open_cb, FALSE, NULL },
{ NULL, NULL, FALSE, NULL }
};

Expand Down Expand Up @@ -112,6 +113,9 @@ static void configure_response_cb(GtkDialog *dialog, gint response, gpointer use
sc_info->check_while_typing = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
g_object_get_data(G_OBJECT(dialog), "check_type"))));

sc_info->check_on_document_open = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
g_object_get_data(G_OBJECT(dialog), "check_on_open"))));

sc_info->use_msgwin = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
g_object_get_data(G_OBJECT(dialog), "check_msgwin"))));

Expand All @@ -126,6 +130,8 @@ static void configure_response_cb(GtkDialog *dialog, gint response, gpointer use
g_key_file_set_string(config, "spellcheck", "language", sc_info->default_language);
g_key_file_set_boolean(config, "spellcheck", "check_while_typing",
sc_info->check_while_typing);
g_key_file_set_boolean(config, "spellcheck", "check_on_document_open",
sc_info->check_on_document_open);
g_key_file_set_boolean(config, "spellcheck", "use_msgwin",
sc_info->use_msgwin);
g_key_file_set_boolean(config, "spellcheck", "show_toolbar_item",
Expand Down Expand Up @@ -175,6 +181,8 @@ void plugin_init(GeanyData *data)
"spellcheck", "language", default_lang);
sc_info->check_while_typing = utils_get_setting_boolean(config,
"spellcheck", "check_while_typing", FALSE);
sc_info->check_on_document_open = utils_get_setting_boolean(config,
"spellcheck", "check_on_document_open", FALSE);
sc_info->show_toolbar_item = utils_get_setting_boolean(config,
"spellcheck", "show_toolbar_item", TRUE);
sc_info->show_editor_menu_item = utils_get_setting_boolean(config,
Expand Down Expand Up @@ -243,7 +251,8 @@ static void dictionary_dir_button_clicked_cb(GtkButton *button, gpointer item)

GtkWidget *plugin_configure(GtkDialog *dialog)
{
GtkWidget *label, *vbox, *combo, *check_type, *check_msgwin, *check_toolbar, *check_editor_menu;
GtkWidget *label, *vbox, *combo, *check_type, *check_on_open,
*check_msgwin, *check_toolbar, *check_editor_menu;
#ifdef HAVE_ENCHANT_1_5
GtkWidget *entry_dir, *hbox, *button, *image;
#endif
Expand All @@ -254,6 +263,13 @@ GtkWidget *plugin_configure(GtkDialog *dialog)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_type), sc_info->check_while_typing);
gtk_box_pack_start(GTK_BOX(vbox), check_type, FALSE, FALSE, 6);

check_on_open = gtk_check_button_new_with_label(_("Check spelling when opening a document"));
ui_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);
gtk_box_pack_start(GTK_BOX(vbox), check_on_open, FALSE, FALSE, 6);

check_toolbar = gtk_check_button_new_with_label(
_("Show toolbar item to toggle spell checking"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_toolbar), sc_info->show_toolbar_item);
Expand Down Expand Up @@ -314,6 +330,7 @@ GtkWidget *plugin_configure(GtkDialog *dialog)
#endif
g_object_set_data(G_OBJECT(dialog), "combo", combo);
g_object_set_data(G_OBJECT(dialog), "check_type", check_type);
g_object_set_data(G_OBJECT(dialog), "check_on_open", check_on_open);
g_object_set_data(G_OBJECT(dialog), "check_msgwin", check_msgwin);
g_object_set_data(G_OBJECT(dialog), "check_toolbar", check_toolbar);
g_object_set_data(G_OBJECT(dialog), "check_editor_menu", check_editor_menu);
Expand Down
1 change: 1 addition & 0 deletions spellcheck/src/scplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct
gchar *dictionary_dir;
gboolean use_msgwin;
gboolean check_while_typing;
gboolean check_on_document_open;
gboolean show_toolbar_item;
gboolean show_editor_menu_item;
GPtrArray *dicts;
Expand Down

0 comments on commit 5a94d95

Please sign in to comment.