[anjuta/gtksourcecompletion: 3/3] Add the devhelp provider and fix the bugs to make it work.



commit 8500ac6a9e09dc6a0ba6773ceaebe88f0f835129
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun May 17 22:37:41 2009 +0200

    Add the devhelp provider and fix the bugs to make it work.
---
 libanjuta/interfaces/libanjuta.idl      |   45 ++++----
 plugins/devhelp/Makefile.am             |    4 +-
 plugins/devhelp/gsc-provider-devhelp.c  |  193 +++++++++++++++++++++++++++++++
 plugins/devhelp/gsc-provider-devhelp.h  |   59 ++++++++++
 plugins/devhelp/plugin.c                |   11 ++-
 plugins/devhelp/plugin.h                |    1 +
 plugins/sourceview/sourceview-private.h |    1 +
 plugins/sourceview/sourceview.c         |   26 ++++-
 8 files changed, 315 insertions(+), 25 deletions(-)

diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index b69deed..ea40fd6 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -1173,6 +1173,30 @@ interface IAnjutaDocument
 		void clear ();
 }
 
+interface IAnjutaEditorAssistProvider
+{
+	#include <gtk/gtk.h>
+	#include <libanjuta/interfaces/ianjuta-iterable.h>
+
+	struct Proposal
+	{
+		gchar *label;
+		gchar *text;
+		GdkPixbuf *pixbuf;
+		gchar *info;
+	}
+	
+	const gchar *get_name ();
+	
+	GdkPixbuf *get_icon ();
+	
+	List<AnjutaEditorAssistProviderProposal *> get_proposals (IAnjutaIterable *position);
+	
+	GtkWidget *get_info_widget (IAnjutaEditorAssistProviderProposal *proposal);
+	
+	void update_info (IAnjutaEditorAssistProviderProposal *proposal, GtkWidget *info);
+}
+
 /**
  * SECTION:ianjuta-editor
  * @title: IAnjutaEditor
@@ -1872,27 +1896,6 @@ interface IAnjutaEditor
 		void fix ();
 	}
 	
-	interface IAnjutaEditorAssistProvider
-	{
-		struct Proposal
-		{
-			gchar *label;
-			gchar *text;
-			GdkPixbuf *pixbuf;
-			gchar *info;
-		}
-		
-		const gchar *get_name ();
-		
-		GdkPixbuf *get_icon ();
-		
-		List<AnjutaEditorAssistProviderProposal *> get_proposals (IAnjutaIterable *position);
-		
-		GtkWidget *get_info_widget (IAnjutaEditorAssistProviderProposal *proposal);
-		
-		void update_info (IAnjutaEditorAssistProviderProposal *proposal, GtkWidget *info);
-	}
-	
 	/**
 	 * SECTION:ianjuta-editor-assist
 	 * @title: IAnjutaEditorAssist
diff --git a/plugins/devhelp/Makefile.am b/plugins/devhelp/Makefile.am
index ecd4daf..3843d5e 100644
--- a/plugins/devhelp/Makefile.am
+++ b/plugins/devhelp/Makefile.am
@@ -40,7 +40,9 @@ libanjuta_devhelp_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 # Plugin sources
 libanjuta_devhelp_la_SOURCES = \
 	plugin.c \
-	plugin.h
+	plugin.h \
+	gsc-provider-devhelp.c \
+	gsc-provider-devhelp.h
 
 # Plugin dependencies
 libanjuta_devhelp_la_LIBADD = \
diff --git a/plugins/devhelp/gsc-provider-devhelp.c b/plugins/devhelp/gsc-provider-devhelp.c
new file mode 100644
index 0000000..5b158df
--- /dev/null
+++ b/plugins/devhelp/gsc-provider-devhelp.c
@@ -0,0 +1,193 @@
+/*
+ * gsc-provider-devhelp.c
+ * This file is part of anjuta
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * anjuta 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 of the License, or
+ * (at your option) any later version.
+ *
+ * anjuta 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 anjuta; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+
+#include "gsc-provider-devhelp.h"
+#include <devhelp/dh-link.h>
+#include <devhelp/dh-assistant-view.h>
+#include <libanjuta/interfaces/ianjuta-editor-assist-provider.h>
+
+#define GSC_PROVIDER_DEVHELP_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GSC_TYPE_PROVIDER_DEVHELP, GscProviderDevhelpPrivate))
+
+struct _GscProviderDevhelpPrivate
+{
+	DhBase *dhbase;
+	GtkWidget *view;
+
+	GList *proposals;
+};
+
+static void gsc_provider_devhelp_iface_init (IAnjutaEditorAssistProviderIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GscProviderDevhelp, 
+			 gsc_provider_devhelp, 
+			 G_TYPE_OBJECT,
+			 G_IMPLEMENT_INTERFACE (IANJUTA_TYPE_EDITOR_ASSIST_PROVIDER,
+				 		gsc_provider_devhelp_iface_init))
+
+static const gchar * 
+gsc_provider_devhelp_get_name (IAnjutaEditorAssistProvider *self,
+							   GError **error)
+{
+	return "Devhelp";
+}
+
+static GList * 
+gsc_provider_devhelp_get_proposals (IAnjutaEditorAssistProvider *provider,
+                                    IAnjutaIterable             *iter,
+                                    GError **error)
+{
+	GscProviderDevhelp *devhelp = GSC_PROVIDER_DEVHELP (provider);
+
+	return devhelp->priv->proposals;
+}
+/*
+static gboolean
+gsc_provider_devhelp_filter_proposal (IAnjutaEditorAssistProvider *provider,
+                                      IAnjutaEditorAssistProviderProposal *proposal,
+                                      GtkTextIter                 *iter,
+                                      const gchar                 *criteria)
+{
+	const gchar *item;
+	
+	item = gtk_source_completion_proposal_get_label (proposal);
+	return g_str_has_prefix (item, criteria);
+}*/
+/*
+static gboolean
+gsc_provider_devhelp_get_interactive(IAnjutaEditorAssistProvider *provider)
+{
+	return TRUE;
+}*/
+
+static GtkWidget *
+gsc_provider_devhelp_get_info_widget (IAnjutaEditorAssistProvider *provider,
+									  IAnjutaEditorAssistProviderProposal *proposal,
+									  GError **err)
+{
+	return GSC_PROVIDER_DEVHELP (provider)->priv->view;
+}
+
+static void
+gsc_provider_devhelp_update_info (IAnjutaEditorAssistProvider *provider,
+                                  IAnjutaEditorAssistProviderProposal *proposal,
+                                  GtkWidget *info,
+                                  GError **error)
+{
+	dh_assistant_view_search (DH_ASSISTANT_VIEW (info), proposal->label);
+}
+
+static GdkPixbuf *
+gsc_provider_devhelp_get_icon (IAnjutaEditorAssistProvider *obj, GError **err)
+{
+	return NULL;
+}
+
+static void
+gsc_provider_devhelp_iface_init (IAnjutaEditorAssistProviderIface *iface)
+{
+	iface->get_name = gsc_provider_devhelp_get_name;
+	iface->get_proposals = gsc_provider_devhelp_get_proposals;
+	iface->get_icon = gsc_provider_devhelp_get_icon;
+	
+	iface->get_info_widget = gsc_provider_devhelp_get_info_widget;
+	iface->update_info = gsc_provider_devhelp_update_info;
+}
+
+static void
+free_proposal (gpointer data)
+{
+	IAnjutaEditorAssistProviderProposal *proposal = (IAnjutaEditorAssistProviderProposal *)data;
+	
+	g_free (proposal->label);
+	g_free (proposal->info);
+	g_slice_free (IAnjutaEditorAssistProviderProposal, proposal);
+}
+
+static void
+gsc_provider_devhelp_finalize (GObject *object)
+{
+	GscProviderDevhelp *provider = GSC_PROVIDER_DEVHELP (object);
+	
+	g_object_unref (provider->priv->dhbase);
+	g_list_foreach (provider->priv->proposals, (GFunc)free_proposal, NULL);
+	g_list_free (provider->priv->proposals);
+
+	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 void
+gsc_provider_devhelp_init (GscProviderDevhelp *self)
+{
+	self->priv = GSC_PROVIDER_DEVHELP_GET_PRIVATE (self);
+}
+
+static void
+create_assistant (GscProviderDevhelp *self)
+{
+	GList *item;
+	GList *ret;
+
+	ret = NULL;
+	
+	for (item = dh_base_get_keywords (self->priv->dhbase); item; item = g_list_next (item))
+	{
+		DhLink *link = (DhLink *)item->data;
+		IAnjutaEditorAssistProviderProposal *proposal;
+		
+		proposal = g_slice_new0 (IAnjutaEditorAssistProviderProposal);
+		proposal->label = g_strdup (dh_link_get_name (link));
+		proposal->text = g_strdup (dh_link_get_name (link));
+		
+		ret = g_list_prepend (ret, proposal);
+	}
+	
+	
+	self->priv->view = dh_assistant_view_new ();
+	dh_assistant_view_set_base (DH_ASSISTANT_VIEW (self->priv->view), self->priv->dhbase);
+	
+	gtk_widget_set_size_request (self->priv->view, 400, 300);
+
+	self->priv->proposals = g_list_reverse (ret);
+}
+
+GscProviderDevhelp*
+gsc_provider_devhelp_new (DhBase *dhbase)
+{
+	GscProviderDevhelp *ret = g_object_new (GSC_TYPE_PROVIDER_DEVHELP, NULL);
+	g_warning ("start");
+	ret->priv->dhbase = g_object_ref (dhbase);
+	
+	create_assistant (ret);
+	g_warning ("end");
+	return ret;
+}
diff --git a/plugins/devhelp/gsc-provider-devhelp.h b/plugins/devhelp/gsc-provider-devhelp.h
new file mode 100644
index 0000000..067c950
--- /dev/null
+++ b/plugins/devhelp/gsc-provider-devhelp.h
@@ -0,0 +1,59 @@
+/*
+ * gsc-provider-devhelp.h
+ * This file is part of anjuta
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * anjuta 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 of the License, or
+ * (at your option) any later version.
+ *
+ * anjuta 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 anjuta; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GSC_PROVIDER_DEVHELP_H__
+#define __GSC_PROVIDER_DEVHELP_H__
+
+#include <glib-object.h>
+#include <devhelp/dh-base.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 (DhBase *dhbase);
+
+
+G_END_DECLS
+
+#endif /* __GSC_PROVIDER_DEVHELP_H__ */
diff --git a/plugins/devhelp/plugin.c b/plugins/devhelp/plugin.c
index e169262..87b3860 100644
--- a/plugins/devhelp/plugin.c
+++ b/plugins/devhelp/plugin.c
@@ -27,9 +27,11 @@
 #include <libanjuta/anjuta-debug.h>
 #include <libanjuta/interfaces/ianjuta-document-manager.h>
 #include <libanjuta/interfaces/ianjuta-editor.h>
+#include <libanjuta/interfaces/ianjuta-editor-assist.h>
 #include <libanjuta/interfaces/ianjuta-help.h>
 
 #include "plugin.h"
+#include "gsc-provider-devhelp.h"
 
 #ifndef DISABLE_EMBEDDED_DEVHELP
 
@@ -272,6 +274,9 @@ value_added_current_editor (AnjutaPlugin *plugin, const gchar *name,
 	action = gtk_action_group_get_action (devhelp->action_group,
 										  "ActionHelpContext");
 	g_object_set (action, "sensitive", TRUE, NULL);
+	
+	devhelp->provider = IANJUTA_EDITOR_ASSIST_PROVIDER (gsc_provider_devhelp_new (devhelp->base));
+	ianjuta_editor_assist_add_provider (IANJUTA_EDITOR_ASSIST (devhelp->editor), devhelp->provider, NULL);
 }
 
 static void
@@ -279,12 +284,14 @@ value_removed_current_editor (AnjutaPlugin *plugin,
 							  const gchar *name, gpointer data)
 {
 	GtkAction *action;
-	AnjutaDevhelp* devhelp = ANJUTA_PLUGIN_DEVHELP (data);	
+	AnjutaDevhelp* devhelp = ANJUTA_PLUGIN_DEVHELP (data);
 		
 	devhelp->editor = NULL;
 	action = gtk_action_group_get_action (devhelp->action_group,
 										  "ActionHelpContext");
 	g_object_set (action, "sensitive", FALSE, NULL);
+	
+	ianjuta_editor_assist_remove_provider (IANJUTA_EDITOR_ASSIST (devhelp->editor), devhelp->provider, NULL);
 }
 
 #ifndef DISABLE_EMBEDDED_DEVHELP
@@ -515,7 +522,7 @@ devhelp_instance_init (GObject *obj)
 
 	/* Create devhelp */
 	plugin->base = dh_base_new ();
-
+	
 #endif /* DISABLE_EMBEDDED_DEVHELP */
 	
 	plugin->uiid = 0;
diff --git a/plugins/devhelp/plugin.h b/plugins/devhelp/plugin.h
index 5201c5c..4feea61 100644
--- a/plugins/devhelp/plugin.h
+++ b/plugins/devhelp/plugin.h
@@ -48,6 +48,7 @@ struct _AnjutaDevhelp{
 	
 #ifndef DISABLE_EMBEDDED_DEVHELP
 	DhBase         *base;
+	IAnjutaEditorAssistProvider *provider;
 #endif /* DISABLE_EMBEDDED_DEVHELP */
 	GtkWidget      *view;
 	GtkWidget      *view_sw;
diff --git a/plugins/sourceview/sourceview-private.h b/plugins/sourceview/sourceview-private.h
index d5b50f2..1618030 100644
--- a/plugins/sourceview/sourceview-private.h
+++ b/plugins/sourceview/sourceview-private.h
@@ -68,6 +68,7 @@ struct SourceviewPrivate {
 	
 	/* Assist */
 	AssistTip* assist_tip;
+	GList *providers;
 	
 	/* Hover */
 	gchar* tooltip;
diff --git a/plugins/sourceview/sourceview.c b/plugins/sourceview/sourceview.c
index 599aad6..17ea3c2 100644
--- a/plugins/sourceview/sourceview.c
+++ b/plugins/sourceview/sourceview.c
@@ -2009,7 +2009,7 @@ iassist_suggest (IAnjutaEditorAssist *iassist, GList* providers, IAnjutaIterable
 	
 	for (l = providers; l != NULL; l = g_list_next (l))
 	{
-		CompletionProvider *cp = completion_provider_new (l->data);
+		CompletionProvider *cp = completion_provider_new (l->data, GTK_TEXT_VIEW (sv->priv->view));
 		
 		real_providers = g_list_append (real_providers, cp);
 	}
@@ -2070,6 +2070,29 @@ iassist_tip_shown (IAnjutaEditorAssist* iassist, GError** err)
 	return (sv->priv->assist_tip != NULL);
 }
 
+typedef struct _PairProviders
+{
+	IAnjutaEditorAssistProvider *p1;
+	GtkSourceCompletionProvider *p2;
+} PairProviders;
+
+static void
+iassist_add_provider (IAnjutaEditorAssist *iassist, IAnjutaEditorAssistProvider *provider, GError **err)
+{
+	Sourceview* sv = ANJUTA_SOURCEVIEW(iassist);
+	PairProviders *pair;
+	GtkSourceCompletion *completion;
+	
+	pair = g_slice_new (PairProviders);
+	pair->p1 = provider;
+	pair->p2 = GTK_SOURCE_COMPLETION_PROVIDER (completion_provider_new (provider, GTK_TEXT_VIEW (sv->priv->view)));
+	
+	completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (sv->priv->view));
+	gtk_source_completion_add_provider (completion, pair->p2, NULL);
+	
+	sv->priv->providers = g_list_append (sv->priv->providers, pair);
+}
+
 static void
 iassist_iface_init(IAnjutaEditorAssistIface* iface)
 {
@@ -2078,6 +2101,7 @@ iassist_iface_init(IAnjutaEditorAssistIface* iface)
 	iface->show_tips = iassist_show_tips;
 	iface->cancel_tips = iassist_cancel_tips;
 	iface->tip_shown = iassist_tip_shown;
+	iface->add_provider = iassist_add_provider;
 }
 
 static gboolean



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