gtksourceview r2253 - in branches/gtksourcecompletion: . gtksourceview tests



Author: jessevdk
Date: Fri Apr 10 21:34:35 2009
New Revision: 2253
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2253&view=rev

Log:
	* gtksourceview/gtksourceview-marshal.list:
	* gtksourceview/gtksourcecompletionitem.c:
	* gtksourceview/gtksourcecompletionitem.h:
	* gtksourceview/gtksourcecompletion.c:
	* gtksourceview/gtksourcecompletioninfo.c:
	* gtksourceview/gtksourcecompletionproposal.c:
	* gtksourceview/gtksourcecompletionutils.c:
	* gtksourceview/gtksourcecompletionproposal.h:
	* gtksourceview/gtksourcecompletionutils.h:
	* gtksourceview/Makefile.am:
	* tests/gsc-provider-test.c:
	
	Made proposal into interface and GtkSourceCompletionItem a default
	store implementation of GtkSourceCompletionProposal.
	
	Cleaned up utils


Added:
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionitem.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionitem.h
Modified:
   branches/gtksourcecompletion/ChangeLog
   branches/gtksourcecompletion/gtksourceview/Makefile.am
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletioninfo.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.h
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.h
   branches/gtksourcecompletion/gtksourceview/gtksourceview-marshal.list
   branches/gtksourcecompletion/tests/gsc-provider-test.c

Modified: branches/gtksourcecompletion/gtksourceview/Makefile.am
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/Makefile.am	(original)
+++ branches/gtksourcecompletion/gtksourceview/Makefile.am	Fri Apr 10 21:34:35 2009
@@ -30,6 +30,7 @@
 	gtksourceprintcompositor.h		\
 	gtksourcecompletion.h			\
 	gtksourcecompletioninfo.h		\
+	gtksourcecompletionitem.h		\
 	gtksourcecompletionproposal.h		\
 	gtksourcecompletionprovider.h		\
 	gtksourcecompletiontrigger.h		\
@@ -64,6 +65,7 @@
 	gtksourceprintcompositor.c      \
 	gtksourcecompletion.c		\
 	gtksourcecompletioninfo.c	\
+	gtksourcecompletionitem.c	\
 	gtksourcecompletionproposal.c	\
 	gtksourcecompletionprovider.c	\
 	gtksourcecompletiontrigger.c	\

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c	Fri Apr 10 21:34:35 2009
@@ -896,7 +896,9 @@
 gtk_source_completion_proposal_selected_default (GtkSourceCompletion *self,
 						 GtkSourceCompletionProposal *proposal)
 {
-	gtk_source_completion_proposal_apply (proposal, self->priv->view);
+	gtk_source_completion_proposal_activate (proposal, 
+	                                         GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (
+	                                         	self->priv->view)));
 	end_completion (self);
 	
 	return FALSE;
@@ -1509,8 +1511,11 @@
 		GtkSourceCompletionPage *page;
 		
 		last_proposal = GTK_SOURCE_COMPLETION_PROPOSAL (data_list->data);
-		page = get_page_by_name (self,
-					 gtk_source_completion_proposal_get_page_name (last_proposal));
+		
+		/* FIXME: do something about the page */
+		/*page = get_page_by_name (self,
+					 gtk_source_completion_proposal_get_page_name (last_proposal));*/
+		page = get_page_by_name (self, DEFAULT_PAGE);
 		
 		add_proposal (page,
 			      last_proposal);
