From de0c1edcb593ad50e3c6abb14edadb2c31fcaa57 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Mon, 8 May 2006 04:47:04 +0000 Subject: [PATCH] Add a flag, 'infant', to QofInstance to note that the instance has been committed at least once in its lifecycle. Then, we can mark the collection dirty whenever an object is committed, except for the special case of an QofInstance that has never been committed before and is now being deleted. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13957 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/qofinstance-p.h | 3 +++ lib/libqof/qof/qofinstance.c | 2 ++ lib/libqof/qof/qofutil.c | 11 +++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/libqof/qof/qofinstance-p.h b/lib/libqof/qof/qofinstance-p.h index b83f917d8d..338caf3400 100644 --- a/lib/libqof/qof/qofinstance-p.h +++ b/lib/libqof/qof/qofinstance-p.h @@ -69,6 +69,9 @@ struct QofInstance_s * but has not yet been written out to storage (file/database) */ gboolean dirty; + + /* True iff this instance has never been committed. */ + gboolean infant; }; /* reset the dirty flag */ diff --git a/lib/libqof/qof/qofinstance.c b/lib/libqof/qof/qofinstance.c index 1314a0540e..5a245c1805 100644 --- a/lib/libqof/qof/qofinstance.c +++ b/lib/libqof/qof/qofinstance.c @@ -61,6 +61,7 @@ qof_instance_init (QofInstance *inst, QofIdType type, QofBook *book) inst->editlevel = 0; inst->do_free = FALSE; inst->dirty = FALSE; + inst->infant = TRUE; col = qof_book_get_collection (book, type); qof_entity_init (&inst->entity, type, col); @@ -70,6 +71,7 @@ void qof_instance_release (QofInstance *inst) { kvp_frame_delete (inst->kvp_data); + inst->kvp_data = NULL; inst->editlevel = 0; inst->do_free = FALSE; inst->dirty = FALSE; diff --git a/lib/libqof/qof/qofutil.c b/lib/libqof/qof/qofutil.c index 96dc1f35a1..9cb320669f 100644 --- a/lib/libqof/qof/qofutil.c +++ b/lib/libqof/qof/qofutil.c @@ -303,16 +303,19 @@ qof_commit_edit_part2(QofInstance *inst, /* XXX the backend commit code should clear dirty!! */ inst->dirty = FALSE; } + if (dirty && qof_get_alt_dirty_mode() && + !(inst->infant && inst->do_free)) { + qof_collection_mark_dirty(inst->entity.collection); + qof_book_mark_dirty(inst->book); + } + inst->infant = FALSE; + if (inst->do_free) { if (on_free) on_free(inst); return TRUE; } - if (dirty && qof_get_alt_dirty_mode()) { - qof_collection_mark_dirty(inst->entity.collection); - qof_book_mark_dirty(inst->book); - } if (on_done) on_done(inst); return TRUE;