gtksourceview r2245 - in branches/gtksourcecompletion: . gtksourceview tests



Author: icq
Date: Wed Apr  8 16:28:41 2009
New Revision: 2245
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2245&view=rev

Log:
2009-04-08  Ignacio Casal Quinteiro  <nacho resa gmail com>

        * gtksourceview/gtksourcecompletiontriggerkey.h:
        * gtksourceview/Makefile.am:
        * gtksourceview/gtksourcecompletiontriggerkey.c:
        * tests/completion-simple.c:
        * tests/gsc-provider-test.c:
        * tests/gsc-provider-test.h:
        * tests/gsc-utils-test.c:
        * tests/gsc-utils-test.h:
        * tests/Makefile.am:
        Added test case and added the trigger for key triggering.



Added:
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletiontriggerkey.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletiontriggerkey.h
   branches/gtksourcecompletion/tests/completion-simple.c
   branches/gtksourcecompletion/tests/gsc-provider-test.c
   branches/gtksourcecompletion/tests/gsc-provider-test.h
   branches/gtksourcecompletion/tests/gsc-utils-test.c
   branches/gtksourcecompletion/tests/gsc-utils-test.h
Modified:
   branches/gtksourcecompletion/ChangeLog
   branches/gtksourcecompletion/gtksourceview/Makefile.am
   branches/gtksourcecompletion/tests/Makefile.am

Modified: branches/gtksourcecompletion/gtksourceview/Makefile.am
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/Makefile.am	(original)
+++ branches/gtksourcecompletion/gtksourceview/Makefile.am	Wed Apr  8 16:28:41 2009
@@ -29,9 +29,11 @@
 	gtksourcemark.h				\
 	gtksourceprintcompositor.h		\
 	gtksourcecompletion.h			\
+	gtksourcecompletioninfo.h		\
 	gtksourcecompletionproposal.h		\
 	gtksourcecompletionprovider.h		\
-	gtksourcecompletiontrigger.h
+	gtksourcecompletiontrigger.h		\
+	gtksourcecompletiontriggerkey.h
 
 libgtksourceview_2_0_la_SOURCES = 	\
 	gtksourcebuffer.c 		\
@@ -62,10 +64,10 @@
 	gtksourceprintcompositor.c      \
 	gtksourcecompletion.c		\
 	gtksourcecompletioninfo.c	\
-	gtksourcecompletioninfo.h	\
 	gtksourcecompletionproposal.c	\
 	gtksourcecompletionprovider.c	\
 	gtksourcecompletiontrigger.c	\
+	gtksourcecompletiontriggerkey.c	\
 	gtksourcecompletionutils.c	\
 	gtksourcecompletionutils.h	\
 	$(libgtksourceview_headers)