@@ -1527,7 +1532,7 @@
 	 *center_window, custom etc.
 	 */
 	gtk_source_completion_utils_get_pos_at_cursor (GTK_WINDOW (self),
-						       self->priv->view,
+						       GTK_SOURCE_VIEW (self->priv->view),
 						       &x, &y, NULL);
 
 	gtk_window_move (GTK_WINDOW (self),

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletioninfo.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletioninfo.c	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletioninfo.c	Fri Apr 10 21:34:35 2009
@@ -275,7 +275,7 @@
 	adjust_resize (self);
 	
 	gtk_source_completion_utils_get_pos_at_cursor (GTK_WINDOW (self),
-						       view,
+						       GTK_SOURCE_VIEW (view),
 						       &x,
 						       &y,
 						       &resized);

Added: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionitem.c
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionitem.c	Fri Apr 10 21:34:35 2009
@@ -0,0 +1,295 @@
+#include <gtksourceview/gtksourcecompletionitem.h>
+
+#include "gtksourcecompletionutils.h"
+#include "gtksourceview-i18n.h"
+
+#define GTK_SOURCE_COMPLETION_ITEM_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GTK_TYPE_SOURCE_COMPLETION_ITEM, GtkSourceCompletionItemPrivate))
+
+struct _GtkSourceCompletionItemPrivate
+{
+	gchar *label;
+	gchar *info;
+	GdkPixbuf *icon;	
+};
+
+/* Properties */
+enum
+{
+	PROP_0,
+	PROP_LABEL,
+	PROP_ICON,
+	PROP_INFO
+};
+
+static void gtk_source_completion_proposal_iface_init (gpointer g_iface, gpointer iface_data);
+
+G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionItem, 
+			 gtk_source_completion_item, 
+			 G_TYPE_OBJECT,
+			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROPOSAL,
+			 			gtk_source_completion_proposal_iface_init))
+
+static gboolean
+gtk_source_completion_proposal_activate_impl (GtkSourceCompletionProposal *self,
+					      GtkSourceBuffer		  *buffer)
+{
+	GtkSourceCompletionItem *item = GTK_SOURCE_COMPLETION_ITEM (self);
+
+	gtk_source_completion_utils_replace_current_word (buffer,
+							  item->priv->label,
+							  -1);
+	return FALSE;
+}
+
+static const gchar *
+gtk_source_completion_proposal_get_label_impl (GtkSourceCompletionProposal *self)
+{
+	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->label;
+}
+
+static const GdkPixbuf *
+gtk_source_completion_proposal_get_icon_impl (GtkSourceCompletionProposal *self)
+{
+	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->icon;
+}
+
+static const gchar *
+gtk_source_completion_proposal_get_info_impl (GtkSourceCompletionProposal *self)
+{
+	return GTK_SOURCE_COMPLETION_ITEM (self)->priv->info;
+}
+
+static void
+gtk_source_completion_proposal_iface_init (gpointer g_iface, 
+					   gpointer iface_data)
+{
+	GtkSourceCompletionProposalIface *iface = (GtkSourceCompletionProposalIface *)g_iface;
+	
+	/* Default activate handler */
+	iface->activate = gtk_source_completion_proposal_activate_impl;
+	
+	/* Interface data getter implementations */
+	iface->get_label = gtk_source_completion_proposal_get_label_impl;
+	iface->get_icon = gtk_source_completion_proposal_get_icon_impl;
+	iface->get_info = gtk_source_completion_proposal_get_info_impl;
+}
+
+static void
+gtk_source_completion_item_finalize (GObject *object)
+{
+	GtkSourceCompletionItem *self = GTK_SOURCE_COMPLETION_ITEM(object);
+	
+	g_free (self->priv->label);
+	g_free (self->priv->info);
+	
+	if (self->priv->icon != NULL)
+	{
+		g_object_unref (self->priv->icon);
+	}
+
+	G_OBJECT_CLASS (gtk_source_completion_item_parent_class)->finalize (object);
+}
+
+static void
+gtk_source_completion_item_get_property (GObject    *object,
+					 guint       prop_id,
+					 GValue     *value,
+					 GParamSpec *pspec)
+{
+	GtkSourceCompletionItem *self;
+
+	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_ITEM (object));
+
+	self = GTK_SOURCE_COMPLETION_ITEM (object);
+
+	switch (prop_id)
+	{
+		case PROP_LABEL:
+			g_value_set_string (value, self->priv->label);
+			break;
+		case PROP_INFO:
+			g_value_set_string (value, self->priv->info);
+			break;
+		case PROP_ICON:
+			g_value_set_object (value, self->priv->icon);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gtk_source_completion_item_set_property (GObject      *object,
+					 guint         prop_id,
+					 const GValue *value,
+					 GParamSpec   *pspec)
+{
+	GtkSourceCompletionItem *self;
+
+	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_ITEM (object));
+
+	self = GTK_SOURCE_COMPLETION_ITEM (object);
+
+	switch (prop_id)
+	{
+		case PROP_LABEL:
+			g_free (self->priv->label);
+			self->priv->label = g_value_dup_string (value);
+			break;
+		case PROP_INFO:
+			g_free (self->priv->info);
+			self->priv->info = g_value_dup_string (value);
+			break;
+		case PROP_ICON:
+			if (self->priv->icon != NULL)
+			{
+				g_object_unref (self->priv->icon);
+			}
+			
+			self->priv->icon = GDK_PIXBUF (g_value_dup_object (value));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gtk_source_completion_item_class_init (GtkSourceCompletionItemClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = gtk_source_completion_item_finalize;
+	object_class->get_property = gtk_source_completion_item_get_property;
+	object_class->set_property = gtk_source_completion_item_set_property;
+
+	/**
+	 * GtkSourceCompletionItem:label:
+	 *
+	 * Label to be shown for this item
+	 */
+	g_object_class_install_property (object_class,
+					 PROP_LABEL,
+					 g_param_spec_string ("label",
+							      _("Label"),
+							      _("Label to be shown for this item"),
+							      NULL,
+							      G_PARAM_READWRITE));
+
+	/**
+	 * GtkSourceCompletionItem:icon:
+	 *
+	 * Icon to be shown for this item
+	 */
+	g_object_class_install_property (object_class,
+					 PROP_ICON,
+					 g_param_spec_object ("icon",
+							      _("Icon"),
+							      _("Icon to be shown for this item"),
+							      GDK_TYPE_PIXBUF,
+							      G_PARAM_READWRITE));
+
+	/**
+	 * GtkSourceCompletionItem:info:
+	 *
+	 * Info to be shown for this item
+	 */
+	g_object_class_install_property (object_class,
+					 PROP_INFO,
+					 g_param_spec_string ("info",
+							      _("Info"),
+							      _("Info to be shown for this item"),
+							      NULL,
+							      G_PARAM_READWRITE));
+
+	g_type_class_add_private (object_class, sizeof(GtkSourceCompletionItemPrivate));
+}
+
+static void
+gtk_source_completion_item_init (GtkSourceCompletionItem *self)
+{
+	self->priv = GTK_SOURCE_COMPLETION_ITEM_GET_PRIVATE (self);
+}
+
+/** 
+ * gtk_source_completion_item_new:
+ *
+ * @label: the item label
+ * @icon: the item icon
+ * @info: the item extra information
+ *
+ * Create a new #GtkSourceCompletionItem with label @label, icon @icon and 
+ * extra information @info
+ *
+ * Return value: the newly constructed #GtkSourceCompletionItem
+ *
+ */
+GtkSourceCompletionItem *
+gtk_source_completion_item_new (const gchar *label,
+				GdkPixbuf   *icon,
+				const gchar *info)
+{
+	return g_object_new (GTK_TYPE_SOURCE_COMPLETION_ITEM, 
+			     "label", label,
+			     "icon", icon,
+			     "info", info,
+			     NULL);
+}
+
+/** 
+ * gtk_source_completion_item_new_from_stock:
+ *
+ * @label: the item label
+ * @icon: the item icon
+ * @info: the item extra information
+ *
+ * Create a new #GtkSourceCompletionItem from a stock item. If @label is NULL, 
+ * the stock label will be used.
+ *
+ * Return value: the newly constructed #GtkSourceCompletionItem
+ *
+ */
+GtkSourceCompletionItem *
+gtk_source_completion_item_new_from_stock (const gchar *label,
+					   const gchar *stock,
+					   const gchar *info)
+{
+	GtkSourceCompletionItem *item;
+	GdkPixbuf *icon;
+	GtkIconTheme *theme;
+	gint width;
+	gint height;
+	GtkStockItem stock_item;
+	
+	if (stock != NULL)
+	{
+		theme = gtk_icon_theme_get_default ();
+	
+		gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
+
+		icon = gtk_icon_theme_load_icon (theme, 
+						 stock, 
+						 width, 
+						 GTK_ICON_LOOKUP_USE_BUILTIN, 
+						 NULL);
+
+		if (label == NULL && gtk_stock_lookup (stock, &stock_item))
+		{
+			label = stock_item.label;
+		}
+	}
+	else
+	{
+		icon = NULL;
+	}
+	
+	item = gtk_source_completion_item_new (label, icon, info);
+	
+	if (icon != NULL)
+	{
+		g_object_unref (icon);
+	}
+	
+	return item;	
+}

Added: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionitem.h
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionitem.h	Fri Apr 10 21:34:35 2009
@@ -0,0 +1,43 @@
+#ifndef __GTK_SOURCE_COMPLETION_ITEM_H__
+#define __GTK_SOURCE_COMPLETION_ITEM_H__
+
+#include <glib-object.h>
+#include <gtksourceview/gtksourcecompletionproposal.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SOURCE_COMPLETION_ITEM			(gtk_source_completion_item_get_type ())
+#define GTK_SOURCE_COMPLETION_ITEM(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_COMPLETION_ITEM, GtkSourceCompletionItem))
+#define GTK_SOURCE_COMPLETION_ITEM_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_COMPLETION_ITEM, GtkSourceCompletionItem const))
+#define GTK_SOURCE_COMPLETION_ITEM_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SOURCE_COMPLETION_ITEM, GtkSourceCompletionItemClass))
+#define GTK_IS_SOURCE_COMPLETION_ITEM(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SOURCE_COMPLETION_ITEM))
+#define GTK_IS_SOURCE_COMPLETION_ITEM_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SOURCE_COMPLETION_ITEM))
+#define GTK_SOURCE_COMPLETION_ITEM_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SOURCE_COMPLETION_ITEM, GtkSourceCompletionItemClass))
+
+typedef struct _GtkSourceCompletionItem		GtkSourceCompletionItem;
+typedef struct _GtkSourceCompletionItemClass	GtkSourceCompletionItemClass;
+typedef struct _GtkSourceCompletionItemPrivate	GtkSourceCompletionItemPrivate;
+
+struct _GtkSourceCompletionItem {
+	GObject parent;
+	
+	GtkSourceCompletionItemPrivate *priv;
+};
+
+struct _GtkSourceCompletionItemClass {
+	GObjectClass parent_class;
+};
+
+GType 			 gtk_source_completion_item_get_type 		(void) G_GNUC_CONST;
+
+GtkSourceCompletionItem *gtk_source_completion_item_new 		(const gchar *label,
+									 GdkPixbuf   *icon,
+									 const gchar *info);
+
+GtkSourceCompletionItem *gtk_source_completion_item_new_from_stock	(const gchar *label,
+								 	 const gchar *stock,
+								 	 const gchar *info);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_COMPLETION_ITEM_H__ */

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.c	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.c	Fri Apr 10 21:34:35 2009
@@ -2,7 +2,8 @@
  * gtksourcecompletionproposal.c
  * This file is part of gtksourcecompletion
  *
- * Copyright (C) 2007 -2009 JesÃs Barbero RodrÃguez <chuchiperriman gmail com>
+ * Copyright (C) 2007 - 2009 JesÃs Barbero RodrÃguez <chuchiperriman gmail com>
+ * Copyright (C) 2009 Jesse van den Kieboom <jessevdk 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
@@ -25,358 +26,176 @@
  * @title: GtkSourceCompletionProposal
  * @short_description: Completion proposal object
  *
- * Every proposal is an item into the popup. It controls the label to be
- * shown, the help (info) and the apply when the user selects the proposal.
+ * The proposal interface represents a completion item in the completion window.
+ * It provides information on how to display the completion item and what action
+ * should be taken when the completion item is activated.
  */
-  
-#include <gtksourceview/gtksourcecompletionproposal.h>
-#include "gtksourcecompletionutils.h"
-#include "gtksourceview-i18n.h"
-
-#define GTK_SOURCE_COMPLETION_PROPOSAL_DEFAULT_PAGE _("Default")
-#define GTK_SOURCE_COMPLETION_PROPOSAL_DEFAULT_PRIORITY 10
-
-#define GTK_SOURCE_COMPLETION_PROPOSAL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
-							   GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, GtkSourceCompletionProposalPrivate))
 
