[gtksourceview/gtksourcecompletion] Place the popup at the beggining of the word.



commit b136ebbc6bc6c54c967164e0e2c735b9e5d36a53
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Apr 22 15:36:21 2009 +0200

    Place the popup at the beggining of the word.
    
    Now with the typing poping it popups the window at the beggining of the word.
---
 gtksourceview/gtksourcecompletion.c |   29 ++++++++++++++++++++++-------
 gtksourceview/gtksourcecompletion.h |    3 ++-
 gtksourceview/gtksourceview.c       |    2 +-
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index ec99cb6..e889485 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -1072,6 +1072,7 @@ show_auto_completion (GtkSourceCompletion *completion)
 	GtkTextBuffer *buffer;
 	GtkTextMark *insert_mark;
 	GtkTextIter iter;
+	GtkTextIter word_start;
 	gchar *word;
 	
 	completion->priv->show_timed_out_id = 0;
@@ -1088,12 +1089,14 @@ show_auto_completion (GtkSourceCompletion *completion)
 		return FALSE;
 	}
 	
-	word = gtk_source_completion_utils_get_word (GTK_SOURCE_BUFFER (buffer));
+	word = gtk_source_completion_utils_get_word_iter (GTK_SOURCE_BUFFER (buffer),
+							  &word_start, NULL);
 	
 	/* Check minimum amount of characters */
 	if (g_utf8_strlen (word, -1) >= completion->priv->minimum_auto_complete_length)
 	{
-		gtk_source_completion_show (completion, completion->priv->interactive_providers, word);
+		gtk_source_completion_show (completion, completion->priv->interactive_providers,
+					    word, &word_start);
 	}
 
 	g_free (word);
@@ -1368,9 +1371,6 @@ gtk_source_completion_hide_default (GtkSourceCompletion *completion)
 static void
 gtk_source_completion_show_default (GtkSourceCompletion *completion)
 {
-	gtk_source_completion_utils_move_to_cursor (GTK_WINDOW (completion->priv->window),
-						    GTK_SOURCE_VIEW (completion->priv->view));
-	
 	gtk_widget_show (GTK_WIDGET (completion->priv->window));
 	gtk_widget_grab_focus (GTK_WIDGET (completion->priv->view));
 
@@ -1985,15 +1985,18 @@ add_proposals (GtkSourceCompletion         *completion,
  * @completion: the #GtkSourceCompletion
  * @providers: the list of #GtkSourceCompletionProvider
  * @criteria: the filter criteria
+ * @place: the place where you want to situate the popup window, or %NULL
  *
- * Shows the show completion window.
+ * Shows the show completion window. If @place if %NULL the popup window will
+ * be placed on the cursor position.
  *
  * Returns: %TRUE if it was possible show the show completion window.
  */
 gboolean
 gtk_source_completion_show (GtkSourceCompletion *completion,
                             GList               *providers,
-                            const gchar         *criteria)
+                            const gchar         *criteria,
+                            GtkTextIter         *place)
 {
 	GList *l;
 
@@ -2034,6 +2037,18 @@ gtk_source_completion_show (GtkSourceCompletion *completion,
 	completion->priv->active_providers = 
 		g_list_reverse (completion->priv->active_providers);
 	
+	if (place == NULL)
+	{
+		gtk_source_completion_utils_move_to_cursor (GTK_WINDOW (completion->priv->window),
+							    GTK_SOURCE_VIEW (completion->priv->view));
+	}
+	else
+	{
+		gtk_source_completion_utils_move_to_iter (GTK_WINDOW (completion->priv->window),
+							  GTK_SOURCE_VIEW (completion->priv->view),
+							  place);
+	}
+	
 	return TRUE;
 }
 
diff --git a/gtksourceview/gtksourcecompletion.h b/gtksourceview/gtksourcecompletion.h
index 4d82352..b9c4989 100644
--- a/gtksourceview/gtksourcecompletion.h
+++ b/gtksourceview/gtksourcecompletion.h
@@ -77,7 +77,8 @@ gboolean	 gtk_source_completion_remove_provider		(GtkSourceCompletion         *c
 
 gboolean	 gtk_source_completion_show			(GtkSourceCompletion         *completion,
 								 GList                       *providers,
-								 const gchar                 *criteria);
+								 const gchar                 *criteria,
+								 GtkTextIter                 *place);
 
 void		 gtk_source_completion_hide			(GtkSourceCompletion         *completion);
 
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 988d74e..7fd2074 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -4061,7 +4061,7 @@ gtk_source_view_show_completion	(GtkSourceView *view,
 	g_return_if_fail (GTK_IS_SOURCE_VIEW (view));
 
 	completion = gtk_source_view_get_completion (view);
-	gtk_source_completion_show (completion, proposals, NULL);
+	gtk_source_completion_show (completion, proposals, NULL, NULL);
 }
 							 
 /**



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