Add sort button for Associations

This commit is contained in:
Robert Fewell 2016-08-02 09:41:07 +01:00 committed by John Ralls
parent a860643922
commit 531f0f3c37
2 changed files with 71 additions and 2 deletions

View File

@ -86,6 +86,56 @@ gnc_assoc_dialog_close_cb (GtkDialog *dialog, gpointer user_data)
LEAVE(" ");
}
static gint
sort_iter_compare_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
gint ret = 0;
gchar *uri1, *uri2;
gtk_tree_model_get (model, a, URI, &uri1, -1);
gtk_tree_model_get (model, b, URI, &uri2, -1);
ret = g_utf8_collate (uri1, uri2);
g_free (uri1);
g_free (uri2);
return ret;
}
static void
assoc_dialog_sort (AssocDialog *assoc_dialog)
{
GtkTreeModel *model;
GtkTreeSortable *sortable;
gint id;
GtkSortType order;
model = gtk_tree_view_get_model (GTK_TREE_VIEW(assoc_dialog->view));
sortable = GTK_TREE_SORTABLE(model);
if (gtk_tree_sortable_get_sort_column_id (sortable, &id, &order))
{
if (order == GTK_SORT_ASCENDING)
order = GTK_SORT_DESCENDING;
else
order = GTK_SORT_ASCENDING;
}
else
{
gtk_tree_sortable_set_sort_func (sortable, URI, sort_iter_compare_func,
assoc_dialog, NULL);
order = GTK_SORT_ASCENDING;
}
/* set sort order */
gtk_tree_sortable_set_sort_column_id (sortable, URI, order);
}
static void
assoc_dialog_update (AssocDialog *assoc_dialog)
{
@ -146,6 +196,10 @@ gnc_assoc_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user
assoc_dialog_update (assoc_dialog);
return;
case -8:
assoc_dialog_sort (assoc_dialog);
return;
case GTK_RESPONSE_CLOSE:
default:
gnc_close_gui_component_by_data (DIALOG_ASSOC_CM_CLASS, assoc_dialog);

View File

@ -36,6 +36,20 @@
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="sort">
<property name="label" translatable="yes">_Sort Association</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Check">
<property name="label" translatable="yes">_Locate Association</property>
@ -47,7 +61,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -63,7 +77,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@ -178,6 +192,7 @@
</object>
</child>
<action-widgets>
<action-widget response="-8">sort</action-widget>
<action-widget response="-10">Check</action-widget>
<action-widget response="-6">close_button</action-widget>
</action-widgets>