-G_DEFINE_TYPE(GtkSourceCompletionProposal, gtk_source_completion_proposal, G_TYPE_OBJECT);
+#include <gtksourceview/gtksourcecompletionproposal.h>
 
-struct _GtkSourceCompletionProposalPrivate
-{
-	gchar *label;
-	gchar *info;
-	GdkPixbuf *icon;
-	gchar *page_name;
-};
+#include "gtksourceview-marshal.h"
 
-/* Properties */
+/* Signals */
 enum
 {
-	PROP_0,
-	PROP_LABEL,
-	PROP_INFO,
-	PROP_ICON,
-	PROP_PAGE_NAME
+	ACTIVATE,
+	NUM_SIGNALS
 };
 
-static gboolean
-gtk_source_completion_proposal_apply_default (GtkSourceCompletionProposal *self,
-					      GtkTextView *view)
-{
-	gtk_source_completion_utils_replace_current_word (view,
-							  self->priv->label);
-	return FALSE;
-}
+static guint signals[NUM_SIGNALS] = {0,};
 
 static const gchar *
-gtk_source_completion_proposal_get_info_default (GtkSourceCompletionProposal *self)
+gtk_source_completion_proposal_get_label_default (GtkSourceCompletionProposal *proposal)
 {
-	return self->priv->info;
+	g_return_val_if_reached (NULL);
 }
 
-static void
-gtk_source_completion_proposal_init (GtkSourceCompletionProposal *self)
+static void 
+gtk_source_completion_proposal_init (GtkSourceCompletionProposalIface *iface)
 {
-	self->priv = GTK_SOURCE_COMPLETION_PROPOSAL_GET_PRIVATE (self);
+	static gboolean initialized = FALSE;
 	
-	self->priv->label = NULL;
-	self->priv->info = NULL;
-	self->priv->icon = NULL;
-	self->priv->page_name = g_strdup (GTK_SOURCE_COMPLETION_PROPOSAL_DEFAULT_PAGE);
-}
-
-static void
-gtk_source_completion_proposal_finalize (GObject *object)
-{
-	GtkSourceCompletionProposal *self = GTK_SOURCE_COMPLETION_PROPOSAL (object);
-	
-	g_free (self->priv->label);
-	g_free (self->priv->info);
-	g_free (self->priv->page_name);
-	
-	if (self->priv->icon != NULL)
-		g_object_unref(self->priv->icon);
+	iface->get_label = gtk_source_completion_proposal_get_label_default;
 	
-	G_OBJECT_CLASS (gtk_source_completion_proposal_parent_class)->finalize (object);
-}
-
-static void
-gtk_source_completion_proposal_get_property (GObject    *object,
-					     guint       prop_id,
-					     GValue     *value,
-					     GParamSpec *pspec)
-{
-	GtkSourceCompletionProposal *self;
-
-	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (object));
-
-	self = GTK_SOURCE_COMPLETION_PROPOSAL (object);
-
-	switch (prop_id)
+	if (!initialized)
 	{
-			
-		case PROP_LABEL:
-			g_value_set_string (value,self->priv->label);
-			break;
-		case PROP_INFO:
-			g_value_set_string (value,
-					    self->priv->info);
-			break;
-		case PROP_ICON:
-			g_value_set_pointer (value,
-					     (gpointer)self->priv->icon);
-			break;
-		case PROP_PAGE_NAME:
-			g_value_set_string (value,
-					    self->priv->page_name);
-			break;
-		default:
-			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-			break;
+		signals[ACTIVATE] = 
+			g_signal_new ("activate",
+			      G_TYPE_FROM_INTERFACE (iface),
+			      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+			      G_STRUCT_OFFSET (GtkSourceCompletionProposalIface, activate),
+			      g_signal_accumulator_true_handled, 
+			      NULL,
+			      _gtksourceview_marshal_BOOLEAN__OBJECT, 
+			      G_TYPE_BOOLEAN,
+			      1,
+			      GTK_TYPE_SOURCE_BUFFER);
+		
+		initialized = TRUE;
 	}
 }
 
