[gtksourceview/gtksourcecompletion] Added automatic per provider window positioning



commit 5b042d3eb693364f3dc1bc571f2f4f9985c2ebbf
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sat Sep 19 21:22:33 2009 +0200

    Added automatic per provider window positioning
    
    Added gsc_provider_get_start_iter. This is used when the selected
    proposal changes to move the window to the start of what the proposal
    is proposing to complete

 gtksourceview/gtksourcecompletion.c         |   27 ++++++++++++++++++++++
 gtksourceview/gtksourcecompletionprovider.c |   23 +++++++++++++++++++
 gtksourceview/gtksourcecompletionprovider.h |    7 ++++++
 tests/gsc-provider-devhelp.c                |   32 +++++++++++++++-----------
 4 files changed, 75 insertions(+), 14 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 48d6d8a..94d2ca8 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -907,6 +907,30 @@ update_proposal_info (GtkSourceCompletion *completion)
 	}
 }
 
+static void
+update_window_position (GtkSourceCompletion *completion)
+{
+	GtkSourceCompletionProvider *provider;
+	GtkSourceCompletionProposal *proposal;
+	
+	if (get_selected_proposal (completion, NULL, &provider, &proposal))
+	{
+		GtkTextIter iter;
+		
+		if (gtk_source_completion_provider_get_start_iter (provider, 
+		                                                   proposal, 
+		                                                   &iter))
+		{
+			gtk_source_completion_utils_move_to_iter (GTK_WINDOW (completion->priv->window),
+			                                          GTK_SOURCE_VIEW (completion->priv->view),
+			                                          &iter);
+		}
+		
+		g_object_unref (provider);
+		g_object_unref (proposal);
+	}
+}
+
 static void 
 selection_changed_cb (GtkTreeSelection    *selection, 
 		      GtkSourceCompletion *completion)
@@ -930,6 +954,9 @@ selection_changed_cb (GtkTreeSelection    *selection,
 	{
 		update_proposal_info (completion);
 	}
+	
+	/* Update window position if needed */
+	update_window_position (completion);
 }
 
 static void
diff --git a/gtksourceview/gtksourcecompletionprovider.c b/gtksourceview/gtksourcecompletionprovider.c
index df18511..158636d 100644
--- a/gtksourceview/gtksourcecompletionprovider.c
+++ b/gtksourceview/gtksourcecompletionprovider.c
@@ -92,6 +92,14 @@ gtk_source_completion_provider_update_info_default (GtkSourceCompletionProvider
 }
 
 static gboolean
+gtk_source_completion_provider_get_start_iter_default (GtkSourceCompletionProvider *provider,
+                                                       GtkSourceCompletionProposal *proposal,
+                                                       GtkTextIter                 *iter)
+{
+	return FALSE;
+}
+
+static gboolean
 gtk_source_completion_provider_activate_proposal_default (GtkSourceCompletionProvider *provider,
                                                           GtkSourceCompletionProposal *proposal,
                                                           GtkTextIter                 *iter)
