[anjuta/gtksourcecompletion] Add missing files.



commit 1c4bc9d091d2e0e49ee789e4811e6a07c5bd96ee
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun May 17 23:14:05 2009 +0200

    Add missing files.
---
 plugins/devhelp/gsc-provider-devhelp.c   |    1 +
 plugins/devhelp/gsc-provider-devhelp.h   |    3 +-
 plugins/sourceview/completion-provider.c |  216 ++++++++++++++++++++++++++++++
 plugins/sourceview/completion-provider.h |   60 ++++++++
 4 files changed, 279 insertions(+), 1 deletions(-)

diff --git a/plugins/devhelp/gsc-provider-devhelp.c b/plugins/devhelp/gsc-provider-devhelp.c
index 5b158df..3c0f1d2 100644
--- a/plugins/devhelp/gsc-provider-devhelp.c
+++ b/plugins/devhelp/gsc-provider-devhelp.c
@@ -3,6 +3,7 @@
  * This file is part of anjuta
  *
  * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *						Jesse van den Kieboom
  *
  * anjuta is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/plugins/devhelp/gsc-provider-devhelp.h b/plugins/devhelp/gsc-provider-devhelp.h
index 067c950..ec45242 100644
--- a/plugins/devhelp/gsc-provider-devhelp.h
+++ b/plugins/devhelp/gsc-provider-devhelp.h
@@ -1,8 +1,9 @@
 /*
- * gsc-provider-devhelp.h
+ * gsc-provider-devhelp.c
  * This file is part of anjuta
  *
  * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *						Jesse van den Kieboom
  *
  * anjuta is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/plugins/sourceview/completion-provider.c b/plugins/sourceview/completion-provider.c
new file mode 100644
index 0000000..8a5d2ee
--- /dev/null
+++ b/plugins/sourceview/completion-provider.c
@@ -0,0 +1,216 @@
+/*
+ * completion-provider.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
+ */
+
+/*
+ * Description:
+ * Class for mapping an IAnjutaEditorAssistProvider into a
+ * GtkSourceCompletionProvider
+ */
+
+#include "completion-provider.h"
+#include "sourceview-cell.h"
+#include <gtksourceview/gtksourcecompletionitem.h>
+#include <gtksourceview/gtksourcecompletionprovider.h>
+#include <glib/gi18n.h>
+
+
+#define COMPLETION_PROVIDER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), COMPLETION_TYPE_PROVIDER, CompletionProviderPrivate))
+
+struct _CompletionProviderPrivate
+{
+	IAnjutaEditorAssistProvider *provider;
+	GtkTextView *view;
+};
+
+static void completion_provider_iface_init (GtkSourceCompletionProviderIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (CompletionProvider, 
+						 completion_provider, 
+						 G_TYPE_OBJECT,
+						 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROVIDER,
+												completion_provider_iface_init))
+
+static void
+completion_provider_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (completion_provider_parent_class)->finalize (object);
+}
+
+static void
+completion_provider_class_init (CompletionProviderClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	object_class->finalize = completion_provider_finalize;
+
+	g_type_class_add_private (object_class, sizeof(CompletionProviderPrivate));
+}
+
+static void
+completion_provider_init (CompletionProvider *self)
+{
+	self->priv = COMPLETION_PROVIDER_GET_PRIVATE (self);
+}
+
+static const gchar * 
+completion_provider_get_name (GtkSourceCompletionProvider *self)
+{
+	return _("Completion Items");
+}
+
+static GList * 
+completion_provider_get_proposals (GtkSourceCompletionProvider *provider,
+                                   GtkTextIter                 *iter)
+{
+	CompletionProvider *prov = COMPLETION_PROVIDER (provider);
+	GList *elements, *l, *proposals = NULL;
+	SourceviewCell *cell = sourceview_cell_new (iter, prov->priv->view);
+
+	elements = ianjuta_editor_assist_provider_get_proposals (prov->priv->provider, IANJUTA_ITERABLE (cell), NULL);
+	
+	for (l = elements; l != NULL; l = g_list_next (l))
+	{
+		GtkSourceCompletionItem *proposal;
+		IAnjutaEditorAssistProviderProposal *p = (IAnjutaEditorAssistProviderProposal *)l->data;
+		
+		proposal = gtk_source_completion_item_new (p->label,
+												   p->text,
+												   p->pixbuf,
+												   p->info);
+		proposals = g_list_prepend (proposals, proposal);
+	}
+
+	proposals = g_list_reverse (proposals);
+
+	return proposals;
+}
+
+static gboolean
+completion_provider_filter_proposal (GtkSourceCompletionProvider *provider,
+                                     GtkSourceCompletionProposal *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
+completion_provider_get_interactive (GtkSourceCompletionProvider *provider)
+{
+	return TRUE;
+}
+
+static IAnjutaEditorAssistProviderProposal *
+create_proposal_from_gsv_proposal (GtkSourceCompletionProposal *proposal)
+{
+	IAnjutaEditorAssistProviderProposal *p;
+	GdkPixbuf *icon;
+
+	p = g_slice_new0 (IAnjutaEditorAssistProviderProposal);
+	
+	p->label = g_strdup (gtk_source_completion_proposal_get_label (proposal));
+	p->text = g_strdup (gtk_source_completion_proposal_get_text (proposal));
+	icon = gtk_source_completion_proposal_get_icon (proposal);
+	if (icon != NULL)
+		p->pixbuf = g_object_ref (icon);
+	p->info = g_strdup (gtk_source_completion_proposal_get_info (proposal));
+	
+	return p;
+}
+
+static void
+free_proposal (IAnjutaEditorAssistProviderProposal *proposal)
+{
+	g_free (proposal->label);
+	g_free (proposal->text);
+	if (proposal->pixbuf != NULL)
+		g_object_unref (proposal->pixbuf);
+	g_free (proposal->info);
+	
+	g_slice_free (IAnjutaEditorAssistProviderProposal, proposal);
+}
+
+static GtkWidget *
+completion_provider_get_info_widget (GtkSourceCompletionProvider *provider,
+                                     GtkSourceCompletionProposal *proposal)
+{
+	CompletionProvider *cp = COMPLETION_PROVIDER (provider);
+	IAnjutaEditorAssistProviderProposal *p;
+	GtkWidget *widget;
+	
+	p = create_proposal_from_gsv_proposal (proposal);
+
+	widget = ianjuta_editor_assist_provider_get_info_widget (cp->priv->provider,
+															 p, NULL);
+
+	free_proposal (p);
+	
+	return widget;
+}
+
+static void
+completion_provider_update_info (GtkSourceCompletionProvider *provider,
+                                 GtkSourceCompletionProposal *proposal,
+                                 GtkSourceCompletionInfo     *info)
+{
+	CompletionProvider *cp = COMPLETION_PROVIDER (provider);
+	IAnjutaEditorAssistProviderProposal *p;
+	GtkWidget *widget;
+	
+	p = create_proposal_from_gsv_proposal (proposal);
+	
+	widget = gtk_source_completion_info_get_widget (info);
+	
+	ianjuta_editor_assist_provider_update_info (cp->priv->provider,
+												p, widget, NULL);
+	
+	free_proposal (p);
+}
+
+static void
+completion_provider_iface_init (GtkSourceCompletionProviderIface *iface)
+{
+	iface->get_name = completion_provider_get_name;
+	iface->get_proposals = completion_provider_get_proposals;
+	iface->get_interactive = completion_provider_get_interactive;
+	iface->filter_proposal = completion_provider_filter_proposal;
+	
+	iface->get_info_widget = completion_provider_get_info_widget;
+	iface->update_info = completion_provider_update_info;
+}
+
+CompletionProvider *
+completion_provider_new (IAnjutaEditorAssistProvider *provider,
+						 GtkTextView *view)
+{
+	CompletionProvider *comp;
+	
+	comp = g_object_new (COMPLETION_TYPE_PROVIDER, NULL);
+	
+	comp->priv->provider = provider;
+	comp->priv->view = view;
+	
+	return comp;
+}
diff --git a/plugins/sourceview/completion-provider.h b/plugins/sourceview/completion-provider.h
new file mode 100644
index 0000000..4df945a
--- /dev/null
+++ b/plugins/sourceview/completion-provider.h
@@ -0,0 +1,60 @@
+/*
+ * completion-provider.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 __COMPLETION_PROVIDER_H__
+#define __COMPLETION_PROVIDER_H__
+
+#include <glib-object.h>
+#include <libanjuta/interfaces/ianjuta-editor-assist-provider.h>
+
+G_BEGIN_DECLS
+
+#define COMPLETION_TYPE_PROVIDER			(completion_provider_get_type ())
+#define COMPLETION_PROVIDER(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), COMPLETION_TYPE_PROVIDER, CompletionProvider))
+#define COMPLETION_PROVIDER_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), COMPLETION_TYPE_PROVIDER, CompletionProvider const))
+#define COMPLETION_PROVIDER_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), COMPLETION_TYPE_PROVIDER, CompletionProviderClass))
+#define COMPLETION_IS_PROVIDER(obj)			(G_TYPE_CHECK_INSTANCE_TYPE ((obj), COMPLETION_TYPE_PROVIDER))
+#define COMPLETION_IS_PROVIDER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), COMPLETION_TYPE_PROVIDER))
+#define COMPLETION_PROVIDER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), COMPLETION_TYPE_PROVIDER, CompletionProviderClass))
+
+typedef struct _CompletionProvider			CompletionProvider;
+typedef struct _CompletionProviderClass		CompletionProviderClass;
+typedef struct _CompletionProviderPrivate	CompletionProviderPrivate;
+
+struct _CompletionProvider {
+	GObject parent;
+	
+	CompletionProviderPrivate *priv;
+};
+
+struct _CompletionProviderClass {
+	GObjectClass parent_class;
+};
+
+GType completion_provider_get_type (void) G_GNUC_CONST;
+CompletionProvider *completion_provider_new (IAnjutaEditorAssistProvider *provider,
+											 GtkTextView *view);
+
+
+G_END_DECLS
+
+#endif /* __COMPLETION_PROVIDER_H__ */



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