[gedit-plugins] Added word completion plugin.



commit a566cc9d6bb8615ba362411d29094ec2428a02f3
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Oct 14 00:06:04 2009 +0200

    Added word completion plugin.

 configure.ac                                       |   12 +-
 plugins/wordcompletion/Makefile.am                 |   32 +++
 .../wordcompletion/gedit-word-completion-plugin.c  |  198 ++++++++++++++++++++
 .../wordcompletion/gedit-word-completion-plugin.h  |   69 +++++++
 .../wordcompletion.gedit-plugin.desktop.in.in      |    9 +
 po/POTFILES.in                                     |    4 +-
 6 files changed, 318 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 417144c..9b68676 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,9 +85,9 @@ GEDIT_HAS_PYTHON=1
 
 AC_MSG_CHECKING([which plugins to build])
 
-ALL_PLUGINS="bookmarks showtabbar charmap drawspaces"
-USEFUL_PLUGINS="bookmarks showtabbar charmap drawspaces"
-DEFAULT_PLUGINS="bookmarks showtabbar charmap drawspaces"
+ALL_PLUGINS="bookmarks showtabbar charmap drawspaces wordcompletion"
+USEFUL_PLUGINS="bookmarks showtabbar charmap drawspaces wordcompletion"
+DEFAULT_PLUGINS="bookmarks showtabbar charmap drawspaces wordcompletion"
 
 PYTHON_ALL_PLUGINS="bracketcompletion codecomment colorpicker joinlines sessionsaver smartspaces terminal"
 PYTHON_USEFUL_PLUGINS="bracketcompletion codecomment colorpicker joinlines sessionsaver smartspaces terminal"
@@ -113,8 +113,8 @@ AC_ARG_WITH([plugins],
 			  build the specified plugins. Available:
 			  bracketcompletion, charmap, codecomment,
 			  colorpicker, drawspaces, joinlines, showtabbar,
-			  sessionsaver, smartspaces,  terminal, as well
-			  as the aliases default, all, and really-all],
+			  sessionsaver, smartspaces,  terminal, wordcompletion,
+			  as well as the aliases default, all, and really-all],
 			  [plugins=$with_plugins],
 			  [plugins="default"])
 
@@ -434,6 +434,8 @@ plugins/smartspaces/Makefile
 plugins/smartspaces/smartspaces.gedit-plugin.desktop.in
 plugins/terminal/Makefile
 plugins/terminal/terminal.gedit-plugin.desktop.in
+plugins/wordcompletion/Makefile
+plugins/wordcompletion/wordcompletion.gedit-plugin.desktop.in
 po/Makefile.in])
 
 AC_OUTPUT
