mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 797185 - Allow sorting on all Transaction Association columns
This commit is contained in:
parent
282e456f52
commit
1884ae2093
@ -46,7 +46,18 @@
|
||||
#define GNC_PREFS_GROUP "dialogs.trans-assoc"
|
||||
|
||||
/** Enumeration for the tree-store */
|
||||
enum GncAssocColumn {DATE_TRANS, DESC_TRANS, URI_U, AVAILABLE, URI_SPLIT, URI, URI_RELATIVE};
|
||||
enum GncAssocColumn
|
||||
{
|
||||
DATE_TRANS,
|
||||
DATE_INT64, // used just for sorting date_trans
|
||||
DESC_TRANS,
|
||||
DISPLAY_URI,
|
||||
AVAILABLE,
|
||||
URI_SPLIT,
|
||||
URI,
|
||||
URI_RELATIVE, // used just for sorting relative_pix
|
||||
URI_RELATIVE_PIX
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -528,56 +539,6 @@ gnc_assoc_dialog_window_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpo
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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_U, &uri1, -1);
|
||||
gtk_tree_model_get (model, b, URI_U, &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)
|
||||
{
|
||||
@ -638,13 +599,6 @@ assoc_dialog_update (AssocDialog *assoc_dialog)
|
||||
g_object_unref (G_OBJECT(model));
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_assoc_dialog_sort_button_cb (GtkWidget * widget, gpointer user_data)
|
||||
{
|
||||
AssocDialog *assoc_dialog = user_data;
|
||||
assoc_dialog_sort (assoc_dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_assoc_dialog_check_button_cb (GtkWidget * widget, gpointer user_data)
|
||||
{
|
||||
@ -673,14 +627,14 @@ row_selected_cb (GtkTreeView *view, GtkTreePath *path,
|
||||
|
||||
gtk_tree_model_get (assoc_dialog->model, &iter, URI, &uri, URI_SPLIT, &split, -1);
|
||||
|
||||
// Open associated link
|
||||
if (gtk_tree_view_get_column (GTK_TREE_VIEW(assoc_dialog->view), URI_U) == col)
|
||||
// Open associated link, subtract 1 to allow for date_int64
|
||||
if (gtk_tree_view_get_column (GTK_TREE_VIEW(assoc_dialog->view), DISPLAY_URI - 1) == col)
|
||||
gnc_assoc_open_uri (GTK_WINDOW(assoc_dialog->window), uri);
|
||||
|
||||
g_free (uri);
|
||||
|
||||
// Open transaction
|
||||
if (gtk_tree_view_get_column (GTK_TREE_VIEW(assoc_dialog->view), DESC_TRANS) == col)
|
||||
// Open transaction, subtract 1 to allow for date_int64
|
||||
if (gtk_tree_view_get_column (GTK_TREE_VIEW(assoc_dialog->view), DESC_TRANS - 1) == col)
|
||||
{
|
||||
GncPluginPage *page;
|
||||
GNCSplitReg *gsr;
|
||||
@ -760,10 +714,12 @@ add_trans_info_to_model (QofInstance* data, gpointer user_data)
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE(assoc_dialog->model), &iter,
|
||||
DATE_TRANS, datebuff,
|
||||
DATE_INT64, t, // used just for sorting date column
|
||||
DESC_TRANS, xaccTransGetDescription (trans),
|
||||
URI_U, display_uri, AVAILABLE, _("Unknown"),
|
||||
DISPLAY_URI, display_uri, AVAILABLE, _("Unknown"),
|
||||
URI_SPLIT, split, URI, uri,
|
||||
URI_RELATIVE, (rel == TRUE ? "emblem-default" : NULL), -1);
|
||||
URI_RELATIVE, rel, // used just for sorting relative column
|
||||
URI_RELATIVE_PIX, (rel == TRUE ? "emblem-default" : NULL), -1);
|
||||
g_free (display_uri);
|
||||
g_free (scheme);
|
||||
g_free (uri);
|
||||
@ -801,7 +757,6 @@ gnc_assoc_dialog_create (GtkWindow *parent, AssocDialog *assoc_dialog)
|
||||
GtkBuilder *builder;
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeViewColumn *tree_column;
|
||||
GtkCellRenderer *cr;
|
||||
GtkWidget *button;
|
||||
|
||||
ENTER(" ");
|
||||
@ -813,8 +768,6 @@ gnc_assoc_dialog_create (GtkWindow *parent, AssocDialog *assoc_dialog)
|
||||
assoc_dialog->window = window;
|
||||
assoc_dialog->session = gnc_get_current_session();
|
||||
|
||||
button = GTK_WIDGET(gtk_builder_get_object (builder, "sort_button"));
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(gnc_assoc_dialog_sort_button_cb), assoc_dialog);
|
||||
button = GTK_WIDGET(gtk_builder_get_object (builder, "check_button"));
|
||||
g_signal_connect(button, "clicked", G_CALLBACK(gnc_assoc_dialog_check_button_cb), assoc_dialog);
|
||||
button = GTK_WIDGET(gtk_builder_get_object (builder, "close_button"));
|
||||
@ -835,26 +788,16 @@ gnc_assoc_dialog_create (GtkWindow *parent, AssocDialog *assoc_dialog)
|
||||
assoc_set_path_head_label (assoc_dialog->path_head_label);
|
||||
|
||||
// set the Associate column to be the one that expands
|
||||
tree_column = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object (builder, "uri-entry"));
|
||||
tree_column = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object (builder, "assoc"));
|
||||
gtk_tree_view_column_set_expand (tree_column, TRUE);
|
||||
|
||||
/* Need to add toggle renderers here to get the xalign to work. */
|
||||
tree_column = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_set_title (tree_column, _("Relative"));
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW(assoc_dialog->view), tree_column);
|
||||
gtk_tree_view_column_set_alignment (tree_column, 0.5);
|
||||
cr = gtk_cell_renderer_pixbuf_new();
|
||||
gtk_tree_view_column_pack_start (tree_column, cr, TRUE);
|
||||
// connect 'active' and set 'xalign' property of the cell renderer
|
||||
gtk_tree_view_column_set_attributes (tree_column, cr, "icon-name", URI_RELATIVE, NULL);
|
||||
gtk_cell_renderer_set_alignment (cr, 0.5, 0.5);
|
||||
|
||||
g_signal_connect (assoc_dialog->view, "row-activated",
|
||||
G_CALLBACK(row_selected_cb), (gpointer)assoc_dialog);
|
||||
|
||||
// set the Associate column to be the one that expands
|
||||
tree_column = GTK_TREE_VIEW_COLUMN(gtk_builder_get_object (builder, "uri-entry"));
|
||||
gtk_tree_view_column_set_expand (tree_column, TRUE);
|
||||
/* default sort order */
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(gtk_tree_view_get_model(
|
||||
GTK_TREE_VIEW(assoc_dialog->view))),
|
||||
DATE_INT64, GTK_SORT_ASCENDING);
|
||||
|
||||
// Set grid lines option to preference
|
||||
gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(assoc_dialog->view), gnc_tree_view_get_grid_lines_pref ());
|
||||
@ -876,6 +819,7 @@ gnc_assoc_dialog_create (GtkWindow *parent, AssocDialog *assoc_dialog)
|
||||
get_trans_info (assoc_dialog);
|
||||
gtk_widget_show_all (GTK_WIDGET(window));
|
||||
|
||||
gtk_tree_view_columns_autosize (GTK_TREE_VIEW(assoc_dialog->view));
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
|
@ -269,9 +269,11 @@
|
||||
<columns>
|
||||
<!-- column-name date -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name date_int64 -->
|
||||
<column type="gint64"/>
|
||||
<!-- column-name desc -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name uri_u -->
|
||||
<!-- column-name display_uri -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name available -->
|
||||
<column type="gchararray"/>
|
||||
@ -280,6 +282,8 @@
|
||||
<!-- column-name uri -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name uri_relative -->
|
||||
<column type="gboolean"/>
|
||||
<!-- column-name uri_relative_pix -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
@ -312,20 +316,6 @@
|
||||
<object class="GtkButtonBox" id="buttonbox">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="sort_button">
|
||||
<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_button">
|
||||
<property name="label" translatable="yes">_Locate Association</property>
|
||||
@ -394,6 +384,8 @@
|
||||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Date</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<property name="reorderable">True</property>
|
||||
<property name="sort_column_id">1</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext1"/>
|
||||
<attributes>
|
||||
@ -407,25 +399,29 @@
|
||||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Description</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<property name="reorderable">True</property>
|
||||
<property name="sort_column_id">2</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext2"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="uri-entry">
|
||||
<object class="GtkTreeViewColumn" id="assoc">
|
||||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Association</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<property name="reorderable">True</property>
|
||||
<property name="sort_column_id">3</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext3">
|
||||
<property name="ellipsize">start</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
@ -435,12 +431,25 @@
|
||||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Available ?</property>
|
||||
<property name="alignment">0.5</property>
|
||||
<property name="sort_column_id">4</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext4">
|
||||
<property name="xpad">10</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">3</attribute>
|
||||
<attribute name="text">4</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="relative">
|
||||
<property name="title" translatable="yes">Relative</property>
|
||||
<property name="sort_column_id">7</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf" id="cellrendererpix1"/>
|
||||
<attributes>
|
||||
<attribute name="icon-name">8</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
|
Loading…
Reference in New Issue
Block a user