[Xfce4-commits] <xfce4-appfinder:master> Only show categories with items.

Nick Schermer noreply at xfce.org
Tue Dec 27 15:30:02 CET 2011


Updating branch refs/heads/master
         to 30518c8a496bab6b912b3dbff9a2bf9be858e0fb (commit)
       from 4c2b6cc66f7318515e438fbda3801cc789c57dc0 (commit)

commit 30518c8a496bab6b912b3dbff9a2bf9be858e0fb
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Dec 27 15:11:37 2011 +0100

    Only show categories with items.

 src/appfinder-model.c  |   78 +++++++++++++++++++++++++++++++++++++++++++++--
 src/appfinder-window.c |    4 +-
 2 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/src/appfinder-model.c b/src/appfinder-model.c
index 1cc45ea..b90d825 100644
--- a/src/appfinder-model.c
+++ b/src/appfinder-model.c
@@ -114,6 +114,7 @@ struct _XfceAppfinderModel
   GarconMenuDirectory   *command_category;
 
   GSList                *categories;
+  guint                  categories_changed_idle_id;
 
   guint                  collect_idle_id;
   GSList                *collect_items;
@@ -306,6 +307,9 @@ xfce_appfinder_model_finalize (GObject *object)
     g_source_remove (model->collect_idle_id);
   g_slist_free (model->collect_categories);
 
+  if (G_UNLIKELY (model->categories_changed_idle_id != 0))
+    g_source_remove (model->categories_changed_idle_id);
+
   /* stop history file monitoring */
   xfce_appfinder_model_history_monitor_stop (model);
 
@@ -640,6 +644,34 @@ xfce_appfinder_model_iter_parent (GtkTreeModel *tree_model,
 
 
 static gboolean
+xfce_appfinder_model_categories_changed_idle (gpointer data)
+{
+  XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (data);
+
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+
+  model->categories_changed_idle_id = 0;
+
+  g_signal_emit (G_OBJECT (model), model_signals[CATEGORIES_CHANGED], 0);
+
+  return FALSE;
+}
+
+
+
+static void
+xfce_appfinder_model_categories_changed (XfceAppfinderModel *model)
+{
+  if (model->categories_changed_idle_id == 0)
+    {
+      model->categories_changed_idle_id =
+        g_idle_add_full (G_PRIORITY_HIGH_IDLE, xfce_appfinder_model_categories_changed_idle, model, NULL);
+    }
+}
+
+
+
+static gboolean
 xfce_appfinder_model_collect_idle (gpointer user_data)
 {
   XfceAppfinderModel *model = XFCE_APPFINDER_MODEL (user_data);
@@ -699,7 +731,7 @@ xfce_appfinder_model_collect_idle (gpointer user_data)
       model->categories = model->collect_categories;
       model->collect_categories = NULL;
 
-      g_signal_emit (G_OBJECT (model), model_signals[CATEGORIES_CHANGED], 0);
+      xfce_appfinder_model_categories_changed (model);
 
       g_slist_foreach (tmp, (GFunc) xfce_appfinder_model_category_free, NULL);
       g_slist_free (tmp);
@@ -826,6 +858,7 @@ xfce_appfinder_model_item_changed (GarconMenuItem     *menu_item,
   GtkTreeIter  iter;
   GtkTreePath *path;
   GPtrArray   *categories;
+  gboolean     old_not_visible;
 
   /* lookup the item in the list */
   for (li = model->items, idx = 0; li != NULL; li = li->next, idx++)
@@ -838,6 +871,8 @@ xfce_appfinder_model_item_changed (GarconMenuItem     *menu_item,
 
           APPFINDER_DEBUG ("update item %s", garcon_menu_item_get_desktop_id (menu_item));
 
+          old_not_visible = item->not_visible;
+
           xfce_appfinder_model_item_free (item, model);
 
           item = xfce_appfinder_model_item_new (menu_item);
@@ -857,6 +892,10 @@ xfce_appfinder_model_item_changed (GarconMenuItem     *menu_item,
           gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
           gtk_tree_path_free (path);
 
+          /* update the categories if the visibility changed */
+          if (old_not_visible != item->not_visible)
+            xfce_appfinder_model_categories_changed (model);
+
           break;
         }
     }
@@ -1155,7 +1194,7 @@ xfce_appfinder_model_category_free (CategoryItem *item)
 
 
 
-static gboolean
+static inline gboolean
 xfce_appfinder_model_ptr_array_find (GPtrArray     *array,
                                      gconstpointer  data)
 {
@@ -1461,7 +1500,7 @@ xfce_appfinder_model_menu_changed (GarconMenu         *menu,
           model->categories = collect_categories;
           collect_categories = tmp;
 
-          g_signal_emit (G_OBJECT (model), model_signals[CATEGORIES_CHANGED], 0);
+          xfce_appfinder_model_categories_changed (model);
 
           break;
         }
@@ -1573,8 +1612,39 @@ xfce_appfinder_model_get (void)
 GSList *
 xfce_appfinder_model_get_categories (XfceAppfinderModel *model)
 {
+  GSList       *categories = NULL;
+  GSList       *li, *lp;
+  CategoryItem *category;
+  gboolean      visible;
+  ModelItem    *item;
+
   appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
-  return model->categories;
+
+  for (li = model->categories; li != NULL; li = li->next)
+    {
+      category = li->data;
+      appfinder_assert (GARCON_IS_MENU_DIRECTORY (category->directory));
+      visible = FALSE;
+
+      /* check if the category has a visible item */
+      for (lp = model->items; lp != NULL; lp = lp->next)
+        {
+          item = lp->data;
+          if (!item->not_visible
+              && xfce_appfinder_model_ptr_array_find (item->categories, category->directory))
+            {
+              visible = TRUE;
+              break;
+            }
+        }
+
+      if (!visible)
+        continue;
+
+      categories = g_slist_prepend (categories, category);
+    }
+
+  return g_slist_reverse (categories);
 }
 
 
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index 20784f5..4cf1133 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -353,8 +353,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
       G_CALLBACK (xfce_appfinder_window_icon_theme_changed), window);
 
   /* load categories in the model */
-  if (xfce_appfinder_model_get_categories (window->model) != NULL)
-    xfce_appfinder_window_category_set_categories (window);
+  xfce_appfinder_window_category_set_categories (window);
   g_signal_connect_swapped (G_OBJECT (window->model), "categories-changed",
                             G_CALLBACK (xfce_appfinder_window_category_set_categories),
                             window);
@@ -970,6 +969,7 @@ xfce_appfinder_window_category_set_categories (XfceAppfinderWindow *window)
   categories = xfce_appfinder_model_get_categories (window->model);
   if (categories != NULL)
     xfce_appfinder_category_model_set_categories (window->category_model, categories);
+  g_slist_free (categories);
 
   if (xfconf_channel_get_bool (window->channel, "/remember-category", FALSE))
     name = xfconf_channel_get_string (window->channel, "/last/category", NULL);


More information about the Xfce4-commits mailing list