Skip to content

Commit

Permalink
Allow custom undo managers in database plugins
Browse files Browse the repository at this point in the history
Add a _create_undo_manager method in DbGeneric which can be
overridden to supply a custom undo manager rather than the
default DbGenericUndo.
  • Loading branch information
Nick-Hall committed Jul 30, 2023
1 parent 626a965 commit 6d8b93c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gramps/gen/db/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions gramps/gen/db/undoredo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 6d8b93c

Please sign in to comment.