additions to allow gui to rollback the enire transaction,

not just an individual split line.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1249 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-10-01 05:50:45 +00:00
parent 5aff12d808
commit c259ccdfa5
3 changed files with 36 additions and 7 deletions

View File

@ -208,10 +208,11 @@ printf ("leave LedgerTraverse with %d \n", reg->cursor_phys_row);
static void static void
LedgerDestroy (SplitRegister *reg) LedgerDestroy (SplitRegister *reg)
{ {
Transaction *trans;
/* be sure to destroy the "blank split" */ /* be sure to destroy the "blank split" */
if (reg->user_hook) { if (reg->user_hook) {
Split *split; Split *split;
Transaction *trans;
split = (Split *) (reg->user_hook); split = (Split *) (reg->user_hook);
@ -223,6 +224,19 @@ LedgerDestroy (SplitRegister *reg)
xaccTransCommitEdit (trans); xaccTransCommitEdit (trans);
reg->user_hook = NULL; reg->user_hook = NULL;
} }
/* be sure to take care of any open transactions */
if (reg->user_huck) {
trans = (Transaction *) (reg->user_huck);
/* I suppose we could also rollback here ... its not clear what
* the desirable behaviour should be from the user's point of view
* when they close a window with an uncommitted edit in it ...
* Maybe we should prompt them ??
*/
xaccTransCommitEdit (trans);
reg->user_huck = NULL;
}
} }
/* ======================================================== */ /* ======================================================== */
@ -284,7 +298,7 @@ void
xaccSRSaveRegEntry (SplitRegister *reg) xaccSRSaveRegEntry (SplitRegister *reg)
{ {
Split *split; Split *split;
Transaction *trans; Transaction *trans, *oldtrans;
Account * acc; Account * acc;
unsigned int changed; unsigned int changed;
int style; int style;
@ -327,8 +341,15 @@ printf ("save split is %p \n", split);
} }
trans = xaccSplitGetParent (s); trans = xaccSplitGetParent (s);
/* determine whether we should commit the previous edit */
oldtrans = (Transaction *) (reg->user_huck);
if (oldtrans != trans) {
xaccTransCommitEdit (oldtrans);
xaccTransBeginEdit (trans, 0);
reg->user_huck = (void *) trans;
}
split = xaccMallocSplit (); split = xaccMallocSplit ();
xaccTransBeginEdit (trans, 0);
xaccTransAppendSplit (trans, split); xaccTransAppendSplit (trans, split);
if (force_double_entry_awareness) { if (force_double_entry_awareness) {
@ -341,7 +362,14 @@ printf ("save split is %p \n", split);
} else { } else {
trans = xaccSplitGetParent (split); trans = xaccSplitGetParent (split);
xaccTransBeginEdit (trans, 0);
/* determine whether we should commit the previous edit */
oldtrans = (Transaction *) (reg->user_huck);
if (oldtrans != trans) {
xaccTransCommitEdit (oldtrans);
xaccTransBeginEdit (trans, 0);
reg->user_huck = (void *) trans;
}
} }
/* copy the contents from the cursor to the split */ /* copy the contents from the cursor to the split */
@ -459,8 +487,6 @@ printf ("save split is %p \n", split);
xaccSplitSetValue (split, (reg->valueCell->amount)); xaccSplitSetValue (split, (reg->valueCell->amount));
} }
xaccTransCommitEdit (trans);
printf ("finished saving split %s of trans %s \n", printf ("finished saving split %s of trans %s \n",
xaccSplitGetMemo(split), xaccSplitGetMemo(split),
xaccTransGetDescription(trans)); xaccTransGetDescription(trans));

View File

@ -571,6 +571,7 @@ xaccInitSplitRegister (SplitRegister *reg, int type)
reg->user_hook = NULL; reg->user_hook = NULL;
reg->user_hack = NULL; reg->user_hack = NULL;
reg->user_huck = NULL;
reg->destroy = NULL; reg->destroy = NULL;
reg->type = type; reg->type = type;
@ -771,6 +772,7 @@ xaccDestroySplitRegister (SplitRegister *reg)
reg->destroy = NULL; reg->destroy = NULL;
reg->user_hook = NULL; reg->user_hook = NULL;
reg->user_hack = NULL; reg->user_hack = NULL;
reg->user_huck = NULL;
xaccDestroyTable (reg->table); xaccDestroyTable (reg->table);
reg->table = NULL; reg->table = NULL;

View File

@ -158,13 +158,14 @@ struct _SplitRegister {
short num_virt_rows; short num_virt_rows;
short cursor_phys_row; short cursor_phys_row;
short cursor_virt_row; short cursor_virt_row;
void * user_hack;
BasicCell *header_label_cells[NUM_CELLS]; BasicCell *header_label_cells[NUM_CELLS];
/* user_hook allows users of this object to hang /* user_hook allows users of this object to hang
* private data onto it */ * private data onto it */
void *user_hook; void *user_hook;
void *user_hack;
void *user_huck;
/* The destroy callback gives user's a chance /* The destroy callback gives user's a chance
* to free up any associated user_hook data */ * to free up any associated user_hook data */