Added: branches/gtksourcecompletion/gtksourceview/gtksourcecompletiontriggerkey.c
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletiontriggerkey.c	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,226 @@
+/*
+ * gtksourcecompletiontriggerkey.c
+ * This file is part of gtksourceview
+ *
+ * Copyright (C) 2007 -2009 JesÃs Barbero RodrÃguez <chuchiperriman gmail com>
+ *
+ * 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 of the License, 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.
+ */
+
+/**
+ * SECTION:gsc-trigger-key
+ * @title: GtkSourceCompletionTriggerKey
+ * @short_description: Custom keys trigger
+ *
+ * This object trigger a completion event when the user press the configured
+ * keys.
+ * 
+ */
+
+#include <glib/gprintf.h>
+#include <string.h>
+#include <ctype.h>
+#include "gtksourcecompletiontriggerkey.h"
+
+#define GTK_SOURCE_COMPLETION_TRIGGER_KEY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+							GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY, \
+							GtkSourceCompletionTriggerKeyPrivate))
+
+/* User request signals */
+enum
+{
+	CKP_GTK_TEXT_VIEW_KP,
+	LAST_SIGNAL
+};
+
+struct _GtkSourceCompletionTriggerKeyPrivate
+{
+	GtkSourceCompletion *completion;
+	
+	gulong signals[LAST_SIGNAL];
+	gchar *trigger_name;
+	guint key;
+	GdkModifierType mod;
+};
+
+static void	 gtk_source_completion_trigger_key_iface_init	(GtkSourceCompletionTriggerIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GtkSourceCompletionTriggerKey,
+			 gtk_source_completion_trigger_key,
+			 G_TYPE_OBJECT,
+			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_TRIGGER,
+				 		gtk_source_completion_trigger_key_iface_init))
+
+static gboolean
+view_key_press_event_cb (GtkWidget *view,
+			 GdkEventKey *event, 
+			 gpointer user_data)
+{
+	GtkSourceCompletionTriggerKey *self;
+	guint s;
+	guint key;
+	
+	self = GTK_SOURCE_COMPLETION_TRIGGER_KEY (user_data);
+	s = event->state & gtk_accelerator_get_default_mod_mask ();
+	key = gdk_keyval_to_lower (self->priv->key);
+	
+	if (s == self->priv->mod && gdk_keyval_to_lower(event->keyval) == key)
+	{
+		gtk_source_completion_trigger_event (self->priv->completion,
+						     GTK_SOURCE_COMPLETION_TRIGGER (self));
+		return TRUE;
+	}
+	
+	return FALSE;
+}
+
+static const gchar *
+gtk_source_completion_trigger_key_real_get_name (GtkSourceCompletionTrigger *base)
+{
+	GtkSourceCompletionTriggerKey *self;
+	
+	self = GTK_SOURCE_COMPLETION_TRIGGER_KEY (base);
+	
+	return self->priv->trigger_name;
+}
+
+static gboolean
+gtk_source_completion_trigger_key_real_activate (GtkSourceCompletionTrigger* base)
+{
+	GtkSourceCompletionTriggerKey *self;
+	GtkTextView *view;
+
+	self = GTK_SOURCE_COMPLETION_TRIGGER_KEY (base);
+	view = gtk_source_completion_get_view (self->priv->completion);
+	g_assert (GTK_IS_TEXT_VIEW (view));
+	
+	self->priv->signals[CKP_GTK_TEXT_VIEW_KP] =  
+			g_signal_connect_data (view,
+					       "key-press-event",
+					       G_CALLBACK (view_key_press_event_cb),
+					       self,
+					       NULL,
+					       0);
+	return TRUE;
+}
+
+static gboolean
+gtk_source_completion_trigger_key_real_deactivate (GtkSourceCompletionTrigger* base)
+{
+	GtkSourceCompletionTriggerKey *self;
+	GtkTextView *view;
+	
+	self = GTK_SOURCE_COMPLETION_TRIGGER_KEY (base);
+	view = gtk_source_completion_get_view (self->priv->completion);
+	
+	g_signal_handler_disconnect (view,
+				     self->priv->signals[CKP_GTK_TEXT_VIEW_KP]);
+	
+	return FALSE;
+}
+
+static void 
+gtk_source_completion_trigger_key_init (GtkSourceCompletionTriggerKey * self)
+{
+	self->priv = GTK_SOURCE_COMPLETION_TRIGGER_KEY_GET_PRIVATE (self);
+	
+	self->priv->trigger_name = NULL;
+}
+
+static void 
+gtk_source_completion_trigger_key_finalize (GObject *object)
+{
+	GtkSourceCompletionTriggerKey *self;
+	
+	self = GTK_SOURCE_COMPLETION_TRIGGER_KEY (object);
+	
+	g_free (self->priv->trigger_name);
+	g_object_unref (self->priv->completion);
+
+	G_OBJECT_CLASS (gtk_source_completion_trigger_key_parent_class)->finalize (object);
+}
+
+static void 
+gtk_source_completion_trigger_key_class_init (GtkSourceCompletionTriggerKeyClass * klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	g_type_class_add_private (klass, sizeof (GtkSourceCompletionTriggerKeyPrivate));
+
+	object_class->finalize = gtk_source_completion_trigger_key_finalize;
+}
+
+static void 
+gtk_source_completion_trigger_key_iface_init (GtkSourceCompletionTriggerIface * iface)
+{
+	iface->get_name   = gtk_source_completion_trigger_key_real_get_name;
+	iface->activate   = gtk_source_completion_trigger_key_real_activate;
+	iface->deactivate = gtk_source_completion_trigger_key_real_deactivate;
+}
+
+/**
+ * gtk_source_completion_trigger_key_new:
+ * @completion: The #GtkSourceCompletion
+ * @trigger_name: The trigger name wich will be user the we trigger the event.
+ * @keys: The string representation of the keys that we will
+ * use to activate the event. You can get this 
+ * string with #gtk_accelerator_name
+ *
+ * This is a generic trigger. You tell the name and the key and the trigger
+ * will be triggered when the user press this key (or keys).
+ *
+ * Returns: a new #GtkSourceCompletionTriggerKey
+ *
+ */
+GtkSourceCompletionTriggerKey* 
+gtk_source_completion_trigger_key_new (GtkSourceCompletion *completion,
+				       const gchar *trigger_name,
+				       const gchar *keys)
+{
+	GtkSourceCompletionTriggerKey *self;
+	
+	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION (completion), NULL);
+	g_return_val_if_fail (trigger_name != NULL, NULL);
+	
+	self = GTK_SOURCE_COMPLETION_TRIGGER_KEY (g_object_new (GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY,
+								NULL));
+	
+	self->priv->completion = g_object_ref (completion);
+	self->priv->trigger_name = g_strdup (trigger_name);
+	gtk_source_completion_trigger_key_set_keys (self, keys);
+	
+	return self;
+}
+
+/**
+ * gtk_source_completion_trigger_key_set_keys:
+ * @self: The #GtkSourceCompletionTriggerKey 
+ * @keys: The string representation of the keys that we will
+ * use to activate the user request event. You can get this 
+ * string with #gtk_accelerator_name
+ *
+ * Assign the keys that we will use to activate the user request event.
+ */
+void
+gtk_source_completion_trigger_key_set_keys (GtkSourceCompletionTriggerKey *self,
+					    const gchar *keys)
+{
+	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_TRIGGER_KEY (self));
+
+	gtk_accelerator_parse (keys, &self->priv->key, &self->priv->mod);
+}
+
+

