gtksourceview r2265 - in branches/gtksourcecompletion: . tests



Author: jessevdk
Date: Fri Apr 10 23:09:07 2009
New Revision: 2265
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2265&view=rev

Log:
	* tests/gsc-provider-devhelp.h:
	* tests/gsc-provider-devhelp.c:
	* tests/completion-simple.c:
	* tests/Makefile.am:
	* configure.ac:
	
	Added very basic devhelp provider, seems to work


Added:
   branches/gtksourcecompletion/tests/gsc-provider-devhelp.c
   branches/gtksourcecompletion/tests/gsc-provider-devhelp.h
Modified:
   branches/gtksourcecompletion/ChangeLog
   branches/gtksourcecompletion/configure.ac
   branches/gtksourcecompletion/tests/Makefile.am
   branches/gtksourcecompletion/tests/completion-simple.c

Modified: branches/gtksourcecompletion/configure.ac
==============================================================================
--- branches/gtksourcecompletion/configure.ac	(original)
+++ branches/gtksourcecompletion/configure.ac	Fri Apr 10 23:09:07 2009
@@ -64,6 +64,8 @@
 	gio-2.0
 	gtk+-2.0 >= $GTK_REQUIRED_VERSION
 	libxml-2.0 >= $LIBXML_REQUIRED_VERSION
+	libdevhelp-1.0
+	gconf-2.0
 ])
 
 # i18N stuff

Modified: branches/gtksourcecompletion/tests/Makefile.am
==============================================================================
--- branches/gtksourcecompletion/tests/Makefile.am	(original)
+++ branches/gtksourcecompletion/tests/Makefile.am	Fri Apr 10 23:09:07 2009
@@ -25,6 +25,8 @@
         completion-simple.c		\
         gsc-provider-test.h		\
         gsc-provider-test.c		\
+        gsc-provider-devhelp.h		\
+        gsc-provider-devhelp.c		\
 	gsc-utils-test.c		\
 	gsc-utils-test.h
 

Modified: branches/gtksourcecompletion/tests/completion-simple.c
==============================================================================
--- branches/gtksourcecompletion/tests/completion-simple.c	(original)
+++ branches/gtksourcecompletion/tests/completion-simple.c	Fri Apr 10 23:09:07 2009
@@ -28,8 +28,11 @@
 #include <gtksourceview/gtksourcecompletioninfo.h>
 #include <gtksourceview/gtksourcecompletiontriggerkey.h>
 
+#include <devhelp/dh-base.h>
+
 #include "gsc-utils-test.h"
 #include "gsc-provider-test.h"
+#include "gsc-provider-devhelp.h"
 
 #define TEST_PAGE "Page 3"
 #define FIXED_PAGE "Fixed"
@@ -311,11 +314,13 @@
 create_completion(void)
 {
 	GscProviderTest *prov_test;
+	GscProviderDevhelp *prov_devhelp;
 	GtkSourceCompletionTriggerKey *ur_trigger;
 	CustomWidget *custom;
 	GtkSourceCompletionInfo *info;
 	
 	prov_test = gsc_provider_test_new ();
+	prov_devhelp = gsc_provider_devhelp_new (GTK_SOURCE_VIEW (view));
 	
 	comp = gtk_source_view_get_completion (GTK_SOURCE_VIEW (view));
 	
@@ -328,6 +333,9 @@
 
 	gtk_source_completion_add_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_test),
 					    GTK_SOURCE_COMPLETION_TRIGGER (ur_trigger));
+
+	gtk_source_completion_add_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_devhelp),
+					    GTK_SOURCE_COMPLETION_TRIGGER (ur_trigger));
 	
 	g_signal_connect (comp, "show", G_CALLBACK (show_completion_cb), NULL);
 	g_signal_connect (comp, "hide", G_CALLBACK (hide_completion_cb), NULL);

