Re: [gedit-list] enable spell check on startup ( improved )
- From: Ritesh Khadgaray <khadgaray gmail com>
- To: Trond Danielsen <trond danielsen gmail com>
- Cc: gedit-list gnome org
- Subject: Re: [gedit-list] enable spell check on startup ( improved )
- Date: Sun, 18 Mar 2007 15:49:12 +0530
Heya,
An improved version, which sucks less and is a rip of mode-line. Now,
all i need is configuration UI for the plugin, and a schema .
On Wed, 2007-01-03 at 12:41 +0100, Trond Danielsen wrote:
> Hi!
>
> This is not possible at the moment, but it should be simple to add
> this option to the plugin. If you are up for hacking, you can take a
> look at gedit-spell-plugin.c (line 93 :) ).
>
> 2007/1/3, Ritesh Khadgaray <khadgaray gmail com>:
> > Heya,
> >
> > Is it possible to enable spell check on startup, and not manually via
> > Tool->Spell check every time i start gedit ?
> >
> > --
> > Ritesh Khadgaray
> > LinuX N Stuff
> > Ph: +919822394463
> > Eat Right, Exercise, Die Anyway.
> >
> >
> > _______________________________________________
> > gedit-list mailing list
> > gedit-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gedit-list
> >
> >
> >
> >
>
>
--
Ritesh Khadgaray
ॐ मणि पद्मे हूँ
LinuX N Stuff
Ph: +919243176435
Eat Right, Exercise, Die Anyway.
--- gedit-spell-plugin.c.orig 2007-03-18 15:46:25.000000000 +0530
+++ gedit-spell-plugin.c 2007-03-18 15:46:11.000000000 +0530
@@ -20,6 +20,14 @@
* $Id: gedit-spell-plugin.c 5335 2006-12-04 00:31:27Z paolo $
*/
+
+/*
+ * To Do - Write a schema, and probably add a UI ?
+ * As a temporary work to enable auto-init of spell check
+ * gconftool-2 --type bool --set /apps/gedit-2/plugins/spellcheck/value true
+ *
+ */
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -38,6 +46,8 @@
#include <gedit/gedit-metadata-manager.h>
#include <gedit/gedit-prefs-manager.h>
#include <gedit/gedit-statusbar.h>
+#include <gconf/gconf-client.h>
+
#include "gedit-spell-checker.h"
#include "gedit-spell-checker-dialog.h"
@@ -46,6 +56,7 @@
#define WINDOW_DATA_KEY "GeditSpellPluginWindowData"
#define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1"
+#define SPELL_BROWSER_BASE_KEY "/apps/gedit-2/plugins/spellcheck/"
#define GEDIT_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_SPELL_PLUGIN, GeditSpellPluginPrivate))
@@ -823,6 +834,86 @@
g_free (data);
}
+
+static void
+on_document_loaded_or_saved (GeditDocument *document,
+ const GError *error,
+ GeditView *view)
+{
+ g_warning("on_document_loaded_or_saved");
+
+ GeditAutomaticSpellChecker *autospell;
+ GeditSpellChecker *spell;
+ gboolean active;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
+
+ if (document == NULL)
+ return;
+
+ spell = get_spell_checker_from_document (document);
+ g_return_if_fail (spell != NULL);
+
+ autospell = gedit_automatic_spell_checker_get_from_document (document);
+
+ if (autospell == NULL)
+ {
+ g_return_if_fail (view != NULL);
+
+ autospell = gedit_automatic_spell_checker_new (document, spell);
+ gedit_automatic_spell_checker_attach_view (autospell, view);
+ gedit_automatic_spell_checker_recheck_all (autospell);
+ }
+
+}
+
+
+static void
+connect_handlers (GeditView *view)
+{
+ GtkTextBuffer *doc;
+
+ doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+
+ g_signal_connect (doc, "loaded",
+ G_CALLBACK (on_document_loaded_or_saved),
+ view);
+ g_signal_connect (doc, "saved",
+ G_CALLBACK (on_document_loaded_or_saved),
+ view);
+}
+
+static void
+on_window_tab_added (GeditWindow *window,
+ GeditTab *tab,
+ gpointer user_data)
+{
+ g_warning("on_window_tab_added");
+ connect_handlers (gedit_tab_get_view (tab));
+}
+
+static void
+on_window_new_tab_added (GeditWindow *window,
+ GeditTab *tab,
+ gpointer user_data)
+{
+ g_warning("on_window_new_tab_added");
+ on_document_loaded_or_saved(gedit_tab_get_document(tab),
+ NULL,
+ gedit_tab_get_view(tab));
+}
+static void
+on_window_tab_removed (GeditWindow *window,
+ GeditTab *tab,
+ gpointer user_data)
+{
+ g_signal_handlers_disconnect_by_func(gedit_tab_get_document(tab),
+ on_document_loaded_or_saved,NULL);
+}
+
+
static void
update_ui_real (GeditWindow *window,
WindowData *data)
@@ -909,6 +1000,30 @@
GTK_UI_MANAGER_MENUITEM,
FALSE);
+ /* routine to init spell check
+ * borrowed without permission from mode-line
+ */
+ GConfClient *client= gconf_client_get_default();
+ gboolean check = gconf_client_get_bool(client,SPELL_BROWSER_BASE_KEY "value",NULL);
+ g_object_unref(client);
+ if ( check == TRUE )
+ {
+ GList *views;
+ GList *l;
+
+ views = gedit_window_get_views (window);
+ for (l = views; l != NULL; l = l->next)
+ {
+ connect_handlers (GEDIT_VIEW (l->data));
+ }
+ g_list_free (views);
+
+ g_signal_connect (window, "tab-added",
+ G_CALLBACK (on_window_new_tab_added), NULL);
+
+ g_signal_connect (window, "tab-removed",
+ G_CALLBACK (on_window_tab_removed), NULL);
+ }
update_ui_real (window, data);
@@ -932,6 +1047,23 @@
gtk_ui_manager_remove_action_group (manager, data->action_group);
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
+
+ /*
+ * callback un-register . Modeled after mode-line plugin
+ * monkey see, monkey do -- khadgaray
+ */
+ GList *doc;
+ GList *l;
+
+ doc = gedit_window_get_documents (window);
+ for (l = doc; l != NULL; l = l->next)
+ {
+ g_signal_handlers_disconnect_by_func (GEDIT_DOCUMENT (l->data),
+ on_document_loaded_or_saved,NULL);
+ }
+ g_list_free (doc);
+
+ g_signal_handlers_disconnect_by_func(window,on_window_new_tab_added,NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]