[gedit-list] [PATCH] Re: enable spell check on startup ( improved )



heya,

  Schema file added. Where should i plugin a configuration UI, if at i
must ?


On Sun, 2007-03-18 at 15:49 +0530, Ritesh Khadgaray wrote:
> 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.
-- 
Ritesh Khadgaray
ॐ मणि पद्मे हूँ
LinuX N Stuff
Ph: +919243176435
Eat Right, Exercise, Die Anyway.
diff -Naur spell/gedit-spell-plugin.c spell.orig/gedit-spell-plugin.c
--- spell/gedit-spell-plugin.c	2007-03-20 06:02:07.000000000 +0530
+++ spell.orig/gedit-spell-plugin.c	2007-03-20 06:06:47.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,71 @@
 	g_free (data);
 }
 
+
+static void
+on_document_load (GeditDocument *document,
+			     const GError  *error,
+			     GeditView *view)
+{
+	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_load),
+		  view);
+}
+
+static void
+on_window_tab_added (GeditWindow *window,
+		     GeditTab *tab,
+		     gpointer user_data)
+{
+	on_document_load (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_load,NULL);
+}
+
+
 static void
 update_ui_real (GeditWindow *window,
 		WindowData *data)
@@ -909,6 +985,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_tab_added), NULL);
+		
+		g_signal_connect (window, "tab-removed",
+				  G_CALLBACK (on_window_tab_removed), NULL);
+	}
 	
 
 	update_ui_real (window, data);
@@ -932,6 +1032,24 @@
 	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, monkey cleans -- 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_load, NULL);
+	}
+	g_list_free (doc);
+	
+	g_signal_handlers_disconnect_by_func(window,on_window_tab_added, NULL);
+	g_signal_handlers_disconnect_by_func(window,on_window_tab_removed, NULL);
 }
 
 static void
diff -Naur spell/gedit-spell-plugin.schemas.in spell.orig/gedit-spell-plugin.schemas.in
--- spell/gedit-spell-plugin.schemas.in	1970-01-01 05:30:00.000000000 +0530
+++ spell.orig/gedit-spell-plugin.schemas.in	2007-03-20 05:00:18.000000000 +0530
@@ -0,0 +1,15 @@
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/gedit-2/plugins/spellcheck/value</key>
+      <applyto>/apps/gedit-2/plugins/spellcheck/value</applyto>
+      <owner>gedit</owner>
+      <type>bool</type>
+      <default>FALSE</default>
+      <locale name="C">
+	<short>Auto initialize spell-check</short>
+	<long>Enables spell-check for new document, and on document load</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>
diff -Naur spell/Makefile.am spell.orig/Makefile.am
--- spell/Makefile.am	2007-03-20 06:02:07.000000000 +0530
+++ spell.orig/Makefile.am	2007-03-20 05:18:14.000000000 +0530
@@ -52,12 +52,33 @@
 
 plugin_DATA = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
 
+schemasdir	 = $(GCONF_SCHEMA_FILE_DIR)
+schemas_in_files = gedit-spell-plugin.schemas.in
+schemas_DATA 	 = $(schemas_in_files:.schemas.in=.schemas)
+ INTLTOOL_SCHEMAS_RULE@
+
+if GCONF_SCHEMAS_INSTALL
+install-data-local:
+	        if test -z "$(DESTDIR)" ; then \
+	                for p in $(schemas_DATA) ; do \
+	                        GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/plugins/spell/$$p ; \
+	                done \
+	        fi
+else
+install-data-local:
+endif
+
+
 EXTRA_DIST = 					\
 	$(glade_DATA)				\
 	$(plugin_in_files)			\
+	$(schemas_in_files)			\
 	gedit-spell-checker-dialog-marshal.list 
 
-CLEANFILES = $(BUILT_SOURCES) $(plugin_DATA)
+CLEANFILES = \
+	$(BUILT_SOURCES)	\
+	$(plugin_DATA)	\
+	$(schemas_DATA)		
 
 dist-hook:
 	cd $(distdir); rm -f $(BUILT_SOURCES)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]