[SF#FR#261]Sort plugins in Add plugin window in alphabetic order.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Fri, 21 Nov 2014 17:15:50 +0000 (19:15 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Fri, 21 Nov 2014 17:15:50 +0000 (19:15 +0200)
It is more convenient than have them unsorted.

ChangeLog
src/configurator.c

index 7e9887c..aa3caa0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -64,6 +64,7 @@
 * Fixed border of 'batt' plugin, it should correctly use panel settings.
     Also 'Size' setting of it doesn't include border width.
 * Allowed default alarmCommand on 'batt' plugin be translated.
+* Implemented sorting plugins in Add plugin window in alphabetic order.
 
 0.7.2
 -------------------------------------------------------------------------
index 3b0f64e..b70bb38 100644 (file)
@@ -716,6 +716,19 @@ static void on_add_plugin_response( GtkDialog* dlg,
     gtk_widget_destroy( GTK_WIDGET(dlg) );
 }
 
+static gint sort_by_name(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data)
+{
+    char *str_a, *str_b;
+    gint res;
+
+    gtk_tree_model_get(model, a, 0, &str_a, -1);
+    gtk_tree_model_get(model, b, 0, &str_b, -1);
+    res = g_utf8_collate(str_a, str_b);
+    g_free(str_a);
+    g_free(str_b);
+    return res;
+}
+
 static void on_add_plugin( GtkButton* btn, GtkTreeView* _view )
 {
     GtkWidget* dlg, *parent_win, *scroll;
@@ -789,6 +802,11 @@ static void on_add_plugin( GtkButton* btn, GtkTreeView* _view )
             /* g_debug( "%s (%s)", pc->type, _(pc->name) ); */
         }
     }
+    gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(list),
+                                            sort_by_name, NULL, NULL);
+    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list),
+                                         GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
+                                         GTK_SORT_ASCENDING);
 
     gtk_tree_view_set_model( view, GTK_TREE_MODEL(list) );
     g_object_unref( list );