From ddb9495572ee2617b0ae515018406e38069136f6 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Thu, 26 Mar 1998 01:21:18 +0000 Subject: [PATCH] fix blan-split handling git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@734 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/Ledger.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Ledger.c b/src/Ledger.c index cadd2d0c2d..ec8d86706a 100644 --- a/src/Ledger.c +++ b/src/Ledger.c @@ -36,6 +36,10 @@ #define BUFSIZE 1024 /* ======================================================== */ +/* this callback gets called when the user clicks on the gui + * in such a way as to leave the current transaction, and to + * go to a new one. So, sve the current transaction. + */ static void LedgerMoveCursor (Table *table, void * client_data) @@ -252,6 +256,7 @@ xaccLoadRegister (BasicRegister *reg, Split **slist, int num_phys_cols; int num_virt_rows; int phys_row; + int vrow; table = reg->table; @@ -292,41 +297,50 @@ xaccLoadRegister (BasicRegister *reg, Split **slist, printf ("load reg of %d entries --------------------------- \n",i); /* populate the table */ i=0; + vrow = 0; split = slist[0]; while (split) { - phys_row = reg->header->numRows; - phys_row += i * (reg->cursor->numRows); - /* i+1 because header is virt row zero */ - xaccSetCursor (table, reg->cursor, phys_row, 0, i+1, 0); - xaccMoveCursor (table, phys_row, 0); - xaccLoadRegEntry (reg, split); + /* don't load the "blank split" inline; instead, we put + * it at the end. */ + if (split != ((Split *) (reg->user_hook))) { + phys_row = reg->header->numRows; + phys_row += vrow * (reg->cursor->numRows); + + /* vrow+1 because header is virt row zero */ + vrow ++; + xaccSetCursor (table, reg->cursor, phys_row, 0, vrow, 0); + xaccMoveCursor (table, phys_row, 0); + xaccLoadRegEntry (reg, split); + } - i++; + i++; split = slist[i]; } /* add the "blank split" at the end */ - if (!(reg->user_hook)) { + if (reg->user_hook) { + split = (Split *) reg->user_hook; + } else { trans = xaccMallocTransaction (); xaccTransSetDateToday (trans); split = xaccTransGetSourceSplit (trans); xaccAccountInsertSplit (default_source_acc, split); reg->user_hook = (void *) split; reg->destroy = LedgerDestroy; - - phys_row = reg->header->numRows; - phys_row += i * (reg->cursor->numRows); - xaccSetCursor (table, reg->cursor, phys_row, 0, i+1, 0); - xaccMoveCursor (table, phys_row, 0); - - xaccLoadRegEntry (reg, split); - i++; } + + phys_row = reg->header->numRows; + phys_row += vrow * (reg->cursor->numRows); + vrow ++; + xaccSetCursor (table, reg->cursor, phys_row, 0, vrow, 0); + xaccMoveCursor (table, phys_row, 0); + + xaccLoadRegEntry (reg, split); /* restore the cursor to its original location */ phys_row = reg->header->numRows; - phys_row += i * (reg->cursor->numRows); + phys_row += vrow * (reg->cursor->numRows); if (phys_row <= save_cursor_phys_row) { save_cursor_phys_row = phys_row - reg->cursor->numRows;