From 304e4972433aca6a0dd634bdef720b46e18781a1 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 4 Sep 2020 00:29:28 +0800 Subject: [PATCH] Bug 476114 - Goto register by date feature req (bis) Addendum to c14241644 - ensure the splitlist is sorted before finding split. This ensures the correct split is found when the register has a non-default sorting. e.g. sorting by reverse posted-date would find the most recent split; this commit ensures the split nearest the desired date is selected. Also I've confirmed there's no need to clear filter; if the register has filtered splits, the algorithm will find the nearest *visible* split on or after the desired date. --- gnucash/gnome/gnc-plugin-page-register.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c index b75bf72af94..4bb4d44e053 100644 --- a/gnucash/gnome/gnc-plugin-page-register.c +++ b/gnucash/gnome/gnc-plugin-page-register.c @@ -4702,7 +4702,7 @@ gnc_plugin_page_register_cmd_goto_date (GtkAction* action, GNCSplitReg* gsr; Query* query; time64 date = gnc_time (NULL); - Split *split = NULL; + GList *splits; ENTER ("(action %p, plugin_page %p)", action, page); g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (page)); @@ -4716,23 +4716,19 @@ gnc_plugin_page_register_cmd_goto_date (GtkAction* action, gsr = gnc_plugin_page_register_get_gsr (GNC_PLUGIN_PAGE (page)); query = gnc_plugin_page_register_get_query (GNC_PLUGIN_PAGE (page)); + splits = g_list_copy (qof_query_run (query)); + splits = g_list_sort (splits, (GCompareFunc)xaccSplitOrder); - for (GList *lp = qof_query_run (query); lp; lp = lp->next) + for (GList *lp = splits; lp; lp = lp->next) { if (xaccTransGetDate (xaccSplitGetParent (lp->data)) >= date) { - split = lp->data; + gnc_split_reg_jump_to_split (gsr, lp->data); break; } } - /* Test for visibility of split */ - /* if (gnc_split_reg_clear_filter_for_split (gsr, split)) */ - /* gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(page)); */ - - if (split) - gnc_split_reg_jump_to_split (gsr, split); - + g_list_free (splits); LEAVE (" "); }