-static void
-gtk_source_completion_proposal_set_property (GObject      *object,
-					     guint         prop_id,
-					     const GValue *value,
-					     GParamSpec   *pspec)
-{
-	GtkSourceCompletionProposal *self;
-
-	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (object));
-
-	self = GTK_SOURCE_COMPLETION_PROPOSAL (object);
-
-	switch (prop_id)
-	{
-		case PROP_LABEL:
-			self->priv->label = g_value_dup_string (value);
-			break;
-		case PROP_INFO:
-			self->priv->info = g_value_dup_string (value);
-			break;
-		case PROP_ICON:
-			if (self->priv->icon != NULL)
-				g_object_unref (self->priv->icon);
-
-			self->priv->icon = g_object_ref ((GdkPixbuf*)g_value_get_pointer (value));
-			break;
-		case PROP_PAGE_NAME:
-			self->priv->page_name = g_value_dup_string (value);
-			break;
-		default:
-			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-			break;
-	}
-}
-
-static void
-gtk_source_completion_proposal_class_init (GtkSourceCompletionProposalClass *klass)
-{
-	GObjectClass* object_class = G_OBJECT_CLASS (klass);
-
-	object_class->get_property = gtk_source_completion_proposal_get_property;
-	object_class->set_property = gtk_source_completion_proposal_set_property;
-	object_class->finalize = gtk_source_completion_proposal_finalize;
-
-	g_type_class_add_private (object_class, sizeof (GtkSourceCompletionProposalPrivate));
-	
-	klass->apply = gtk_source_completion_proposal_apply_default;
-	klass->get_info = gtk_source_completion_proposal_get_info_default;
-	
-	/* Proposal properties */
-	
-	/**
-	 * GtkSourceCompletionProposal:label:
-	 *
-	 * Label to be shown for this proposal
-	 */
-	g_object_class_install_property (object_class,
-					 PROP_LABEL,
-					 g_param_spec_string ("label",
-							      _("Label to be shown for this proposal"),
-							      _("Label to be shown for this proposal"),
-							      NULL,
-							      G_PARAM_READWRITE));
-	/**
-	 * GtkSourceCompletionProposal:info:
-	 *
-	 * Info to be shown for this proposal
-	 */
-	g_object_class_install_property (object_class,
-					 PROP_INFO,
-					 g_param_spec_string ("info",
-							      _("Info to be shown for this proposal"),
-							      _("Info to be shown for this proposal"),
-							      NULL,
-							      G_PARAM_READWRITE));
-	/**
-	 * GtkSourceCompletionProposal:icon:
-	 *
-	 * Icon to be shown for this proposal
-	 */
-	g_object_class_install_property (object_class,
-					 PROP_ICON,
-					 g_param_spec_pointer ("icon",
-							      _("Icon to be shown for this proposal"),
-							      _("Icon to be shown for this proposal"),
-							      G_PARAM_READWRITE));
-
-	/**
-	 * GtkSourceCompletionProposal:page-name:
-	 *
-	 * Page name for this proposal
-	 */
-	g_object_class_install_property (object_class,
-					 PROP_PAGE_NAME,
-					 g_param_spec_string ("page-name",
-							      _("Page name for this proposal"),
-							      _("Page name for this proposal"),
-							      NULL,
-							      G_PARAM_READWRITE));
-}
-
-/**
- * gtk_source_completion_proposal_new:
- * @label: Item label that will be shown in the completion popup. 
- * @info: Item info markup that will be shown when the user select to view the item info.
- * @icon: Item icon that will be shown in the completion popup
- *
- * This function creates a new #GtkSourceCompletionProposal. By default, when the user selects 
- * the proposal, the proposal label will be inserted into the GtkTextView.
- * You can overwrite the apply and disply-info functions to overwrite the default.
- *
- * Returns: A new #GtkSourceCompletionProposal
- */
-GtkSourceCompletionProposal *
-gtk_source_completion_proposal_new (const gchar *label,
-				    const gchar *info,
-				    GdkPixbuf *icon)
+GType 
+gtk_source_completion_proposal_get_type ()
 {
-	GtkSourceCompletionProposal *self;
-	
-	self = GTK_SOURCE_COMPLETION_PROPOSAL (g_object_new (GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, NULL));
+	static GType gtk_source_completion_proposal_type_id = 0;
 	
-	self->priv->label = g_strdup (label);
-	self->priv->info = g_strdup (info);
-	if (icon != NULL)
-	{
-		self->priv->icon = g_object_ref (icon);
-	}
-	else
+	if (!gtk_source_completion_proposal_type_id)
 	{
-		self->priv->icon = NULL;
+		static const GTypeInfo g_define_type_info =
+		{
+			sizeof (GtkSourceCompletionProposalIface),
+			(GBaseInitFunc) gtk_source_completion_proposal_init, 
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			0,
+			0,
+			NULL
+		};
+		
+		gtk_source_completion_proposal_type_id = 
+			g_type_register_static (G_TYPE_INTERFACE,
+						"GtkSourceCompletionProposal",
+						&g_define_type_info,
+						0);
 	}
 	
-	return self;
+	return gtk_source_completion_proposal_type_id;
 }
 
 /**
  * gtk_source_completion_proposal_get_label:
  * @proposal: The #GtkSourceCompletionProposal
  *
- * Returns: The proposal label that will be shown into the popup
+ * Gets the label of @proposal
+ *
+ * Returns: The label of @proposal
  */
 const gchar *
 gtk_source_completion_proposal_get_label (GtkSourceCompletionProposal *proposal)
 {
-	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
-	
-	return proposal->priv->label;
+	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);	
+	return GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal)->get_label (proposal);
 }
 
 /**
  * gtk_source_completion_proposal_get_icon:
  * @proposal: The #GtkSourceCompletionProposal
  *
- * Gets the icon of this @proposal that will be shown into the popup.
+ * Gets the icon of @proposal
  *
- * Returns: the icon of this @proposal that will be shown into the popup
+ * Returns: The icon of @proposal
  */
 const GdkPixbuf *
 gtk_source_completion_proposal_get_icon (GtkSourceCompletionProposal *proposal)
 {
+	GtkSourceCompletionProposalIface *iface;
+	
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
 
-	return proposal->priv->icon;
-}
-
-/**
- * gtk_source_completion_proposal_set_page_name:
- * @proposal: The #GtkSourceCompletionProposal
- * @page_name: The name for the page
- *
- * Sets the name of the page where this proposal will be shown.
- * If @page_name is %NULL the default page will be used.
- */
-void
-gtk_source_completion_proposal_set_page_name (GtkSourceCompletionProposal *proposal,
-					      const gchar *page_name)
-{
-	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal));
-
-	g_free (proposal->priv->page_name);
+	iface = GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal);
 	