diff --git a/plugins/wordcompletion/Makefile.am b/plugins/wordcompletion/Makefile.am
new file mode 100644
index 0000000..4a79021
--- /dev/null
+++ b/plugins/wordcompletion/Makefile.am
@@ -0,0 +1,32 @@
+# Word Completion plugin
+plugindir = $(GEDIT_PLUGINS_LIBS_DIR)
+
+INCLUDES = \
+	-I$(top_srcdir) 				\
+	$(GEDIT_CFLAGS) 				\
+	$(WARN_CFLAGS)					\
+	$(DISABLE_DEPRECATED_CFLAGS)
+
+plugin_LTLIBRARIES = libwordcompletion.la
+
+libwordcompletion_la_SOURCES = \
+	gedit-word-completion-plugin.h				\
+	gedit-word-completion-plugin.c				
+
+libwordcompletion_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
+libwordcompletion_la_LIBADD = $(GEDIT_LIBS)
+
+# Plugin Info
+
+plugin_in_files = wordcompletion.gedit-plugin.desktop.in
+
+%.gedit-plugin: %.gedit-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+plugin_DATA = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
+
+EXTRA_DIST = $(plugin_in_files)
+
+CLEANFILES = $(plugin_DATA)
+DISTCLEANFILES = $(plugin_DATA)
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/wordcompletion/gedit-word-completion-plugin.c b/plugins/wordcompletion/gedit-word-completion-plugin.c
new file mode 100644
index 0000000..36811d1
--- /dev/null
+++ b/plugins/wordcompletion/gedit-word-completion-plugin.c
@@ -0,0 +1,198 @@
+/* 
+ * Copyright (C) 2009 Ignacio Casal Quinteiro <icq gnome org>
+ *               2009 Jesse van den Kieboom <jesse gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gedit-word-completion-plugin.h"
+
+#include <glib/gi18n-lib.h>
+#include <gedit/gedit-debug.h>
+#include <gedit/gedit-window.h>
+#include <gedit/gedit-view.h>
+#include <gedit/gedit-tab.h>
+#include <gtksourceview/gtksourcecompletionprovider.h>
+#include <gtksourceview/completion-providers/words/gtksourcecompletionwords.h>
+
+#define WINDOW_DATA_KEY "GeditWordCompletionPluginWindowData"
+
+GEDIT_PLUGIN_REGISTER_TYPE (GeditWordCompletionPlugin, gedit_word_completion_plugin)
+
+typedef struct
+{
+	GtkSourceCompletionWords *provider;
+	gulong tab_added_id;
+	gulong tab_removed_id;
+} WindowData;
+
+static void
+free_window_data (WindowData *data)
+{
+	g_return_if_fail (data != NULL);
+
+	g_object_unref (data->provider);
+	g_slice_free (WindowData, data);
+}
+
+static void
+gedit_word_completion_plugin_init (GeditWordCompletionPlugin *plugin)
+{
+	gedit_debug_message (DEBUG_PLUGINS, "GeditWordCompletionPlugin initializing");
+}
+
+static void
+gedit_word_completion_plugin_dispose (GObject *object)
+{
+	G_OBJECT_CLASS (gedit_word_completion_plugin_parent_class)->dispose (object);
+}
+
+static void
+add_view (WindowData    *data,
+	  GtkSourceView *view)
+{
+	GtkSourceCompletion *completion;
+	GtkTextBuffer *buf;
+	
+	completion = gtk_source_view_get_completion (view);
+	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+	
+	gtk_source_completion_add_provider (completion,
+					    GTK_SOURCE_COMPLETION_PROVIDER (data->provider),
+					    NULL);
+	gtk_source_completion_words_register (data->provider,
+					      buf);
+}
+
+static void
+remove_view (WindowData    *data,
+	     GtkSourceView *view)
+{
+	GtkSourceCompletion *completion;
+	GtkTextBuffer *buf;
+	
+	completion = gtk_source_view_get_completion (view);
+	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+	
+	gtk_source_completion_remove_provider (completion,
+					       GTK_SOURCE_COMPLETION_PROVIDER (data->provider),
+					       NULL);
+	gtk_source_completion_words_unregister (data->provider,
+						buf);
+}
+
+static void
+tab_added_cb (GeditWindow *window,
+	      GeditTab    *tab,
+	      gpointer     useless)
+{
+	GeditView *view;
+	WindowData *data;
+	
+	data = (WindowData *) g_object_get_data (G_OBJECT (window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+	
+	view = gedit_tab_get_view (tab);
+
+	add_view (data, GTK_SOURCE_VIEW (view));
+}
+
+static void
+tab_removed_cb (GeditWindow *window,
+		GeditTab    *tab,
+		gpointer     useless)
+{
+	GeditView *view;
+	WindowData *data;
+	
+	data = (WindowData *) g_object_get_data (G_OBJECT (window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+	
+	view = gedit_tab_get_view (tab);
+
+	remove_view (data, GTK_SOURCE_VIEW (view));
+}
+
+static void
+impl_activate (GeditPlugin *plugin,
+	       GeditWindow *window)
+{
+	WindowData *data;
+	GList *views, *l;
+
+	gedit_debug (DEBUG_PLUGINS);
+
+	data = g_slice_new (WindowData);
+	data->provider = gtk_source_completion_words_new (_("Document Words"),
+							  NULL);
+
+	views = gedit_window_get_views (window);
+	for (l = views; l != NULL; l = g_list_next (l))
+	{
+		add_view (data, GTK_SOURCE_VIEW (l->data));
+	}
+
+	g_object_set_data_full (G_OBJECT (window),
+				WINDOW_DATA_KEY,
+				data,
+				(GDestroyNotify) free_window_data);
+
+	data->tab_added_id =
+		g_signal_connect (window, "tab-added",
+				  G_CALLBACK (tab_added_cb),
+				  NULL);
+	data->tab_removed_id =
+		g_signal_connect (window, "tab-removed",
+				  G_CALLBACK (tab_removed_cb),
+				  NULL);
+}
+
+static void
+impl_deactivate	(GeditPlugin *plugin,
+		 GeditWindow *window)
+{
+	GeditWordCompletionPlugin *ds_plugin = GEDIT_WORD_COMPLETION_PLUGIN (plugin);
+	GtkUIManager *manager;
+	WindowData *data;
+
+	gedit_debug (DEBUG_PLUGINS);
+	
+	data = (WindowData *) g_object_get_data (G_OBJECT (window),
+						 WINDOW_DATA_KEY);
+	g_return_if_fail (data != NULL);
+	
+	g_signal_handler_disconnect (window, data->tab_added_id);
+	g_signal_handler_disconnect (window, data->tab_removed_id);
+	
+	g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
+}
+
+static void
+gedit_word_completion_plugin_class_init (GeditWordCompletionPluginClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
+
+	object_class->dispose = gedit_word_completion_plugin_dispose;
+
+	plugin_class->activate = impl_activate;
+	plugin_class->deactivate = impl_deactivate;
+}
diff --git a/plugins/wordcompletion/gedit-word-completion-plugin.h b/plugins/wordcompletion/gedit-word-completion-plugin.h
new file mode 100644
index 0000000..58fb01b
--- /dev/null
+++ b/plugins/wordcompletion/gedit-word-completion-plugin.h
@@ -0,0 +1,69 @@
+/* 
+ * Copyright (C) 2009 Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GEDIT_WORD_COMPLETION_PLUGIN_H__
+#define __GEDIT_WORD_COMPLETION_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gedit/gedit-plugin.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_WORD_COMPLETION_PLUGIN		(gedit_word_completion_plugin_get_type ())
+#define GEDIT_WORD_COMPLETION_PLUGIN(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_WORD_COMPLETION_PLUGIN, GeditWordCompletionPlugin))
+#define GEDIT_WORD_COMPLETION_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_WORD_COMPLETION_PLUGIN, GeditWordCompletionPluginClass))
+#define GEDIT_IS_WORD_COMPLETION_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GEDIT_TYPE_WORD_COMPLETION_PLUGIN))
+#define GEDIT_IS_WORD_COMPLETION_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_WORD_COMPLETION_PLUGIN))
+#define GEDIT_WORD_COMPLETION_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_WORD_COMPLETION_PLUGIN, GeditWordCompletionPluginClass))
+
+/*
+ * Main object structure
+ */
+typedef struct _GeditWordCompletionPlugin		GeditWordCompletionPlugin;
+
+struct _GeditWordCompletionPlugin
+{
+	GeditPlugin parent_instance;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _GeditWordCompletionPluginClass	GeditWordCompletionPluginClass;
+
+struct _GeditWordCompletionPluginClass
+{
+	GeditPluginClass parent_class;
+};
+
+/*
+ * Public methods
+ */
+GType	gedit_word_completion_plugin_get_type	(void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GEDIT_WORD_COMPLETION_PLUGIN_H__ */
diff --git a/plugins/wordcompletion/wordcompletion.gedit-plugin.desktop.in.in b/plugins/wordcompletion/wordcompletion.gedit-plugin.desktop.in.in
new file mode 100644
index 0000000..a236bab
--- /dev/null
+++ b/plugins/wordcompletion/wordcompletion.gedit-plugin.desktop.in.in
@@ -0,0 +1,9 @@
+[Gedit Plugin]
+Module=wordcompletion
+IAge=2
+_Name=Word Completion
+_Description=Word completion using the completion framework
+Authors=Jesse van den Kieboom <jesse gnome org>\nIgnacio Casal Quinteiro <icq gnome org>
+Copyright=Copyright © 2009 Jesse van den Kieboom
+Website=http://www.gedit.org
+Version= VERSION@
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8a31eb0..fee9f78 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,4 +22,6 @@ plugins/sessionsaver/sessionsaver.gedit-plugin.desktop.in.in
 plugins/smartspaces/smartspaces.gedit-plugin.desktop.in.in
 plugins/terminal/terminal.gedit-plugin.desktop.in.in
 plugins/terminal/terminal.py
-
+plugins/wordcompletion/gedit-word-completion-plugin.c
+plugins/wordcompletion/wordcompletion.gedit-plugin.desktop.in
+plugins/wordcompletion/wordcompletion.gedit-plugin.desktop.in.in



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