From d1ff3b469e3130b6d14bcb91f96273282b00dd7c Mon Sep 17 00:00:00 2001 From: David Hampton Date: Wed, 13 Nov 2002 01:44:19 +0000 Subject: [PATCH] Sort the splits in a transaction when the transaction is committed, not each time the view of the transaction is refreshed in the register. #92156 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7476 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 10 +++++ src/engine/Transaction.c | 28 +++++++++++++ .../ledger-core/split-register-load.c | 42 +------------------ 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93a667d3fa..66e06a3f91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,16 @@ 2002-11-12 David Hampton + * src/register/ledger-core/split-register-load.c + (gnc_split_register_add_transaction): Don't sort transaction + splits here. This function gets called every time you switch + splits, and so can reorder them just when you least expect + it. #92156 + + * src/engine/Transaction.c (xaccTransCommitEdit): Sort transaction + splits when the user has finished making changes to the + transaction. #92156 + * src/register/ledger-core/split-register-control.c (gnc_split_register_traverse): Move the checking for non-existent and placeholder accounts to a separate function, and call that new diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 007e4f7e35..6d4bcca959 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -1637,6 +1637,34 @@ xaccTransCommitEdit (Transaction *trans) /* ------------------------------------------------- */ /* OK, at this point, we are done making sure that * we've got a validly constructed transaction. + * + * Next, sort the splits + */ + { + GList *node, *new_list = NULL; + + /* first debits */ + for (node = trans->splits; node; node = node->next) { + split = node->data; + if (gnc_numeric_negative_p (xaccSplitGetValue (split))) + continue; + new_list = g_list_append(new_list, split); + } + + /* then credits */ + for (node = trans->splits; node; node = node->next) { + split = node->data; + if (!gnc_numeric_negative_p (xaccSplitGetValue (split))) + continue; + new_list = g_list_append(new_list, split); + } + + /* install newly sorted list */ + g_list_free(trans->splits); + trans->splits = new_list; + } + + /* * Next, we send it off to the back-end, to see if the * back-end will accept it. */ diff --git a/src/register/ledger-core/split-register-load.c b/src/register/ledger-core/split-register-load.c index 5f7cd57952..79ccf249c9 100644 --- a/src/register/ledger-core/split-register-load.c +++ b/src/register/ledger-core/split-register-load.c @@ -83,7 +83,6 @@ gnc_split_register_add_transaction (SplitRegister *reg, CellBlock *split_cursor, gboolean visible_splits, gboolean start_primary_color, - gboolean sort_splits, gboolean add_blank, Transaction *find_trans, Split *find_split, @@ -100,43 +99,6 @@ gnc_split_register_add_transaction (SplitRegister *reg, TRUE, start_primary_color, *vcell_loc); vcell_loc->virt_row++; - if (sort_splits) - { - /* first debits */ - for (node = xaccTransGetSplitList (trans); node; node = node->next) - { - Split *secondary = node->data; - - if (gnc_numeric_negative_p (xaccSplitGetValue (secondary))) - continue; - - if (secondary == find_split && find_class == CURSOR_CLASS_SPLIT) - *new_split_row = vcell_loc->virt_row; - - gnc_table_set_vcell (reg->table, split_cursor, - xaccSplitGetGUID (secondary), - visible_splits, TRUE, *vcell_loc); - vcell_loc->virt_row++; - } - - /* then credits */ - for (node = xaccTransGetSplitList (trans); node; node = node->next) - { - Split *secondary = node->data; - - if (!gnc_numeric_negative_p (xaccSplitGetValue (secondary))) - continue; - - if (secondary == find_split && find_class == CURSOR_CLASS_SPLIT) - *new_split_row = vcell_loc->virt_row; - - gnc_table_set_vcell (reg->table, split_cursor, - xaccSplitGetGUID (secondary), - visible_splits, TRUE, *vcell_loc); - vcell_loc->virt_row++; - } - } - else { for (node = xaccTransGetSplitList (trans); node; node = node->next) { @@ -409,7 +371,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist, gnc_split_register_add_transaction (reg, trans, split, lead_cursor, split_cursor, multi_line, start_primary_color, - TRUE, TRUE, + TRUE, find_trans, find_split, find_class, &new_split_row, &vcell_loc); @@ -446,7 +408,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist, gnc_split_register_add_transaction (reg, trans, split, lead_cursor, split_cursor, - multi_line, start_primary_color, FALSE, + multi_line, start_primary_color, info->blank_split_edited, find_trans, find_split, find_class, &new_split_row, &vcell_loc);