[gtksourceview] Completion: simplify get_num_visible_providers()



commit 0a8aefb88a2f7a4261ff5660b78764de81af845e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Feb 27 14:59:46 2013 +0100

    Completion: simplify get_num_visible_providers()

 gtksourceview/gtksourcecompletion.c |   32 ++++++++------------------------
 1 files changed, 8 insertions(+), 24 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index e35c1ee..cc08aee 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -503,34 +503,18 @@ get_num_visible_providers (GtkSourceCompletion *completion,
                            guint               *num,
                            guint               *current)
 {
-       GList *providers;
-       GList *item;
-       GtkSourceCompletionProvider *visible;
-
-       visible = get_visible_provider (completion);
+       GList *providers = gtk_source_completion_model_get_providers (completion->priv->model_proposals);
+       GtkSourceCompletionProvider *visible = get_visible_provider (completion);
 
-       *num = 0;
+       *num = g_list_length (providers);
        *current = 0;
 
-       providers = gtk_source_completion_model_get_providers (completion->priv->model_proposals);
-
-       for (item = providers; item; item = g_list_next (item))
+       if (visible != NULL)
        {
-               /* This works for now since we only show either all providers,
-                  or a single one */
-               if (item->data == visible)
-               {
-                       *current = ++*num;
-               }
-               else
-               {
-                       /* See if it has anything */
-                       if (gtk_source_completion_model_n_proposals (completion->priv->model_proposals,
-                                                                    GTK_SOURCE_COMPLETION_PROVIDER 
(item->data)))
-                       {
-                               ++*num;
-                       }
-               }
+               gint idx = g_list_index (providers, visible);
+               g_return_if_fail (idx != -1);
+
+               *current = idx + 1;
        }
 
        g_list_free (providers);


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