Added: branches/gtksourcecompletion/gtksourceview/gtksourcecompletiontriggerkey.h
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletiontriggerkey.h	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,68 @@
+/*
+ * gtksourcecompletiontrigger-key.h
+ * This file is part of gtksourcecompletion
+ *
+ * Copyright (C) 2007 -2009 JesÃs Barbero RodrÃguez <chuchiperriman gmail com>
+ *
+ * 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 of the License, 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 GTK_SOURCE_COMPLETION_TRIGGER_KEY_H__
+#define GTK_SOURCE_COMPLETION_TRIGGER_KEY_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include "gtksourcecompletiontrigger.h"
+#include "gtksourcecompletion.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY (gtk_source_completion_trigger_key_get_type ())
+#define GTK_SOURCE_COMPLETION_TRIGGER_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY, GtkSourceCompletionTriggerKey))
+#define GTK_SOURCE_COMPLETION_TRIGGER_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY, GtkSourceCompletionTriggerKeyClass))
+#define GTK_IS_SOURCE_COMPLETION_TRIGGER_KEY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY))
+#define GTK_IS_SOURCE_COMPLETION_TRIGGER_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY))
+#define GTK_SOURCE_COMPLETION_TRIGGER_KEY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SOURCE_COMPLETION_TRIGGER_KEY, GtkSourceCompletionTriggerKeyClass))
+
+typedef struct _GtkSourceCompletionTriggerKey GtkSourceCompletionTriggerKey;
+typedef struct _GtkSourceCompletionTriggerKeyClass GtkSourceCompletionTriggerKeyClass;
+typedef struct _GtkSourceCompletionTriggerKeyPrivate GtkSourceCompletionTriggerKeyPrivate;
+
+struct _GtkSourceCompletionTriggerKey
+{
+	GObject parent;
+	
+	GtkSourceCompletionTriggerKeyPrivate *priv;
+};
+
+struct _GtkSourceCompletionTriggerKeyClass
+{
+	GObjectClass parent;
+};
+
+GType		 gtk_source_completion_trigger_key_get_type	(void) G_GNUC_CONST;
+
+GtkSourceCompletionTriggerKey
+		*gtk_source_completion_trigger_key_new		(GtkSourceCompletion *completion,
+								 const gchar *trigger_name,
+								 const gchar *keys);
+
+void		 gtk_source_completion_trigger_key_set_keys	(GtkSourceCompletionTriggerKey *self,
+								 const gchar *keys);
+
+G_END_DECLS
+
+#endif

Modified: branches/gtksourcecompletion/tests/Makefile.am
==============================================================================
--- branches/gtksourcecompletion/tests/Makefile.am	(original)
+++ branches/gtksourcecompletion/tests/Makefile.am	Wed Apr  8 16:28:41 2009
@@ -9,10 +9,10 @@
 	$(TESTS_CFLAGS)
 
 # testing executables
-EXTRA_PROGRAMS = test-widget testregion
+EXTRA_PROGRAMS = test-widget testregion test-completion
 # testregion need gtk_text_region_ api which is normally private
 # modify gtksourceview/Makefile.am to export gtk_text_* symbols
-noinst_PROGRAMS = test-widget
+noinst_PROGRAMS = test-widget test-completion
 
 test_widget_SOURCES = test-widget.c
 
@@ -21,6 +21,18 @@
 	$(DEP_LIBS)                     \
 	$(TESTS_LIBS)
 
+test_completion_SOURCES =		\
+        completion-simple.c		\
+        gsc-provider-test.h		\
+        gsc-provider-test.c		\
+	gsc-utils-test.c		\
+	gsc-utils-test.h
+
+test_completion_LDADD = 			\
+	$(top_builddir)/gtksourceview/libgtksourceview-2.0.la \
+	$(DEP_LIBS)                     \
+	$(TESTS_LIBS)
+
 testregion_SOURCES = testregion.c
 
 testregion_LDADD = 			\

Added: branches/gtksourcecompletion/tests/completion-simple.c
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/completion-simple.c	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,269 @@
+/*
+ * main.c
+ * Copyright (C) perriman 2007 <chuchiperriman gmail com>
+ * 
+ * main.c is free software.
+ * 
+ * You may 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.
+ * 
+ * main.c 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 main.c.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtksourceview/gtksourceview.h>
+#include <gtksourceview/gtksourcecompletion.h>
+#include <gtksourceview/gtksourcecompletioninfo.h>
+#include <gtksourceview/gtksourcecompletiontriggerkey.h>
+
+#include "gsc-utils-test.h"
+#include "gsc-provider-test.h"
+
+#define TEST_PAGE "Page 3"
+#define FIXED_PAGE "Fixed"
+
+static GtkWidget *view;
+static GtkSourceCompletion *comp;
+static GtkSourceCompletionInfo *info;
+
+static const gboolean change_keys = FALSE;
+
+static void
+show_completion_cb (GtkWidget *w, gpointer user_data)
+{
+	gint n;
+	gint pos;
+	
+	n = gtk_source_completion_get_n_pages (comp);
+	pos = gtk_source_completion_get_page_pos (comp, TEST_PAGE);
+	
+	if (pos == n -1)
+		pos = 1;
+	else
+		pos++;
+	
+	gtk_source_completion_set_page_pos (comp, TEST_PAGE, pos);
+	g_debug ("pos: %d, urpos: %d", pos, 
+		gtk_source_completion_get_page_pos (comp, TEST_PAGE));
+	g_assert (gtk_source_completion_get_page_pos (comp, TEST_PAGE) == pos);
+}
+
+static void
+hide_completion_cb (GtkWidget *w, gpointer user_data)
+{
+	
+}
+
+static gboolean
+filter_func (GtkSourceCompletionProposal *proposal,
+	     gpointer user_data)
+{
+	const gchar *label = gtk_source_completion_proposal_get_label (proposal);
+	return g_str_has_prefix (label, "sp");
+}
+
+static void
+destroy_cb(GtkObject *object,gpointer   user_data)
+{
+	gtk_main_quit ();
+}
+
+static void
+activate_toggled_cb (GtkToggleButton *button,
+		     gpointer user_data)
+{
+	g_object_set (comp, "active", gtk_toggle_button_get_active (button), NULL);
+}
+
+static void
+remember_toggled_cb (GtkToggleButton *button,
+		     gpointer user_data)
+{
+	g_object_set (comp, "remember-info-visibility", gtk_toggle_button_get_active (button), NULL);
+}
+
+static void
+select_on_show_toggled_cb (GtkToggleButton *button,
+			   gpointer user_data)
+{
+	g_object_set (comp, "select-on-show", gtk_toggle_button_get_active (button), NULL);
+}
+
+static gboolean
+key_press(GtkWidget   *widget,
+	GdkEventKey *event,
+	gpointer     user_data)
+{
+	if (event->keyval == GDK_F9)
+	{
+		gtk_source_completion_filter_proposals (comp,
+					  filter_func,
+					  NULL);
+		return TRUE;
+	} else if (event->keyval == GDK_F8)
+	{
+		GtkSourceCompletionInfo *gsc_info;
+		
+		gsc_info = gtk_source_completion_get_info_widget (comp);
+		
+		if (GTK_WIDGET_VISIBLE (GTK_WIDGET (gsc_info)))
+			gtk_widget_hide (GTK_WIDGET (gsc_info));
+		else
+			gtk_widget_show (GTK_WIDGET (gsc_info));
+	}
+	
+	guint key = 0;
+	GdkModifierType mod;
+	gtk_accelerator_parse ("<Control>b", &key, &mod);
+	
+	guint s = event->state & gtk_accelerator_get_default_mod_mask();
+	
+	if (s == mod && gdk_keyval_to_lower(event->keyval) == key)
+	{
+		if (!GTK_WIDGET_VISIBLE (info))
+		{
+			gchar *text;
+			gchar *word = gsc_get_last_word (GTK_TEXT_VIEW (view));
+			text = g_strdup_printf ("<b>Calltip</b>: %s", word);
+			
+			gtk_source_completion_info_set_markup (info, text);
+			g_free (text);
+			gtk_source_completion_info_move_to_cursor (info, GTK_TEXT_VIEW (view));
+			gtk_widget_show (GTK_WIDGET (info));
+		}
+		else
+		{
+			gtk_widget_hide (GTK_WIDGET (info));
+		}
+	}
+	
+	return FALSE;
+}
+
+static GtkWidget*
+create_window (void)
+{
+	GtkWidget *window;
+	GtkWidget *vbox;
+	GtkWidget *hbox;
+	GtkWidget *activate;
+	GtkWidget *remember;
+	GtkWidget *select_on_show;
+	GtkWidget *label;
+	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	gtk_window_resize(GTK_WINDOW(window),600,400);
+	
+	vbox = gtk_vbox_new (FALSE,1);
+	hbox = gtk_hbox_new (FALSE,1);
+	
+	view = gtk_source_view_new();
+	GtkWidget *scroll = gtk_scrolled_window_new(NULL,NULL);
+	gtk_container_add(GTK_CONTAINER(scroll),view);
+	
+	activate = gtk_check_button_new_with_label ("Active");
+	remember = gtk_check_button_new_with_label ("Remember info visibility");
+	select_on_show = gtk_check_button_new_with_label ("Select first on show");
+	label = gtk_label_new ("F9 filter by \"sp\"\n<Control>b to show a calltip\nF8 show/hide info");
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (activate), TRUE);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (remember), FALSE);
+	gtk_box_pack_start(GTK_BOX(hbox),label, TRUE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox),activate, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox),remember, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(hbox),select_on_show, FALSE, FALSE, 0);
+	
+	gtk_box_pack_start(GTK_BOX(vbox),scroll, TRUE, TRUE, 0);
+	gtk_box_pack_end(GTK_BOX(vbox),hbox, FALSE, FALSE, 0);
+	
+	gtk_container_add(GTK_CONTAINER(window),vbox);
+	
+	g_signal_connect(view, "key-release-event", G_CALLBACK(key_press), NULL);
+	
+	g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
+	
+	g_signal_connect(activate,"toggled",G_CALLBACK(activate_toggled_cb),NULL);
+	g_signal_connect(remember,"toggled",G_CALLBACK(remember_toggled_cb),NULL);
+	g_signal_connect(select_on_show,"toggled",G_CALLBACK(select_on_show_toggled_cb),NULL);
+	
+	return window;
+}
+
+static void
+create_completion(void)
+{
+	GscProviderTest *prov_test;
+	GtkSourceCompletionTriggerKey *ur_trigger;
+	
+	prov_test = gsc_provider_test_new ();
+	
+	comp = gtk_source_view_get_completion (GTK_SOURCE_VIEW (view));
+	
+	ur_trigger = gtk_source_completion_trigger_key_new (comp,
+							    "User Request Trigger",
+							    "<Control>Return");
+	
+	gtk_source_completion_register_trigger (comp, GTK_SOURCE_COMPLETION_TRIGGER (ur_trigger));
+
+	gtk_source_completion_register_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_test),
+						 GTK_SOURCE_COMPLETION_TRIGGER (ur_trigger));
+
+	gtk_source_completion_set_active (comp, TRUE);
+	
+	g_signal_connect (comp, "show", G_CALLBACK (show_completion_cb), NULL);
+	g_signal_connect (comp, "hide", G_CALLBACK (hide_completion_cb), NULL);
+	
+}
+
+static void
+create_info ()
+{
+	info = gtk_source_completion_info_new ();
+	gtk_source_completion_info_set_adjust_height (info,
+				    TRUE,
+				    -1);
+	gtk_source_completion_info_set_adjust_width (info,
+				   TRUE,
+				   -1);
+}
+
+int
+main (int argc, char *argv[])
+{
+ 	GtkWidget *window;
+	
+	gtk_set_locale ();
+	gtk_init (&argc, &argv);
+
+	window = create_window ();
+	create_completion ();
+	create_info ();
+	
+	g_assert (gtk_source_completion_get_n_pages (comp) == 1);
+	gtk_source_completion_set_page_pos (comp, FIXED_PAGE, 0);
+	
+	gtk_widget_show_all (window);
+
+	gtk_main ();
+	return 0;
+}
+
+

Added: branches/gtksourcecompletion/tests/gsc-provider-test.c
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/gsc-provider-test.c	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,118 @@
+/* 
+ *  gsc-provider-test.c - Type here a short description of your plugin
+ *
+ *  Copyright (C) 2008 - perriman
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gsc-provider-test.h"
+
+static void	 gsc_provider_test_iface_init	(GtkSourceCompletionProviderIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GscProviderTest,
+			 gsc_provider_test,
+			 G_TYPE_OBJECT,
+			 G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROVIDER,
+				 		gsc_provider_test_iface_init))
+
+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)
+{
+	GList *list = NULL;
+	GtkSourceCompletionProposal *prop;
+	
+	prop = gtk_source_completion_proposal_new("Proposal 1",
+				"Info proposal 1",
+				NULL);
+	list = g_list_append (list, prop);
+	prop = gtk_source_completion_proposal_new("Proposal 2",
+				"Info proposal 2",
+				NULL);
+	list = g_list_append (list, prop);
+	prop = gtk_source_completion_proposal_new("Proposal 3",
+				"Info proposal 3",
+				NULL);
+	list = g_list_append (list, prop);
+	
+	/*Page 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");
+	list = g_list_append (list, prop);
+	prop = gtk_source_completion_proposal_new("Proposal 2,2",
+				"Info proposal 2,2",
+				NULL);
+	gtk_source_completion_proposal_set_page_name(prop,"Page 2");
+	list = g_list_append (list, prop);
+	prop = gtk_source_completion_proposal_new("Proposal 3,3",
+				"Info proposal 3,3",
+				NULL);
+	gtk_source_completion_proposal_set_page_name(prop,"Page 3");
+	list = g_list_append (list, prop);
+	prop = gtk_source_completion_proposal_new("Proposal Fixed page",
+				"Info proposal fixed",
+				NULL);
+	gtk_source_completion_proposal_set_page_name(prop,"Fixed");
+	list = g_list_append (list, prop);
+	return list;
+}
+
+static void 
+gsc_provider_test_real_finish (GtkSourceCompletionProvider* base)
+{
+
+}
+
+static void 
+gsc_provider_test_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (gsc_provider_test_parent_class)->finalize (object);
+}
+
+
+static void 
+gsc_provider_test_class_init (GscProviderTestClass *klass)
+{
+	G_OBJECT_CLASS (klass)->finalize = gsc_provider_test_finalize;
+}
+
+static void
+gsc_provider_test_iface_init (GtkSourceCompletionProviderIface *iface)
+{
+	iface->get_name = gsc_provider_test_real_get_name;
+	iface->get_proposals = gsc_provider_test_real_get_proposals;
+	iface->finish = gsc_provider_test_real_finish;
+}
+
+
+static void 
+gsc_provider_test_init (GscProviderTest * self)
+{
+}
+
+GscProviderTest *
+gsc_provider_test_new ()
+{
+	return GSC_PROVIDER_TEST (g_object_new (GSC_TYPE_PROVIDER_TEST, NULL));
+}
+

Added: branches/gtksourcecompletion/tests/gsc-provider-test.h
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/gsc-provider-test.h	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,56 @@
+/* 
+ *  gsc-provider-test.h - Type here a short description of your plugin
+ *
+ *  Copyright (C) 2008 - perriman
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, 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 Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __TEST_PROVIDER_H__
+#define __TEST_PROVIDER_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtksourceview/gtksourcecompletionprovider.h>
+
+G_BEGIN_DECLS
+
+#define GSC_TYPE_PROVIDER_TEST (gsc_provider_test_get_type ())
+#define GSC_PROVIDER_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSC_TYPE_PROVIDER_TEST, GscProviderTest))
+#define GSC_PROVIDER_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSC_TYPE_PROVIDER_TEST, GscProviderTestClass))
+#define GSC_IS_PROVIDER_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSC_TYPE_PROVIDER_TEST))
+#define GSC_IS_PROVIDER_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSC_TYPE_PROVIDER_TEST))
+#define GSC_PROVIDER_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSC_TYPE_PROVIDER_TEST, GscProviderTestClass))
+
+#define GSC_PROVIDER_TEST_NAME "GscProviderTest"
+
+typedef struct _GscProviderTest GscProviderTest;
+typedef struct _GscProviderTestClass GscProviderTestClass;
+
+struct _GscProviderTest
+{
+	GObject parent;
+};
+
+struct _GscProviderTestClass
+{
+	GObjectClass parent;
+};
+
+GType		 gsc_provider_test_get_type	(void) G_GNUC_CONST;
+
+GscProviderTest *gsc_provider_test_new (void);
+
+G_END_DECLS
+
+#endif

Added: branches/gtksourcecompletion/tests/gsc-utils-test.c
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/gsc-utils-test.c	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,429 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *  gsc-utils.c
+ *
+ *  Copyright (C) 2007 - Chuchiperriman <chuchiperriman gmail com>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/**
+ * SECTION:gsc-utils
+ * @title: Gsc Utils
+ * @short_description: Useful functions
+ *
+ */
+ 
+#include <string.h> 
+#include "gsc-utils-test.h"
+
+gboolean
+gsc_char_is_separator(const gunichar ch)
+{
+	if (g_unichar_isprint(ch) && (g_unichar_isalnum(ch) || ch == g_utf8_get_char("_")))
+	{
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+
+gchar*
+gsc_get_last_word_and_iter(GtkTextView *text_view, 
+			   GtkTextIter *start_word, 
+			   GtkTextIter *end_word)
+{
+	GtkTextMark* insert_mark;
+	GtkTextBuffer* text_buffer;
+	GtkTextIter actual,temp;
+	GtkTextIter *start_iter;
+	gchar* text;
+	gunichar ch;
+	gboolean found, no_doc_start;
+	
+	if (start_word != NULL)
+	{
+		start_iter = start_word;
+	}
+	else
+	{
+		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);
+	
+	*start_iter = actual;
+	if (end_word!=NULL)
+	{
+		*end_word = actual;
+	}
+	
+	found = FALSE;
+	while ((no_doc_start = gtk_text_iter_backward_char(start_iter)) == TRUE)
+	{
+		ch = gtk_text_iter_get_char(start_iter);
+		if (gsc_char_is_separator(ch))
+		{
+			found = TRUE;
+			break;
+		}
+	}
+	
+	if (!no_doc_start)
+	{
+		gtk_text_buffer_get_start_iter(text_buffer,start_iter);
+		text = gtk_text_iter_get_text (start_iter, &actual);
+	}
+	else
+	{
+	
+		if (found)
+		{
+			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 = "";
+		}
+	}
+	
+	return text;
+}
+
+gchar*
+gsc_get_last_word(GtkTextView *text_view)
+{
+	return gsc_get_last_word_and_iter(text_view, NULL, NULL);
+}
+
+gchar*
+gsc_get_last_word_cleaned(GtkTextView *view)
+{
+	gchar *word = gsc_get_last_word_and_iter(view, NULL, NULL);
+	gchar *clean_word = gsc_clear_word(word);
+	g_free(word);
+	return clean_word;
+}
+
+void
+gsc_get_cursor_pos(GtkTextView *text_view, 
+		   gint *x, 
+		   gint *y)
+{
+	GdkWindow *win;
+	GtkTextMark* insert_mark;
+	GtkTextBuffer* text_buffer;
+	GtkTextIter start;
+	GdkRectangle location;
+	gint win_x, win_y;
+	gint xx, yy;
+
+	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);
+
+	win = gtk_text_view_get_window (text_view, 
+	                                GTK_TEXT_WINDOW_WIDGET);
+	gdk_window_get_origin (win, &xx, &yy);
+	
+	*x = win_x + xx;
+	*y = win_y + yy + location.height;
+}
+
+gchar*
+gsc_gsv_get_text(GtkTextView *text_view)
+{
+	GtkTextIter start, end;
+	GtkTextBuffer *buffer;
+	
+	buffer = gtk_text_view_get_buffer(text_view);
+	gtk_text_buffer_get_start_iter (buffer, &start);
+	gtk_text_buffer_get_end_iter (buffer, &end);
+	return gtk_text_buffer_get_text(buffer,&start,&end,FALSE);
+	
+}
+
+void
+gtk_source_completion_replace_actual_word(GtkTextView *text_view, 
+			const gchar* text)
+{
+	GtkTextBuffer *buffer;
+	GtkTextIter word_start, word_end;
+	
+	buffer = gtk_text_view_get_buffer(text_view);
+	gtk_text_buffer_begin_user_action(buffer);
+	
+	gsc_get_last_word_and_iter(text_view,&word_start, &word_end);
+
+	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);
+}
+
+gchar*
+gsc_clear_word(const gchar* word)
+{
+	int len = g_utf8_strlen(word,-1);
+	int i;
+	const gchar *temp = word;
+	
+	for (i=0;i<len;i++)
+	{
+		if (gsc_char_is_separator(g_utf8_get_char(temp)))
+			temp = g_utf8_next_char(temp);
+		else
+			return g_strdup(temp);
+		
+	}
+	return NULL;
+}
+
+gchar *
+gsc_compute_line_indentation (GtkTextView *view,
+			      GtkTextIter *cur)
+{
+	GtkTextIter start;
+	GtkTextIter end;
+
+	gunichar ch;
+	gint line;
+
+	line = gtk_text_iter_get_line (cur);
+
+	gtk_text_buffer_get_iter_at_line (gtk_text_view_get_buffer (view),
+					  &start,
+					  line);
+
+	end = start;
+
+	ch = gtk_text_iter_get_char (&end);
+
+	while (g_unichar_isspace (ch) &&
+	       (ch != '\n') &&
+	       (ch != '\r') &&
+	       (gtk_text_iter_compare (&end, cur) < 0))
+	{
+		if (!gtk_text_iter_forward_char (&end))
+			break;
+
+		ch = gtk_text_iter_get_char (&end);
+	}
+
+	if (gtk_text_iter_equal (&start, &end))
+		return NULL;
+
+	return gtk_text_iter_get_slice (&start, &end);
+}
+
+gchar*
+gsc_get_text_with_indent(const gchar* content,gchar *indent)
+{
+	GString *fin = NULL;
+	gchar *ret = NULL;
+	gint len = strlen(content);
+	gint i;
+	gint last_line = 0;
+	for (i=0;i < len;i++)
+	{
+		if (content[i] == '\n' || content[i] =='\r')
+		{
+			if (fin==NULL)
+				fin = g_string_new_len(content,i+1);
+			else
+			{
+				fin = g_string_append_len(fin,
+							  &content[last_line+1],
+							  i - last_line);
+			}
+			fin = g_string_append(fin,indent);
+			last_line = i;
+		}
+	}
+	if (fin==NULL)
+		ret = g_strdup(content);
+	else
+	{
+		if (last_line < len -1)
+		{
+			fin = g_string_append_len(fin,
+						  &content[last_line+1],
+						  len - last_line);
+		}
+		ret = g_string_free(fin,FALSE);
+	}
+	return ret;
+}
+
+
+void
+gsc_insert_text_with_indent(GtkTextView *view, const gchar* text)
+{
+	GtkTextBuffer * buffer = gtk_text_view_get_buffer(view);
+	GtkTextMark *insert = gtk_text_buffer_get_insert(buffer);
+	GtkTextIter cur;
+	gtk_text_buffer_get_iter_at_mark(buffer,&cur,insert);
+	gchar *indent = gsc_compute_line_indentation(view,&cur);
+	gchar *indent_text = gsc_get_text_with_indent(text, indent);
+	g_free(indent);
+	gtk_text_buffer_insert_at_cursor(buffer,indent_text,-1);
+	g_free(indent_text);
+	gtk_text_view_scroll_mark_onscreen(view,insert);
+}
+
+gboolean
+gsc_is_valid_word(gchar *current_word, gchar *completion_word)
+{
+	if (completion_word==NULL)
+		return FALSE;
+	if (current_word==NULL)
+		return TRUE;
+	
+	gint len_cur = g_utf8_strlen (current_word,-1);
+	if (g_utf8_collate(current_word,completion_word) == 0)
+		return FALSE;
+
+	if (len_cur!=0 && strncmp(current_word,completion_word,len_cur)==0)
+		return TRUE;
+
+	return FALSE;
+}
+
+void
+gsc_get_window_position_center_screen(GtkWindow *window, gint *x, gint *y)
+{
+	gint w,h;
+	gint sw = gdk_screen_width();
+	gint sh = gdk_screen_height();
+	gtk_window_get_size(window, &w, &h);
+	*x = (sw/2) - (w/2) - 20;
+	*y = (sh/2) - (h/2);
+}
+
+void
+gsc_get_window_position_center_parent(GtkWindow *window,
+				      GtkWidget *parent,
+				      gint *x,
+				      gint *y)
+{
+	GtkWindow *parent_win = GTK_WINDOW(gtk_widget_get_ancestor(parent,
+				GTK_TYPE_WINDOW));
+	gint w,h,px,py, pw,ph;
+	gtk_window_get_position(parent_win,&px,&py);
+	gtk_window_get_size(parent_win, &pw, &ph);
+	gtk_window_get_size(window, &w, &h);
+	
+	*x = px + ((pw/2) - (w/2) -20);
+	*y = py + ((ph/2) - (h/2));
+}
+
+gboolean 
+gsc_get_window_position_in_cursor(GtkWindow *window,
+				  GtkTextView *view,
+				  gint *x,
+				  gint *y,
+				  gboolean *resized)
+{
+	gint w, h, xtext, ytext, ytemp;
+	gint sw = gdk_screen_width();
+	gint sh = gdk_screen_height();
+	gboolean resize = FALSE;
+	gboolean up = FALSE;
+	gsc_get_cursor_pos(view,x,y);
+	
+	gtk_window_get_size(window, &w, &h);
+	
+	/* Processing x position and width */
+	if (w > (sw - 8))
+	{
+		/* Resize to view all the window */
+		resize = TRUE;
+		w = sw -8;
+	}
+	
+	/* Move position to view all the window */
+	if ((*x + w) > (sw - 4))
+	{
+		*x = sw - w -4;
+	}
+
+	/* Processing y position and height */
+	
+	/* 
+	If we cannot show it down, we show it up and if we cannot show it up, we
+	show the window at the largest position 
+	*/
+	if ((*y + h) > sh)
+	{
+		PangoLayout* layout = 
+			gtk_widget_create_pango_layout(GTK_WIDGET(view), NULL);
+		pango_layout_get_pixel_size(layout,&xtext,&ytext);
+		ytemp = *y - ytext;
+		/* Cabe arriba? */
+		if ((ytemp - h) >= 4)
+		{
+			*y = ytemp - h;
+			up = TRUE;
+		}
+		else
+		{
+			/* 
+			Si no cabe arriba, lo ponemos donde haya mÃs espacio
+			y redimensionamos la ventana
+			*/
+			if ((sh - *y) > ytemp)
+			{
+				h = sh - *y - 4;
+			}
+			else
+			{
+				*y = 4;
+				h = ytemp -4;
+				up = TRUE;
+			}
+			resize = TRUE;
+		}
+		g_object_unref(layout);
+	}
+	
+	if (resize)
+		gtk_window_resize(window, w, h);
+
+	if (resized != NULL)
+		*resized = resize;
+	
+	return up;
+}
+
+
+