-	if (page_name == NULL)
+	if (iface->get_icon)
 	{
-		proposal->priv->page_name = g_strdup (GTK_SOURCE_COMPLETION_PROPOSAL_DEFAULT_PAGE);
+		return iface->get_icon (proposal);
 	}
 	else
 	{
-		proposal->priv->page_name = g_strdup (page_name);
+		return NULL;
 	}
 }
 
 /**
- * gtk_source_completion_proposal_get_page_name:
- * @proposal: The #GtkSourceCompletionProposal
- *
- * Gets the page name where the @proposal will be placed.
- *
- * Returns: the page name where the @proposal will be placed.
- */
-const gchar *
-gtk_source_completion_proposal_get_page_name (GtkSourceCompletionProposal *proposal)
-{
-	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
-	
-	return proposal->priv->page_name;
-}
-
-/**
  * gtk_source_completion_proposal_get_info:
  * @proposal: The #GtkSourceCompletionProposal
  *
- * The completion calls this function when the user wants to see the proposal info.
- * You can overwrite this function if you need to change the default mechanism.
+ * Gets extra information associated to the proposal. This information will be
+ * used to present the user with extra, detailed information about the
+ * selected proposal.
  *
- * Returns: The proposal info markup asigned for this proposal or NULL;
+ * Returns: The extra information of @proposal or %NULL if no extra information
+ *          is associated to @proposal
  */
 const gchar *
 gtk_source_completion_proposal_get_info (GtkSourceCompletionProposal *proposal)
 {
+	GtkSourceCompletionProposalIface *iface;
+	
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), NULL);
 
-	return GTK_SOURCE_COMPLETION_PROPOSAL_GET_CLASS (proposal)->get_info (proposal);
+	iface = GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE (proposal);
+	
+	if (iface->get_info)
+	{
+		return iface->get_info (proposal);
+	}
+	else
+	{
+		return NULL;
+	}
 }
 
 /**
- * gtk_source_completion_proposal_apply:
+ * gtk_source_completion_proposal_activate:
  * @proposal: The #GtkSourceCompletionProposal
- * @view: The #GtkTextView
  * 
- * The completion calls this function when the user selects the proposal. 
- * The default handler insert the proposal label into the view. 
- * You can overwrite this function.
+ * This emits the "activate" signal on @proposal. This function is generally 
+ * called when @proposal is activated from the completion window. 
+ * Implementations should take action in the default handler of the signal.
  */
-void
-gtk_source_completion_proposal_apply (GtkSourceCompletionProposal *proposal,
-				      GtkTextView *view)
+gboolean
+gtk_source_completion_proposal_activate (GtkSourceCompletionProposal *proposal,
+					 GtkSourceBuffer	     *buffer)
 {
-	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal));
+	gboolean ret = FALSE;
+
+	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), FALSE);
 	
-	GTK_SOURCE_COMPLETION_PROPOSAL_GET_CLASS (proposal)->apply (proposal, view);
+	g_signal_emit (proposal, signals[ACTIVATE], 0, buffer, &ret);
+
+	return ret;
 }
 
 

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.h
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.h	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionproposal.h	Fri Apr 10 21:34:35 2009
@@ -2,7 +2,8 @@
  * gtksourcecompletionproposal.h
  * This file is part of gtksourcecompletion
  *
- * Copyright (C) 2007 -2009 JesÃs Barbero RodrÃguez <chuchiperriman gmail com>
+ * Copyright (C) 2007 - 2009 JesÃs Barbero RodrÃguez <chuchiperriman gmail com>
+ * Copyright (C) 2009 Jesse van den Kieboom <jessevdk 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
@@ -19,65 +20,48 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, 
  * Boston, MA 02111-1307, USA.
  */
- 
-#ifndef _GTK_SOURCE_COMPLETION_PROPOSAL_H
-#define _GTK_SOURCE_COMPLETION_PROPOSAL_H
+
+#ifndef __GTK_SOURCE_COMPLETION_PROPOSAL_H__
+#define __GTK_SOURCE_COMPLETION_PROPOSAL_H__
 
 #include <glib-object.h>
-#include <glib.h>
-#include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtksourceview/gtksourcebuffer.h>
 
 G_BEGIN_DECLS
 
-#define GTK_TYPE_SOURCE_COMPLETION_PROPOSAL             (gtk_source_completion_proposal_get_type ())
-#define GTK_SOURCE_COMPLETION_PROPOSAL(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, GtkSourceCompletionProposal))
-#define GTK_SOURCE_COMPLETION_PROPOSAL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, GtkSourceCompletionProposalClass))
-#define GTK_IS_SOURCE_COMPLETION_PROPOSAL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL))
-#define GTK_IS_SOURCE_COMPLETION_PROPOSAL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL))
-#define GTK_SOURCE_COMPLETION_PROPOSAL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, GtkSourceCompletionProposalClass))
-
-typedef struct _GtkSourceCompletionProposalPrivate GtkSourceCompletionProposalPrivate;
-typedef struct _GtkSourceCompletionProposalClass GtkSourceCompletionProposalClass;
-typedef struct _GtkSourceCompletionProposal GtkSourceCompletionProposal;
+#define GTK_TYPE_SOURCE_COMPLETION_PROPOSAL			(gtk_source_completion_proposal_get_type ())
+#define GTK_SOURCE_COMPLETION_PROPOSAL(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, GtkSourceCompletionProposal))
+#define GTK_IS_SOURCE_COMPLETION_PROPOSAL(obj)			(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL))
+#define GTK_SOURCE_COMPLETION_PROPOSAL_GET_INTERFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_SOURCE_COMPLETION_PROPOSAL, GtkSourceCompletionProposalIface))
 
