gtksourceview r2283 - branches/gtksourcecompletion/gtksourceview



Author: jessevdk
Date: Tue Apr 14 07:29:53 2009
New Revision: 2283
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2283&view=rev

Log:
Fixed small issue with counting visible providers


Modified:
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c
   branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c	Tue Apr 14 07:29:53 2009
@@ -407,23 +407,19 @@
 }
 
 static void
-update_selection_label (GtkSourceCompletion *completion)
+get_num_visible_providers (GtkSourceCompletion *completion,
+                           guint               *num,
+                           guint               *current)
 {
 	GList *item;
-	gint pos = 1;
-	gint num = 1;
-	gint idx = 1;
-	gchar *name;
-	gchar *tmp;
+	*num = 0;
+	*current = 0;
 	
 	for (item = completion->priv->active_providers; item; item = g_list_next (item))
 	{
-		++idx;
-
 		if (item->data == completion->priv->filter_provider)
 		{
-			pos = idx;
-			++num;
+			*current = ++*num;
 		}
 		else
 		{
@@ -431,10 +427,21 @@
 			if (gtk_source_completion_model_n_proposals (completion->priv->model_proposals,
 			                                             GTK_SOURCE_COMPLETION_PROVIDER (item->data)))
 			{
-				++num;
+				++*num;
 			}
 		}
 	}
+}
+
+static void
+update_selection_label (GtkSourceCompletion *completion)
+{
+	guint pos;
+	guint num;
+	gchar *name;
+	gchar *tmp;
+	
+	get_num_visible_providers (completion, &num, &pos);
 	
 	if (completion->priv->filter_provider == NULL)
 	{
@@ -454,7 +461,7 @@
 	
 	if (num > 1)
 	{
-		tmp = g_strdup_printf ("%s (%d/%d)", name, pos, num);
+		tmp = g_strdup_printf ("%s (%d/%d)", name, pos + 1, num + 1);
 		gtk_label_set_markup (GTK_LABEL (completion->priv->selection_label),
 		                      tmp);
 		g_free (tmp);
@@ -497,12 +504,31 @@
 	GList *orig;
 	GList *current;
 	GtkSourceCompletionProvider *provider;
-
+	guint num;
+	guint pos;
+	
 	/* If there is only one provider, then there is no other selection */
 	if (completion->priv->active_providers->next == NULL)
 	{
 		return FALSE;
 	}
+	
+	get_num_visible_providers (completion, &num, &pos);
+	
+	if (num <= 1)
+	{
+		if (completion->priv->filter_provider != NULL)
+		{
+			completion->priv->filter_provider = NULL;
+			
+			update_selection_label (completion);
+			do_refilter (completion, FALSE);
+			
+			return TRUE;
+		}
+
+		return FALSE;
+	}
 
 	if (completion->priv->filter_provider != NULL)
 	{

Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c	(original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c	Tue Apr 14 07:29:53 2009
@@ -845,20 +845,20 @@
 gtk_source_completion_model_n_proposals (GtkSourceCompletionModel    *model,
                                          GtkSourceCompletionProvider *provider)
 {
-	guint *num;
+	HeaderInfo *info;
 	
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_MODEL (model), 0);
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_PROVIDER (provider), 0);
 	
-	num = g_hash_table_lookup (model->priv->num_per_provider, provider);
+	info = g_hash_table_lookup (model->priv->num_per_provider, provider);
 	
-	if (num == NULL)
+	if (info == NULL)
 	{
 		return 0;
 	}
 	else
 	{
-		return *num;
+		return info->num;
 	}
 }
 



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