[recipes] Sort list pages alphabetically



commit c4107390d103ab42f2a375732bc7874b87ab6f59
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 25 22:32:55 2017 -0400

    Sort list pages alphabetically
    
    This covers all of the category and chef pages.

 src/gr-list-page.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-list-page.c b/src/gr-list-page.c
index 9368f5d..69759cc 100644
--- a/src/gr-list-page.c
+++ b/src/gr-list-page.c
@@ -190,6 +190,21 @@ search_finished (GrRecipeSearch *search,
                                           page->count > 0 ? "list" : "empty");
 }
 
+static int
+sort_func (GtkFlowBoxChild *child1,
+           GtkFlowBoxChild *child2,
+           gpointer         data)
+{
+        GtkWidget *tile1 = gtk_bin_get_child (GTK_BIN (child1));
+        GtkWidget *tile2 = gtk_bin_get_child (GTK_BIN (child2));
+        GrRecipe *recipe1 = gr_recipe_tile_get_recipe (GR_RECIPE_TILE (tile1));
+        GrRecipe *recipe2 = gr_recipe_tile_get_recipe (GR_RECIPE_TILE (tile2));
+        const char *name1 = gr_recipe_get_name (recipe1);
+        const char *name2 = gr_recipe_get_name (recipe2);
+
+        return strcmp (name1, name2);
+}
+
 static void
 gr_list_page_init (GrListPage *page)
 {
@@ -202,6 +217,8 @@ gr_list_page_init (GrListPage *page)
         g_signal_connect (page->search, "hits-added", G_CALLBACK (search_hits_added), page);
         g_signal_connect (page->search, "hits-removed", G_CALLBACK (search_hits_removed), page);
         g_signal_connect (page->search, "finished", G_CALLBACK (search_finished), page);
+
+        gtk_flow_box_set_sort_func (GTK_FLOW_BOX (page->flow_box), sort_func, page, NULL);
 }
 
 static void


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