-struct _GtkSourceCompletionProposal
-{
-	GObject parent_instance;
-	
-	GtkSourceCompletionProposalPrivate *priv;
-};
+typedef struct _GtkSourceCompletionProposal		GtkSourceCompletionProposal;
+typedef struct _GtkSourceCompletionProposalIface	GtkSourceCompletionProposalIface;
 
-struct _GtkSourceCompletionProposalClass
+struct _GtkSourceCompletionProposalIface
 {
-	GObjectClass parent_class;
+	GTypeInterface parent;
+	
+	/* Signals */
+	gboolean	 (*activate)	(GtkSourceCompletionProposal *proposal,
+					 GtkSourceBuffer	     *buffer);
+	
+	/* Interface functions */
+	const gchar 	*(*get_label)	(GtkSourceCompletionProposal *proposal);
+	const GdkPixbuf	*(*get_icon)	(GtkSourceCompletionProposal *proposal);
+	const gchar	*(*get_info)	(GtkSourceCompletionProposal *proposal);
 	
-	gboolean     (*apply)    (GtkSourceCompletionProposal *proposal,
-				  GtkTextView *view);
-	const gchar* (*get_info) (GtkSourceCompletionProposal *proposal);
 };
 
-GType			 gtk_source_completion_proposal_get_type	(void) G_GNUC_CONST;
-
-GtkSourceCompletionProposal
-			*gtk_source_completion_proposal_new		(const gchar *label,
-									 const gchar *info,
-									 GdkPixbuf *icon);
+GType 			 gtk_source_completion_proposal_get_type 	(void) G_GNUC_CONST;
 
 const gchar		*gtk_source_completion_proposal_get_label	(GtkSourceCompletionProposal *proposal);
-
 const GdkPixbuf		*gtk_source_completion_proposal_get_icon	(GtkSourceCompletionProposal *proposal);
-
-
-void			 gtk_source_completion_proposal_set_page_name	(GtkSourceCompletionProposal *proposal,
-									 const gchar *page_name);
-
-const gchar		*gtk_source_completion_proposal_get_page_name	(GtkSourceCompletionProposal *proposal);
-
 const gchar		*gtk_source_completion_proposal_get_info	(GtkSourceCompletionProposal *proposal);
 
-void			 gtk_source_completion_proposal_apply		(GtkSourceCompletionProposal *proposal,
-									 GtkTextView *view);
+gboolean		 gtk_source_completion_proposal_activate	(GtkSourceCompletionProposal *proposal,
+									 GtkSourceBuffer             *buffer);
 
 G_END_DECLS
 
