From af64219849753ca3c18ce46eab0a9d5ce8dc2254 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 31 Jan 1998 19:04:44 +0000 Subject: [PATCH] assorted changes for commiting edits to transaction list git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@472 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/Ledger.c | 98 ++++++++++++++++++++++++++-------------- src/RegWindow.c | 22 +++++---- src/Transaction.c | 17 ++++++- src/register/pricecell.c | 2 +- src/register/register.c | 7 ++- src/register/register.h | 2 +- 6 files changed, 96 insertions(+), 52 deletions(-) diff --git a/src/Ledger.c b/src/Ledger.c index 19ae1bac4a..eb02a1808e 100644 --- a/src/Ledger.c +++ b/src/Ledger.c @@ -14,22 +14,76 @@ /* ======================================================== */ -void -xaccCommitEdits (BasicRegister *reg) +Split * xaccGetCurrentSplit (BasicRegister *reg) { CellBlock *cursor; Split *split; + + /* get the handle to the current split and transaction */ + cursor = reg->table->cursor; + split = (Split *) cursor->user_data; + + return split; +} + +/* ======================================================== */ + +void +xaccSaveRegEntry (BasicRegister *reg) +{ + Split *split; Transaction *trans; - cursor = reg->table->cursor; - - split = (Split *) cursor->user_data; + /* get the handle to the current split and transaction */ + split = xaccGetCurrentSplit (reg); if (!split) return; - trans = (Transaction *) (split->parent); - if (trans->num) free (trans->num); - trans->num = strdup (reg->numCell->value); + /* copy the contents from the cursor to the split */ + xaccTransSetDate (trans, reg->dateCell->date.tm_mday, + reg->dateCell->date.tm_mon+1, + reg->dateCell->date.tm_year+1900); + + xaccTransSetNum (trans, reg->numCell->value); + xaccTransSetDescription (trans, reg->descCell->cell.value); + xaccSplitSetMemo (split, reg->memoCell->value); + xaccSplitSetAction (split, reg->actionCell->cell.value); + xaccSplitSetReconcile (split, reg->recnCell->value[0]); +} + +/* ======================================================== */ + +void +xaccLoadRegEntry (BasicRegister *reg, Split *split) +{ + Transaction *trans; + char buff[2]; + + if (!split) return; + trans = (Transaction *) (split->parent); + + xaccSetDateCellValue (reg->dateCell, trans->date.day, + trans->date.month, + trans->date.year); + + xaccSetBasicCellValue (reg->numCell, trans->num); + xaccSetBasicCellValue (&(reg->actionCell->cell), split->action); + xaccSetQuickFillCellValue (reg->descCell, trans->description); + xaccSetBasicCellValue (reg->memoCell, split->memo); + + buff[0] = split->reconciled; + buff[1] = 0x0; + xaccSetBasicCellValue (reg->recnCell, buff); + + xaccSetDebCredCellValue (reg->debitCell, + reg->creditCell, split->damount); + + xaccSetAmountCellValue (reg->balanceCell, split->balance); + + reg->table->cursor->user_data = (void *) split; + + /* copy cursor contents into the table */ + xaccCommitCursor (reg->table); } /* ======================================================== */ @@ -55,34 +109,8 @@ xaccLoadRegister (BasicRegister *reg, Split **slist) split = slist[0]; while (split) { - trans = (Transaction *) (split->parent); - xaccMoveCursor (table, i, 0); - - sprintf (buff, "%2d/%2d/%4d", trans->date.day, - trans->date.month, - trans->date.year); - - xaccSetBasicCellValue (reg->dateCell, buff); - - xaccSetBasicCellValue (reg->numCell, trans->num); - xaccSetBasicCellValue (&(reg->actionCell->cell), split->action); - xaccSetQuickFillCellValue (reg->descCell, trans->description); - xaccSetBasicCellValue (reg->memoCell, split->memo); - - buff[0] = split->reconciled; - buff[1] = 0x0; - xaccSetBasicCellValue (reg->recnCell, buff); - - xaccSetDebCredCellValue (reg->debitCell, - reg->creditCell, split->damount); - - xaccSetAmountCellValue (reg->balanceCell, split->balance); - - table->cursor->user_data = (void *) split; - - /* copy cursor contents into the table */ - xaccCommitCursor (table); + xaccLoadRegEntry (reg, split); i++; split = slist[i]; diff --git a/src/RegWindow.c b/src/RegWindow.c index 0281216559..727ca10877 100644 --- a/src/RegWindow.c +++ b/src/RegWindow.c @@ -595,8 +595,7 @@ closeRegWindow( Widget mw, XtPointer cd, XtPointer cb ) RegWindow *regData = (RegWindow *)cd; /* Save any unsaved changes */ - /* hack alert */ - /* regSaveTransaction( regData, regData->currEntry ); */ + xaccSaveRegEntry (regData->ledger); regData->blackacc[0]->regData = NULL; regData->blackacc[0]->regLedger = NULL; @@ -669,13 +668,11 @@ startRecnCB( Widget mw, XtPointer cd, XtPointer cb ) \********************************************************************/ static void recordCB( Widget mw, XtPointer cd, XtPointer cb ) - { +{ RegWindow *regData = (RegWindow *)cd; - /* hack alert */ - /* regSaveTransaction( regData, regData->currEntry ); */ - regData->changed = MOD_NONE; - } + xaccSaveRegEntry (regData->ledger); +} /********************************************************************\ * deleteCB * @@ -731,8 +728,13 @@ deleteCB( Widget mw, XtPointer cd, XtPointer cb ) \********************************************************************/ static void cancelCB( Widget mw, XtPointer cd, XtPointer cb ) - { - RegWindow *regData = (RegWindow *)cd; - } +{ + RegWindow *regData = (RegWindow *)cd; + Split * split; + + /* when cancelling edits, reload the cursor from the transaction */ + split = xaccGetCurrentSplit (regData->ledger); + xaccLoadRegEntry (regData->ledger, split); +} /************************** END OF FILE *************************/ diff --git a/src/Transaction.c b/src/Transaction.c index a13c9c0f95..68ff85aecb 100644 --- a/src/Transaction.c +++ b/src/Transaction.c @@ -461,7 +461,22 @@ xaccCountTransactions (Transaction **tarray) \********************************************************************/ void -xaccTransSetDescription (Transaction *trans, char *desc) +xaccTransSetDate (Transaction *trans, int day, int mon, int year) +{ + trans->date.year = year; + trans->date.month = mon; + trans->date.day = day; +} + +void +xaccTransSetNum (Transaction *trans, char *xnum) +{ + if (trans->num) free (trans->num); + trans->num = strdup (xnum); +} + +void +xaccTransSetDescription (Transaction *trans, char *desc) { if (trans->description) free (trans->description); trans->description = strdup (desc); diff --git a/src/register/pricecell.c b/src/register/pricecell.c index d53bf2b1e8..e7582bd202 100644 --- a/src/register/pricecell.c +++ b/src/register/pricecell.c @@ -34,7 +34,7 @@ PriceMV (struct _BasicCell *_cell, } /* hack alert - should parse the float pt value */ - xaccSetBaicCellValue (cell, newval); + xaccSetBasicCellValue (cell, newval); return newval; } diff --git a/src/register/register.c b/src/register/register.c index cf0ef5c366..cfab96ee83 100644 --- a/src/register/register.c +++ b/src/register/register.c @@ -109,10 +109,9 @@ void xaccInitBasicRegister (BasicRegister *reg) curs = xaccMallocCellBlock (2, MAX_COLS); reg->cursor = curs; - cell = (BasicCell *) xaccMallocDateCell(); - cell->width = 9; - xaccAddCell (curs, cell, DATE_CELL_R, DATE_CELL_C); - reg->dateCell = cell; + reg->dateCell = xaccMallocDateCell(); + reg->dateCell->cell.width = 9; + xaccAddCell (curs, &(reg->dateCell->cell), DATE_CELL_R, DATE_CELL_C); cell = xaccMallocTextCell(); cell->width = 7; diff --git a/src/register/register.h b/src/register/register.h index 7d33ee78e8..59fa2146f3 100644 --- a/src/register/register.h +++ b/src/register/register.h @@ -19,7 +19,7 @@ typedef struct _BasicRegister { Table * table; CellBlock * cursor; CellBlock * header; - BasicCell * dateCell; + DateCell * dateCell; BasicCell * numCell; ComboCell * actionCell; ComboCell * xfrmCell;