Added: branches/gtksourcecompletion/tests/gsc-utils-test.h
==============================================================================
--- (empty file)
+++ branches/gtksourcecompletion/tests/gsc-utils-test.h	Wed Apr  8 16:28:41 2009
@@ -0,0 +1,207 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *  gsc-utils.h
+ *
+ *  Copyright (C) 2007 - Chuchiperriman <chuchiperriman gmail com>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library 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
+ *  Lesser General Public License for more details.
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef GTK_SNIPPETS_GSV_UTILS_H
+#define GTK_SNIPPETS_GSV_UTILS_H
+
+#include <gtk/gtk.h>
+
+/**
+* gsc_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*
+gsc_get_last_word_and_iter(GtkTextView *text_view, 
+					GtkTextIter *start_word, 
+					GtkTextIter *end_word);
+
+/**
+ * gsc_get_last_word:
+ * @text_view: The #GtkTextView
+ *
+ * Returns: the last word written in the #GtkTextView or ""
+ */
+gchar*
+gsc_get_last_word(GtkTextView *text_view);
+
+/**
+ * gsc_get_last_word_cleaned:
+ * @text_view: The #GtkTextView
+ *
+ * See #gsc_get_last_word and #gsc_clear_word
+ *
+ * Returns: the last word written in the #GtkTextView or "" (new allocated)
+ */
+gchar*
+gsc_get_last_word_cleaned(GtkTextView *text_view);
+
+/** 
+ * gsc_get_cursor_pos:
+ * @text_view: The #GtkTextView
+ * @x: Assign the x position of the cursor
+ * @y: Assign the y position of the cursor
+ *
+ * Gets the cursor position on the screen.
+ */
+void
+gsc_get_cursor_pos(GtkTextView *text_view, 
+				gint *x, 
+				gint *y);
+
+/**
+ * gsc_gsv_get_text: 
+ * @text_view: The #GtkTextView 
+ *
+ * Returns All the #GtkTextView content .
+ */
+gchar* 
+gsc_gsv_get_text(GtkTextView *text_view);
+
+/**
+ * gsc_replace_actual_word:
+ * @text_view: The #GtkTextView
+ * @text: The text to be inserted instead of the current word
+ * 
+ * Replaces the current word in the #GtkTextView with the new word
+ *
+ */
+void
+gtk_source_completion_replace_actual_word(GtkTextView *text_view, 
+				    const gchar* text);
+
+/**
+ * gsc_char_is_separator:
+ * @ch: The character to check
+ *
+ * A separator is a character like (, an space etc. An _ is not a separator
+ *
+ * Returns TRUE if the ch is a separator
+ */
+gboolean
+gsc_char_is_separator(gunichar ch);
+
+/**
+ * gsc_clear_word:
+ * @word: The word to be cleaned
+ * 
+ * Clean the word eliminates the special characters at the start of this word.
+ * By example "$variable" is cleaned to "variable"
+ *
+ * Returns New allocated string with the word cleaned. If all characters are 
+ * separators, it return NULL;
+ *
+ */
+gchar*
+gsc_clear_word(const gchar* word);
+
+/**
+ * gsc_compute_line_indentation:
+ * @view: The #GtkTextView
+ * @cur: Cursor in the line where we compute the indentation
+ *
+ * Returns: New allocated string with the indentation of this line
+ */
+gchar *
+gsc_compute_line_indentation (GtkTextView *view,
+			     GtkTextIter *cur);
+
+/**
+ * gsc_get_text_with_indent:
+ * @content: The initial text to indent
+ * @indent: Indentation string. You can get the indentation of a line with
+ * #gsc_compute_line_indentation.
+ *
+ * Returns: New allocated string with the content indented.
+ */
+gchar*
+gsc_get_text_with_indent(const gchar* content,gchar *indent);
+
+/**
+ * gsc_insert_text_with_indent:
+ * @view: The #GtkTextView where we will insert the indented text
+ * @text: Text to indent and insert into the view.
+ *
+ * This function indent the text and insert it into the view in the current
+ * position.
+ */
+void
+gsc_insert_text_with_indent(GtkTextView *view, const gchar* text);
+
+/**
+ * gsc_is_valid_word:
+ * @current_word: The current word 
+ * @completion_word: The completion word
+ *
+ * Returns: TRUE if the completion_word starts with current_word and it is not
+ * the same word.
+ */
+gboolean
+gsc_is_valid_word(gchar *current_word, gchar *completion_word);
+
+/**
+ * gsc_get_window_position_in_cursor:
+ * @window: Window to set
+ * @view: Parent view where we get the cursor position
+ * @x: The returned x position
+ * @y: The returned y position
+ *
+ * Returns: TRUE if the position is over the text and FALSE if 
+ * the position is under the text.
+ */
+gboolean 
+gsc_get_window_position_in_cursor(GtkWindow *window,
+				  GtkTextView *view,
+				  gint *x,
+				  gint *y,
+				  gboolean *resized);
+
+/**
+ * gsc_get_window_position_center_screen:
+ * @window: Window to set
+ * @x: The returned x position
+ * @y: The returned y position
+ *
+ * Assing x and y values to center the window in the screen
+ *
+ */
+void
+gsc_get_window_position_center_screen(GtkWindow *window, gint *x, gint *y);
+
+/**
+ * gsc_get_window_position_center_parent:
+ * @window: Window to set
+ * @parent: Parent widget where we want to center the window
+ * @x: The returned x position
+ * @y: The returned y position
+ *
+ * Assing x and y values to center the window in the parent widget
+ *
+ */
+void
+gsc_get_window_position_center_parent(GtkWindow *window,
+				      GtkWidget *parent,
+				      gint *x,
+				      gint *y);
+
+#endif 



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