From 6d8b93ce84411075541ec9b21f07abd424ebd345 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sat, 29 Jul 2023 22:31:03 +0100 Subject: [PATCH] Allow custom undo managers in database plugins Add a _create_undo_manager method in DbGeneric which can be overridden to supply a custom undo manager rather than the default DbGenericUndo. --- gramps/gen/db/generic.py | 10 ++++++++-- gramps/gen/db/undoredo.py | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gramps/gen/db/generic.py b/gramps/gen/db/generic.py index 59410209671..674a9aa9216 100644 --- a/gramps/gen/db/generic.py +++ b/gramps/gen/db/generic.py @@ -626,11 +626,11 @@ def load(self, directory, callback=None, mode=DBMODE_W, self._set_save_path(directory) - if self._directory: + if self._directory and self._directory != ":memory:": self.undolog = os.path.join(self._directory, DBUNDOFN) else: self.undolog = None - self.undodb = DbGenericUndo(self, self.undolog) + self.undodb = self._create_undo_manager() self.undodb.open() # Other items to load @@ -665,6 +665,12 @@ def load(self, directory, callback=None, mode=DBMODE_W, self.close() raise DbUpgradeRequiredError(dbversion, self.VERSION[0]) + def _create_undo_manager(self): + """ + Create the undo manager. + """ + return DbGenericUndo(self, self.undolog) + def _close(self): """ Close database backend. diff --git a/gramps/gen/db/undoredo.py b/gramps/gen/db/undoredo.py index a8bff6784c8..51fa9dc2d38 100644 --- a/gramps/gen/db/undoredo.py +++ b/gramps/gen/db/undoredo.py @@ -125,6 +125,13 @@ def commit(self, txn, msg): txn.set_description(msg) txn.timestamp = time.time() self.undoq.append(txn) + self._after_commit(txn) + + def _after_commit(self, transaction): + """ + Post-transaction commit processing. + """ + pass def undo(self, update_history=True): """