From 0de4ce1106e2247e4f6d221833a7c2b8459f2533 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 17 Jun 2024 13:36:54 +0100 Subject: [PATCH] Bug 799047 - AutoComplete Only Considers Visible Transactions In the past, all transactions were used on the first load of the register and this is when the autocomplete would be populated, on subsequent loads it would be a filtered list. With the change to delay loading, the first load is empty and the autocomplete is now being populated by the filtered list. To fix this, make a copy of the original query and compare this query to the query used for refresh. When different, pass a second list of splits to the register to populate the autocomplete lists. --- gnucash/gnome/dialog-sx-editor.c | 2 +- .../register/ledger-core/gnc-ledger-display.c | 14 +++++- .../ledger-core/split-register-load.c | 46 ++++++++++++++++--- gnucash/register/ledger-core/split-register.h | 4 +- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/gnucash/gnome/dialog-sx-editor.c b/gnucash/gnome/dialog-sx-editor.c index 4c1a54ee91..f8144effed 100644 --- a/gnucash/gnome/dialog-sx-editor.c +++ b/gnucash/gnome/dialog-sx-editor.c @@ -1509,7 +1509,7 @@ schedXact_editor_populate (GncSxEditorDialog *sxed) if (splitList) { splitReg = gnc_ledger_display_get_split_register (sxed->ledger); - gnc_split_register_load (splitReg, splitList, NULL); + gnc_split_register_load (splitReg, splitList, NULL, NULL); } /* otherwise, use the existing stuff. */ g_list_free (splitList); } diff --git a/gnucash/register/ledger-core/gnc-ledger-display.c b/gnucash/register/ledger-core/gnc-ledger-display.c index bf0f48a183..2c0dbf6de2 100644 --- a/gnucash/register/ledger-core/gnc-ledger-display.c +++ b/gnucash/register/ledger-core/gnc-ledger-display.c @@ -59,6 +59,7 @@ struct gnc_ledger_display GncGUID leader; Query* query; + Query* pre_filter_query; GNCLedgerDisplayType ld_type; @@ -655,6 +656,9 @@ close_handler (gpointer user_data) qof_query_destroy (ld->query); ld->query = NULL; + qof_query_destroy (ld->pre_filter_query); + ld->pre_filter_query = NULL; + g_free (ld); } @@ -834,6 +838,8 @@ gnc_ledger_display_internal (Account* lead_account, Query* q, else gnc_ledger_display_make_query (ld, limit, reg_type); + ld->pre_filter_query = qof_query_copy (ld->query); + ld->component_id = gnc_register_gui_component (klass, refresh_handler, close_handler, ld); @@ -854,7 +860,7 @@ gnc_ledger_display_internal (Account* lead_account, Query* q, * the query when we're not in focus yet. */ ld->loading = TRUE; - gnc_split_register_load (ld->reg, NULL, gnc_ledger_display_leader (ld)); + gnc_split_register_load (ld->reg, NULL, NULL, gnc_ledger_display_leader (ld)); ld->loading = FALSE; return ld; } @@ -888,6 +894,7 @@ static void gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld) { GList* splits; + GList* pre_filter_splits = NULL; if (ld->loading) return; @@ -899,6 +906,9 @@ gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld) */ splits = qof_query_run (ld->query); + if (!qof_query_equal (ld->query, ld->pre_filter_query)) + pre_filter_splits = qof_query_run (ld->pre_filter_query); + gnc_ledger_display_set_watches (ld, splits); if (!gnc_split_register_full_refresh_ok (ld->reg)) @@ -906,7 +916,7 @@ gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld) ld->loading = TRUE; - gnc_split_register_load (ld->reg, splits, + gnc_split_register_load (ld->reg, splits, pre_filter_splits, gnc_ledger_display_leader (ld)); ld->needs_refresh = FALSE; diff --git a/gnucash/register/ledger-core/split-register-load.c b/gnucash/register/ledger-core/split-register-load.c index 1f756e07b0..d6963ed316 100644 --- a/gnucash/register/ledger-core/split-register-load.c +++ b/gnucash/register/ledger-core/split-register-load.c @@ -256,8 +256,9 @@ _find_split_with_parent_txn (gconstpointer a, gconstpointer b) return xaccSplitGetParent (split) == txn ? 0 : 1; } -static void add_quickfill_completions (TableLayout* layout, Transaction* trans, - Split* split, gboolean has_last_num) +static void +add_quickfill_completions (TableLayout* layout, Transaction* trans, + Split* split, gboolean has_last_num) { gnc_quickfill_cell_add_completion ( (QuickFillCell*) gnc_table_layout_get_cell (layout, NOTES_CELL), @@ -365,9 +366,30 @@ update_info (SRInfo* info, SplitRegister* reg) info->reg_loaded = TRUE; } +static void +add_completions_from_pre_filter_slist (TableLayout* layout, GList *pre_filter_slist, + gboolean first_pass, gboolean quickfill_setup, + gboolean has_last_num) +{ + GList *node; + + for (node = pre_filter_slist; node; node = node->next) + { + Split *split = node->data; + Transaction *trans = xaccSplitGetParent (split); + + gnc_completion_cell_add_menu_item ( + (CompletionCell*) gnc_table_layout_get_cell (layout, DESC_CELL), + xaccTransGetDescription (trans)); + + if (!first_pass && !quickfill_setup) + add_quickfill_completions (layout, trans, split, has_last_num); + } +} + void gnc_split_register_load (SplitRegister* reg, GList* slist, - Account* default_account) + GList* pre_filter_slist, Account* default_account) { SRInfo* info; Transaction* pending_trans; @@ -635,6 +657,13 @@ gnc_split_register_load (SplitRegister* reg, GList* slist, (CompletionCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL), table->model->reverse_sort); + if (!info->first_pass && pre_filter_slist) + { + add_completions_from_pre_filter_slist (reg->table->layout, pre_filter_slist, + info->first_pass, info->quickfill_setup, + has_last_num); + } + /* populate the table */ for (node = slist; node; node = node->next) { @@ -752,12 +781,15 @@ gnc_split_register_load (SplitRegister* reg, GList* slist, /* On first load the split list is empty so fill up the quickfill cells * only on the next load. */ - if (!info->first_pass && !info->quickfill_setup) + if (!info->first_pass && !pre_filter_slist && !info->quickfill_setup) add_quickfill_completions (reg->table->layout, trans, split, has_last_num); - gnc_completion_cell_add_menu_item ( - (CompletionCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL), - xaccTransGetDescription (trans)); + if (!info->first_pass && !pre_filter_slist) + { + gnc_completion_cell_add_menu_item ( + (CompletionCell*) gnc_table_layout_get_cell (reg->table->layout, DESC_CELL), + xaccTransGetDescription (trans)); + } if (trans == find_trans) new_trans_row = vcell_loc.virt_row; diff --git a/gnucash/register/ledger-core/split-register.h b/gnucash/register/ledger-core/split-register.h index 5274c6aaec..99b2a79cd8 100644 --- a/gnucash/register/ledger-core/split-register.h +++ b/gnucash/register/ledger-core/split-register.h @@ -530,10 +530,12 @@ void gnc_split_register_cancel_cursor_trans_changes (SplitRegister* reg); * * @param slist a list of splits * + * @param pre_filter_slist the list of splits before applying filter + * * @param default_account an account to provide defaults for the blank split */ void gnc_split_register_load (SplitRegister* reg, GList* slist, - Account* default_account); + GList* pre_filter_slist, Account* default_account); /** Copy the contents of the current cursor to a split. The split and * transaction that are updated are the ones associated with the