@@ -116,6 +124,7 @@ gtk_source_completion_provider_base_init (GtkSourceCompletionProviderIface *ifac
 	iface->get_info_widget = gtk_source_completion_provider_get_info_widget_default;
 	iface->update_info = gtk_source_completion_provider_update_info_default;
 	
+	iface->get_start_iter = gtk_source_completion_provider_get_start_iter_default;
 	iface->activate_proposal = gtk_source_completion_provider_activate_proposal_default;
 
 	if (!initialized)
@@ -287,6 +296,20 @@ gtk_source_completion_provider_update_info (GtkSourceCompletionProvider *provide
 	GTK_SOURCE_COMPLETION_PROVIDER_GET_INTERFACE (provider)->update_info (provider, proposal, info);
 }
 
+gboolean
+gtk_source_completion_provider_get_start_iter (GtkSourceCompletionProvider *provider,
+                                               GtkSourceCompletionProposal *proposal,
+                                               GtkTextIter                 *iter)
+{
+	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROVIDER (provider), FALSE);
+	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROPOSAL (proposal), FALSE);
+	g_return_val_if_fail (iter != NULL, FALSE);
+	
+	return GTK_SOURCE_COMPLETION_PROVIDER_GET_INTERFACE (provider)->get_start_iter (provider, 
+	                                                                                proposal,
+	                                                                                iter);
+}
+
 /**
  * gtk_source_completion_provider_activate_proposal:
  * @provider: A #GtkSourceCompletionProvider
diff --git a/gtksourceview/gtksourcecompletionprovider.h b/gtksourceview/gtksourcecompletionprovider.h
index 6077ba7..730062e 100644
--- a/gtksourceview/gtksourcecompletionprovider.h
+++ b/gtksourceview/gtksourcecompletionprovider.h
@@ -66,6 +66,9 @@ struct _GtkSourceCompletionProviderIface
 						 GtkSourceCompletionProposal *proposal,
 						 GtkSourceCompletionInfo     *info);
 
+	gboolean	 (*get_start_iter)	(GtkSourceCompletionProvider *provider,
+						 GtkSourceCompletionProposal *proposal,
+						 GtkTextIter                 *iter);
 	gboolean	 (*activate_proposal)	(GtkSourceCompletionProvider *provider,
 						 GtkSourceCompletionProposal *proposal,
 						 GtkTextIter                 *iter);
@@ -94,6 +97,10 @@ void 		 gtk_source_completion_provider_update_info	(GtkSourceCompletionProvider
 								 GtkSourceCompletionProposal *proposal,
 								 GtkSourceCompletionInfo     *info);
 
+gboolean	 gtk_source_completion_provider_get_start_iter	(GtkSourceCompletionProvider *provider,
+								 GtkSourceCompletionProposal *proposal,
+								 GtkTextIter                 *iter);
+
 gboolean	 gtk_source_completion_provider_activate_proposal (GtkSourceCompletionProvider *provider,
 								   GtkSourceCompletionProposal *proposal,
 								   GtkTextIter                 *iter);
diff --git a/tests/gsc-provider-devhelp.c b/tests/gsc-provider-devhelp.c
index 16efa96..55de543 100644
--- a/tests/gsc-provider-devhelp.c
+++ b/tests/gsc-provider-devhelp.c
@@ -28,6 +28,8 @@ struct _GscProviderDevhelpPrivate
 	DhBase *dhbase;
 	GtkWidget *view;
 	GdkPixbuf *icon;
+	
+	GtkTextIter completion_iter;
 	gchar *word;
 
 	GList *dhptr;
@@ -152,7 +154,8 @@ is_word_char (gunichar ch)
 }
 
 static gchar *
-get_word_at_iter (GtkTextIter *iter)
+get_word_at_iter (GscProviderDevhelp *devhelp,
+                  GtkTextIter        *iter)
 {
 	GtkTextIter start = *iter;
 	gint line = gtk_text_iter_get_line (iter);
@@ -180,6 +183,7 @@ get_word_at_iter (GtkTextIter *iter)
 		return NULL;
 	}
 	
+	devhelp->priv->completion_iter = start;
 	return gtk_text_iter_get_text (&start, iter);
 }
 
@@ -221,7 +225,7 @@ add_in_idle (GscProviderDevhelp *devhelp)
 				break;
 			}
 		}
-		
+
 		++idx;
 		devhelp->priv->idleptr = g_list_next (devhelp->priv->idleptr);
 	}
@@ -260,18 +264,7 @@ gsc_provider_devhelp_populate (GtkSourceCompletionProvider *provider,
 	devhelp->priv->context = g_object_ref (context);
 
 	gtk_source_completion_context_get_iter (context, &iter);
-	devhelp->priv->word = get_word_at_iter (&iter);
-	
-	if (devhelp->priv->word)
-	{
-		gchar *last = g_utf8_prev_char (devhelp->priv->word + strlen (devhelp->priv->word));
-		gunichar l = g_utf8_get_char (last);
-		
-		if (l == ':' || l == '.')
-		{
-			gtk_source_completion_context_move_window (context, &iter);
-		}
-	}
+	devhelp->priv->word = get_word_at_iter (devhelp, &iter);
 	
 	/* Do first right now */
 	if (add_in_idle (devhelp))
@@ -305,6 +298,15 @@ gsc_provider_devhelp_get_icon (GtkSourceCompletionProvider *provider)
 	return GSC_PROVIDER_DEVHELP (provider)->priv->icon;
 }
 
+static gboolean
+gsc_provider_devhelp_get_start_iter (GtkSourceCompletionProvider *provider,
+                                     GtkSourceCompletionProposal *proposal,
+                                     GtkTextIter                 *iter)
+{
+	*iter = GSC_PROVIDER_DEVHELP (provider)->priv->completion_iter;
+	return TRUE;
+}
+
 static void
 gsc_provider_devhelp_iface_init (GtkSourceCompletionProviderIface *iface)
 {
@@ -315,6 +317,8 @@ gsc_provider_devhelp_iface_init (GtkSourceCompletionProviderIface *iface)
 	iface->update_info = gsc_provider_devhelp_update_info;
 	
 	iface->get_icon = gsc_provider_devhelp_get_icon;
+	
+	iface->get_start_iter = gsc_provider_devhelp_get_start_iter;
 }
 
 static void



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