Added: branches/gtksourcecompletion/tests/gsc-provider-devhelp.c
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/gsc-provider-devhelp.c	Fri Apr 10 23:09:07 2009
@@ -0,0 +1,107 @@
+#include "gsc-provider-devhelp.h"
+#include <devhelp/dh-base.h>
+#include <devhelp/dh-link.h>
+#include "gsc-utils-test.h"
+#include <gtksourceview/gtksourceview.h>
+#include <gtksourceview/gtksourcecompletionitem.h>
+
+#define GSC_PROVIDER_DEVHELP_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GSC_TYPE_PROVIDER_DEVHELP, GscProviderDevhelpPrivate))
+
+struct _GscProviderDevhelpPrivate
+{
+	GCompletion *completion;
+	GtkSourceView *view;
+};
+
+static void gsc_provider_devhelp_iface_init (GtkSourceCompletionProviderIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GscProviderDevhelp, 
+			 gsc_provider_devhelp, 
+			 G_TYPE_OBJECT,
+			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROVIDER,
+				 		gsc_provider_devhelp_iface_init))
+
+#define GSC_PROVIDER_DEVHELP_NAME "GscProviderDevhelp"
+
+static const gchar * 
+gsc_provider_devhelp_real_get_name (GtkSourceCompletionProvider *self)
+{
+	return GSC_PROVIDER_DEVHELP_NAME;
+}
+
+static GList * 
+gsc_provider_devhelp_real_get_proposals (GtkSourceCompletionProvider *base,
+				         GtkSourceCompletionTrigger  *trigger)
+{
+	GscProviderDevhelp *devhelp = GSC_PROVIDER_DEVHELP(base);
+	
+	gchar *word = gsc_get_last_word (GTK_TEXT_VIEW (devhelp->priv->view));
+	
+	GList *items = g_completion_complete (devhelp->priv->completion, word, NULL);
+	GList *ret = NULL;
+	
+	for (; items; items = g_list_next(items))
+	{
+		DhLink *link = (DhLink *)items->data;
+		ret = g_list_prepend(ret, gtk_source_completion_item_new (link->name, NULL, link->uri));
+	}
+
+	g_free(word);
+	
+	return g_list_reverse (ret);
+}
+
+static void
+gsc_provider_devhelp_iface_init (GtkSourceCompletionProviderIface *iface)
+{
+	iface->get_name = gsc_provider_devhelp_real_get_name;
+	iface->get_proposals = gsc_provider_devhelp_real_get_proposals;
+}
+
+static void
+gsc_provider_devhelp_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (gsc_provider_devhelp_parent_class)->finalize (object);
+}
+
+static void
+gsc_provider_devhelp_class_init (GscProviderDevhelpClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	object_class->finalize = gsc_provider_devhelp_finalize;
+
+	g_type_class_add_private (object_class, sizeof(GscProviderDevhelpPrivate));
+}
+
+static gchar *
+name_from_link (gpointer data)
+{
+	DhLink *link = (DhLink *)data;
+	
+	return link->name;
+}
+
+static void
+gsc_provider_devhelp_init (GscProviderDevhelp *self)
+{
+	self->priv = GSC_PROVIDER_DEVHELP_GET_PRIVATE (self);
+	
+	DhBase *base = dh_base_new ();
+	GList *keywords = dh_base_get_keywords (base);
+	
+	self->priv->completion = g_completion_new (name_from_link);
+	g_completion_add_items (self->priv->completion, keywords);
+	
+	g_list_free (keywords);
+	g_object_unref (base);
+}
+
+GscProviderDevhelp*
+gsc_provider_devhelp_new (GtkSourceView *view)
+{
+	GscProviderDevhelp *ret = g_object_new (GSC_TYPE_PROVIDER_DEVHELP, NULL);
+	ret->priv->view = view;
+	
+	return ret;
+}

Added: branches/gtksourcecompletion/tests/gsc-provider-devhelp.h
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/gsc-provider-devhelp.h	Fri Apr 10 23:09:07 2009
@@ -0,0 +1,37 @@
+#ifndef __GSC_PROVIDER_DEVHELP_H__
+#define __GSC_PROVIDER_DEVHELP_H__
+
+#include <gtksourceview/gtksourcecompletionprovider.h>
+#include <gtksourceview/gtksourceview.h>
+
+G_BEGIN_DECLS
+
+#define GSC_TYPE_PROVIDER_DEVHELP		(gsc_provider_devhelp_get_type ())
+#define GSC_PROVIDER_DEVHELP(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GSC_TYPE_PROVIDER_DEVHELP, GscProviderDevhelp))
+#define GSC_PROVIDER_DEVHELP_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GSC_TYPE_PROVIDER_DEVHELP, GscProviderDevhelp const))
+#define GSC_PROVIDER_DEVHELP_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GSC_TYPE_PROVIDER_DEVHELP, GscProviderDevhelpClass))
+#define GSC_IS_PROVIDER_DEVHELP(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSC_TYPE_PROVIDER_DEVHELP))
+#define GSC_IS_PROVIDER_DEVHELP_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GSC_TYPE_PROVIDER_DEVHELP))
+#define GSC_PROVIDER_DEVHELP_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GSC_TYPE_PROVIDER_DEVHELP, GscProviderDevhelpClass))
+
+typedef struct _GscProviderDevhelp		GscProviderDevhelp;
+typedef struct _GscProviderDevhelpClass		GscProviderDevhelpClass;
+typedef struct _GscProviderDevhelpPrivate	GscProviderDevhelpPrivate;
+
+struct _GscProviderDevhelp {
+	GObject parent;
+	
+	GscProviderDevhelpPrivate *priv;
+};
+
+struct _GscProviderDevhelpClass {
+	GObjectClass parent_class;
+};
+
+GType gsc_provider_devhelp_get_type (void) G_GNUC_CONST;
+GscProviderDevhelp *gsc_provider_devhelp_new (GtkSourceView *view);
+
+
+G_END_DECLS
+
+#endif /* __GSC_PROVIDER_DEVHELP_H__ */



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