-#endif
+#endif /* __GTK_SOURCE_COMPLETION_PROPOSAL_H__ */

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.c	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.c	Fri Apr 10 21:34:35 2009
@@ -51,26 +51,29 @@
 }
 
 /**
-* gsc_utils_view_get_last_word_and_iter:
-* @text_view: The #GtkTextView
-* @start_word: if != NULL then assign it the start position of the word
-* @end_word: if != NULL then assing it the end position of the word
-* 
-* Returns: the last word written in the #GtkTextView or ""
-*
-**/
-gchar*
-gtk_source_completion_utils_get_word_iter(GtkTextView *text_view, 
-				      GtkTextIter *start_word, 
-				      GtkTextIter *end_word)
+ * gtk_source_completion_utils_get_word_iter:
+ *
+ * @source_buffer: The #GtkSourceBuffer
+ * @start_word: if != NULL then assign it the start position of the word
+ * @end_word: if != NULL then assing it the end position of the word
+ * 
+ * Returns: the current word
+ *
+ */
+gchar *
+gtk_source_completion_utils_get_word_iter (GtkSourceBuffer *source_buffer, 
+					   GtkTextIter     *start_word, 
+					   GtkTextIter     *end_word)
 {
-	GtkTextMark* insert_mark;
-	GtkTextBuffer* text_buffer;
-	GtkTextIter actual,temp;
+	GtkTextMark *insert_mark;
+	GtkTextBuffer *text_buffer;
+	GtkTextIter actual;
+	GtkTextIter temp;
 	GtkTextIter *start_iter;
-	gchar* text;
+	gchar *text;
 	gunichar ch;
-	gboolean found, no_doc_start;
+	gboolean found;
+	gboolean no_doc_start;
 	
 	if (start_word != NULL)
 	{
@@ -81,21 +84,24 @@
 		start_iter = &temp;
 	}
 	
-	text_buffer = gtk_text_view_get_buffer(text_view);
-	insert_mark = gtk_text_buffer_get_insert(text_buffer);
-	gtk_text_buffer_get_iter_at_mark(text_buffer,&actual,insert_mark);
+	text_buffer = GTK_TEXT_BUFFER (source_buffer);
+	insert_mark = gtk_text_buffer_get_insert (text_buffer);
+	gtk_text_buffer_get_iter_at_mark (text_buffer ,&actual, insert_mark);
 	
 	*start_iter = actual;
-	if (end_word!=NULL)
+
+	if (end_word != NULL)
 	{
 		*end_word = actual;
 	}
 	
 	found = FALSE;
-	while ((no_doc_start = gtk_text_iter_backward_char(start_iter)) == TRUE)
+
+	while ((no_doc_start = gtk_text_iter_backward_char (start_iter)) == TRUE)
 	{
-		ch = gtk_text_iter_get_char(start_iter);
-		if (gtk_source_completion_utils_is_separator(ch))
+		ch = gtk_text_iter_get_char (start_iter);
+
+		if (gtk_source_completion_utils_is_separator (ch))
 		{
 			found = TRUE;
 			break;
@@ -104,7 +110,7 @@
 	
 	if (!no_doc_start)
 	{
-		gtk_text_buffer_get_start_iter(text_buffer,start_iter);
+		gtk_text_buffer_get_start_iter (text_buffer, start_iter);
 		text = gtk_text_iter_get_text (start_iter, &actual);
 	}
 	else
@@ -112,14 +118,13 @@
 	
 		if (found)
 		{
-			gtk_text_iter_forward_char(start_iter);
+			gtk_text_iter_forward_char (start_iter);
 			text = gtk_text_iter_get_text (start_iter, &actual);
 		}
 		else
 		{
 			*start_iter = actual;
-			/*FIXME dup this var?*/
-			text = "";
+			text = g_strdup ("");
 		}
 	}
 	
@@ -127,53 +132,56 @@
 }
 
 /**
- * gsc_utils_view_get_last_word:
- * @text_view: The #GtkTextView
+ * gtk_source_completion_utils_get_word:
+ * @source_buffer: The #GtkSourceBuffer
  *
- * Returns: the last word written in the #GtkTextView or ""
+ * Returns: the current word
  */
-gchar*
-gtk_source_completion_utils_get_word(GtkTextView *text_view)
+gchar *
+gtk_source_completion_utils_get_word (GtkSourceBuffer *source_buffer)
 {
-	return gtk_source_completion_utils_get_word_iter (text_view, NULL, NULL);
+	return gtk_source_completion_utils_get_word_iter (source_buffer, NULL, NULL);
 }
 
 /** 
  * gsc_utils_view_get_cursor_pos:
- * @text_view: The #GtkTextView
+ * @source_view: The #GtksourceView
  * @x: Assign the x position of the cursor
  * @y: Assign the y position of the cursor
  *
  * Gets the cursor position on the screen.
  */
 void
-gtk_source_completion_utils_get_cursor_pos(GtkTextView *text_view, 
-			      gint *x, 
-			      gint *y)
+gtk_source_completion_utils_get_cursor_pos (GtkSourceView *source_view, 
+					    gint          *x, 
+					    gint          *y)
 {
 	GdkWindow *win;
-	GtkTextMark* insert_mark;
-	GtkTextBuffer* text_buffer;
+	GtkTextMark *insert_mark;
+	GtkTextView *text_view;
+	GtkTextBuffer *text_buffer;
 	GtkTextIter start;
 	GdkRectangle location;
-	gint win_x, win_y;
-	gint xx, yy;
+	gint win_x;
+	gint win_y;
+	gint xx;
+	gint yy;
+
+	text_view = GTK_TEXT_VIEW (source_view);
+	text_buffer = gtk_text_view_get_buffer (text_view);
+	insert_mark = gtk_text_buffer_get_insert (text_buffer);
+
+	gtk_text_buffer_get_iter_at_mark (text_buffer, &start, insert_mark);
+	gtk_text_view_get_iter_location (text_view, &start, &location);
 
-	text_buffer = gtk_text_view_get_buffer(text_view);
-	insert_mark = gtk_text_buffer_get_insert(text_buffer);
-	gtk_text_buffer_get_iter_at_mark(text_buffer,&start,insert_mark);
-	gtk_text_view_get_iter_location(text_view,
-					&start,
-					&location );
 	gtk_text_view_buffer_to_window_coords (text_view,
-						GTK_TEXT_WINDOW_WIDGET,
-						location.x, 
-						location.y,
-						&win_x, 
-						&win_y);
+					       GTK_TEXT_WINDOW_WIDGET,
+					       location.x, 
+					       location.y,
+					       &win_x, 
+					       &win_y);
 
-	win = gtk_text_view_get_window (text_view, 
-	                                GTK_TEXT_WINDOW_WIDGET);
+	win = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_WIDGET);
 	gdk_window_get_origin (win, &xx, &yy);
 	
 	*x = win_x + xx;
@@ -182,33 +190,32 @@
 
 /**
  * gsc_utils_view_replace_current_word:
- * @text_view: The #GtkTextView
+ * @source_buffer: The #GtkSourceBuffer
  * @text: The text to be inserted instead of the current word
  * 
- * Replaces the current word in the #GtkTextView with the new word
+ * Replaces the current word in the #GtkSourceBuffer with the new word
  *
  */
 void
-gtk_source_completion_utils_replace_current_word(GtkTextView *text_view, 
-				    const gchar* text)
+gtk_source_completion_utils_replace_current_word (GtkSourceBuffer *source_buffer, 
+						  const gchar     *text,
+						  gint             len)
 {
 	GtkTextBuffer *buffer;
-	GtkTextIter word_start, word_end;
+	gchar *word;
+	GtkTextIter word_start;
+	GtkTextIter word_end;
 	
-	buffer = gtk_text_view_get_buffer(text_view);
-	gtk_text_buffer_begin_user_action(buffer);
+	buffer = GTK_TEXT_BUFFER (source_buffer);
+	gtk_text_buffer_begin_user_action (buffer);
 	
-	gtk_source_completion_utils_get_word_iter (text_view,&word_start, &word_end);
+	word = gtk_source_completion_utils_get_word_iter (source_buffer, &word_start, &word_end);
+	g_free (word);
 
-	GtkTextMark *mark = gtk_text_buffer_create_mark(buffer,
-							"temp_replace",
-							&word_start,
-							TRUE);
-	gtk_text_buffer_delete(buffer,&word_start,&word_end);
-	gtk_text_buffer_get_iter_at_mark(buffer,&word_start,mark);
-	gtk_text_buffer_insert(buffer, &word_start, text,-1);
-	gtk_text_buffer_delete_mark(buffer,mark);
-	gtk_text_buffer_end_user_action(buffer);
+	gtk_text_buffer_delete (buffer, &word_start, &word_end);
+	gtk_text_buffer_insert (buffer, &word_start, text, len);
+
+	gtk_text_buffer_end_user_action (buffer);
 }
 
 /**
@@ -222,20 +229,37 @@
  * the position is under the text.
  */
 gboolean 
