mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add sorted-order accounts
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1319 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
1ed074fddb
commit
cf0fd7af1f
@ -1,7 +1,7 @@
|
|||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* Group.c -- the main data structure of the program *
|
* Group.c -- the main data structure of the program *
|
||||||
* Copyright (C) 1997 Robin D. Clark *
|
* Copyright (C) 1997 Robin D. Clark *
|
||||||
* Copyright (C) 1997 Linas Vepstas *
|
* Copyright (C) 1997, 1998 Linas Vepstas *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or *
|
* This program is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU General Public License as *
|
* modify it under the terms of the GNU General Public License as *
|
||||||
@ -375,38 +375,56 @@ xaccInsertSubAccount( Account *adult, Account *child )
|
|||||||
|
|
||||||
void
|
void
|
||||||
xaccGroupInsertAccount( AccountGroup *grp, Account *acc )
|
xaccGroupInsertAccount( AccountGroup *grp, Account *acc )
|
||||||
{
|
{
|
||||||
int i=-1;
|
int i,j,nacc;
|
||||||
Account **arr;
|
Account **oldarr, **newarr;
|
||||||
|
int ralo = 1;
|
||||||
|
|
||||||
if (NULL == grp) return;
|
if (NULL == grp) return;
|
||||||
if (NULL == acc) return;
|
if (NULL == acc) return;
|
||||||
|
|
||||||
/* If the account is currently in another group, remove it there first.
|
/* If the account is currently in another group, remove it there first.
|
||||||
* Basically, we can't have accounts being in two places at once. */
|
* Basically, we can't have accounts being in two places at once.
|
||||||
|
* If old and new parents are the same, reinsertion causes the sort order
|
||||||
|
* to be checked.
|
||||||
|
*/
|
||||||
if (acc->parent) {
|
if (acc->parent) {
|
||||||
|
if (grp == acc->parent) ralo = 0;
|
||||||
xaccRemoveAccount (acc);
|
xaccRemoveAccount (acc);
|
||||||
}
|
}
|
||||||
|
grp->saved = FALSE;
|
||||||
|
|
||||||
/* set back-pointer to the accounts parent */
|
/* set back-pointer to the accounts parent */
|
||||||
acc->parent = grp;
|
acc->parent = grp;
|
||||||
|
|
||||||
arr = grp->account;
|
nacc = grp->numAcc;
|
||||||
|
oldarr = grp->account;
|
||||||
grp->saved = FALSE;
|
newarr = oldarr;
|
||||||
|
if (ralo) {
|
||||||
grp->account = (Account **)_malloc(((grp->numAcc)+2)*sizeof(Account *));
|
newarr = (Account **) realloc (oldarr, (nacc+2)*sizeof(Account *));
|
||||||
|
if (newarr == oldarr) ralo = 0;
|
||||||
for( i=0; i<(grp->numAcc); i++ ) {
|
|
||||||
grp->account[i] = arr[i];
|
|
||||||
}
|
}
|
||||||
_free(arr);
|
|
||||||
|
|
||||||
grp->account[(grp->numAcc)] = acc;
|
|
||||||
grp->numAcc++;
|
|
||||||
grp->account[(grp->numAcc)] = NULL;
|
|
||||||
|
|
||||||
|
/* insert account in proper sort order */
|
||||||
|
for( i=nacc-1, j=nacc; i>=0; i--, j-- ) {
|
||||||
|
if (i != j) {
|
||||||
|
if (0 < xaccAccountOrder (&(oldarr[i]), &acc)) {
|
||||||
|
newarr[j] = oldarr[i];
|
||||||
|
} else {
|
||||||
|
newarr[j] = acc;
|
||||||
|
j--;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
newarr[j] = oldarr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ralo) free (oldarr);
|
||||||
|
|
||||||
|
nacc++;
|
||||||
|
newarr[nacc] = NULL;
|
||||||
|
grp->account = newarr;
|
||||||
|
grp->numAcc = nacc;
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user