From 1353eea3d11b577c79507e32399f44f5edaf027f Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Sat, 17 Jul 2021 10:15:06 +0200 Subject: [PATCH] trigger event after all modifications, not just after the first one. --- lib/src/kdbx_object.dart | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/src/kdbx_object.dart b/lib/src/kdbx_object.dart index 1a7f115..d6989f0 100644 --- a/lib/src/kdbx_object.dart +++ b/lib/src/kdbx_object.dart @@ -54,9 +54,18 @@ mixin Changeable { @mustCallSuper void onAfterModify() {} + /// Called after the all modifications + @protected + @mustCallSuper + void onAfterAnyModify() {} + RET modify(RET Function() modify) { if (_isDirty || _isInModify) { - return modify(); + try { + return modify(); + } finally { + onAfterAnyModify(); + } } _isInModify = true; onBeforeModify(); @@ -66,6 +75,7 @@ mixin Changeable { _isDirty = true; _isInModify = false; onAfterModify(); + onAfterAnyModify(); _controller.add(ChangeEvent(object: this as T, isDirty: _isDirty)); } } @@ -194,9 +204,17 @@ abstract class KdbxObject extends KdbxNode { } } + // @override + // void onAfterModify() { + // super.onAfterModify(); + // times.modifiedNow(); + // // during initial `create` the file will be null. + // file?.dirtyObject(this); + // } + @override - void onAfterModify() { - super.onAfterModify(); + void onAfterAnyModify() { + super.onAfterAnyModify(); times.modifiedNow(); // during initial `create` the file will be null. file?.dirtyObject(this);