-gtk_source_completion_utils_get_pos_at_cursor(GtkWindow *window,
-					GtkTextView *view,
-					gint *x,
-					gint *y,
-					gboolean *resized)
+gtk_source_completion_utils_get_pos_at_cursor (GtkWindow     *window,
+					       GtkSourceView *view,
+					       gint          *x, 
+					       gint          *y,
+					       gboolean      *resized)
 {
-	gint w, h, xtext, ytext, ytemp;
+	gint w;
+	gint h;
+	gint xtext;
+	gint ytext;
+	gint ytemp;
+	GdkScreen *screen;
 	gint sw = gdk_screen_width();
 	gint sh = gdk_screen_height();
 	gboolean resize = FALSE;
 	gboolean up = FALSE;
-	gtk_source_completion_utils_get_cursor_pos (view,x,y);
 	
-	gtk_window_get_size(window, &w, &h);
+	if (window != NULL)
+	{
+		screen = gtk_window_get_screen (window);
+	}
+	else
+	{
+		screen = gdk_screen_get_default ();
+	}
+	
+	sw = gdk_screen_get_width (screen);
+	sh = gdk_screen_get_height (screen);
+
+	gtk_source_completion_utils_get_cursor_pos (view, x, y);
+	gtk_window_get_size (window, &w, &h);
 	
 	/* Processing x position and width */
 	if (w > (sw - 8))

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.h
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.h	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionutils.h	Fri Apr 10 21:34:35 2009
@@ -20,30 +20,35 @@
  * Boston, MA 02111-1307, USA.
  */
  
-#ifndef GTK_SOURCE_COMPLETION_UTILS_H
-#define GTK_SOURCE_COMPLETION_UTILS_H
+#ifndef __GTK_SOURCE_COMPLETION_UTILS_H__
+#define __GTK_SOURCE_COMPLETION_UTILS_H__
 
-#include <gtk/gtk.h>
+#include <gtksourceview/gtksourceview.h>
 
-gboolean	gtk_source_completion_utils_is_separator		(gunichar ch);
+G_BEGIN_DECLS
 
-gchar		*gtk_source_completion_utils_get_word_iter		(GtkTextView *text_view, 
-									 GtkTextIter *start_word, 
-									 GtkTextIter *end_word);
+gboolean	 gtk_source_completion_utils_is_separator		(gunichar         ch);
 
-gchar		*gtk_source_completion_utils_get_word			(GtkTextView *text_view);
+gchar		*gtk_source_completion_utils_get_word_iter		(GtkSourceBuffer *source_buffer, 
+									 GtkTextIter     *start_word, 
+									 GtkTextIter     *end_word);
 
-void		gtk_source_completion_utils_get_cursor_pos		(GtkTextView *text_view, 
-									 gint *x, 
-									 gint *y);
+gchar		*gtk_source_completion_utils_get_word			(GtkSourceBuffer *text_view);
 
-void		gtk_source_completion_utils_replace_current_word	(GtkTextView *text_view, 
-									 const gchar* text);
+void		 gtk_source_completion_utils_get_cursor_pos		(GtkSourceView   *source_view, 
+									 gint            *x, 
+									 gint            *y);
 
-gboolean	gtk_source_completion_utils_get_pos_at_cursor		(GtkWindow *window,
-									 GtkTextView *view,
-									 gint *x,
-									 gint *y,
-									 gboolean *resized);
+void		 gtk_source_completion_utils_replace_current_word	(GtkSourceBuffer *source_buffer, 
+									 const gchar     *text,
+									 gint             len);
 
-#endif 
+gboolean	 gtk_source_completion_utils_get_pos_at_cursor		(GtkWindow       *window,
+									 GtkSourceView   *view,
+									 gint            *x,
+									 gint            *y,
+									 gboolean        *resized);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_COMPLETION_ITEM_H__ */

Modified: branches/gtksourcecompletion/gtksourceview/gtksourceview-marshal.list
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourceview-marshal.list	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourceview-marshal.list	Fri Apr 10 21:34:35 2009
@@ -6,3 +6,4 @@
 VOID:STRING
 BOOLEAN:POINTER
 BOOLEAN:VOID
+BOOLEAN:OBJECT

Modified: branches/gtksourcecompletion/tests/gsc-provider-test.c
==============================================================================
--- branches/gtksourcecompletion/tests/gsc-provider-test.c	(original)
+++ branches/gtksourcecompletion/tests/gsc-provider-test.c	Fri Apr 10 21:34:35 2009
@@ -18,6 +18,7 @@
  */
 
 #include "gsc-provider-test.h"
+#include <gtksourceview/gtksourcecompletionitem.h>
 
 static void	 gsc_provider_test_iface_init	(GtkSourceCompletionProviderIface *iface);
 
@@ -27,34 +28,36 @@
 			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROVIDER,
 				 		gsc_provider_test_iface_init))
 
-static const gchar* 
-gsc_provider_test_real_get_name (GtkSourceCompletionProvider* self)
+static const gchar * 
+gsc_provider_test_real_get_name (GtkSourceCompletionProvider *self)
 {
 	return GSC_PROVIDER_TEST_NAME;
 }
 
 static GList* 
-gsc_provider_test_real_get_proposals (GtkSourceCompletionProvider* base,
-						GtkSourceCompletionTrigger *trigger)
+gsc_provider_test_real_get_proposals (GtkSourceCompletionProvider *base,
+				      GtkSourceCompletionTrigger  *trigger)
 {
 	GList *list = NULL;
-	GtkSourceCompletionProposal *prop;
+	GtkSourceCompletionItem *prop;
 	
-	prop = gtk_source_completion_proposal_new("Proposal 1",
-				"Info proposal 1",
-				NULL);
+	prop = gtk_source_completion_item_new ("Proposal 1",
+	                                       NULL,
+	                                       "Info proposal 1");
+
 	list = g_list_append (list, prop);
-	prop = gtk_source_completion_proposal_new("Proposal 2",
-				"Info proposal 2",
-				NULL);
+	prop = gtk_source_completion_item_new ("Proposal 2",
+	                                       NULL,
+	                                       "Info proposal 2");
+
 	list = g_list_append (list, prop);
-	prop = gtk_source_completion_proposal_new("Proposal 3",
-				"Info proposal 3",
-				NULL);
+	prop = gtk_source_completion_item_new ("Proposal 3",
+	                                       NULL,
+	                                       "Info proposal 3");
 	list = g_list_append (list, prop);
 	
 	/*Page 2*/
-	prop = gtk_source_completion_proposal_new("Proposal 1,2",
+	/*prop = gtk_source_completion_proposal_new("Proposal 1,2",
 				"Info proposal 1,2",
 				NULL);
 	gtk_source_completion_proposal_set_page_name(prop,"Page 2");
@@ -73,7 +76,7 @@
 				"Info proposal fixed",
 				NULL);
 	gtk_source_completion_proposal_set_page_name(prop,"Fixed");
-	list = g_list_append (list, prop);
+	list = g_list_append (list, prop);*/
 	return list;
 }
 



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