From c1aeb6b203d2e3c6b9ef2a5f23ab5a59af34add6 Mon Sep 17 00:00:00 2001 From: prculley Date: Sun, 28 May 2017 13:44:01 -0500 Subject: [PATCH] Undo of delete doesn't update views Fixes #10056. --- gramps/gen/db/generic.py | 33 ++++++++++++++-------------- gramps/plugins/db/bsddb/undoredo.py | 34 +++++++++++++---------------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/gramps/gen/db/generic.py b/gramps/gen/db/generic.py index 1d5332d28..9f958a0c9 100644 --- a/gramps/gen/db/generic.py +++ b/gramps/gen/db/generic.py @@ -44,7 +44,7 @@ import glob from . import (DbReadBase, DbWriteBase, DbUndo, DBLOGNAME, DBUNDOFN, KEY_TO_CLASS_MAP, REFERENCE_KEY, PERSON_KEY, FAMILY_KEY, CITATION_KEY, SOURCE_KEY, EVENT_KEY, MEDIA_KEY, PLACE_KEY, - REPOSITORY_KEY, NOTE_KEY, TAG_KEY) + REPOSITORY_KEY, NOTE_KEY, TAG_KEY, TXNADD, TXNDEL) from ..errors import HandleError from ..utils.callback import Callback from ..updatecallback import UpdateCallback @@ -147,11 +147,11 @@ class DbGenericUndo(DbUndo): # now emit the signals for record_id in subitems: (key, trans_type, handle, old_data, new_data) = \ - pickle.loads(self.undodb[record_id]) + pickle.loads(self.undodb[record_id]) if key != REFERENCE_KEY: - self.undo_signals(new_data, handle, key, - db.emit, SIGBASE[key]) + self.undo_signals(trans_type, handle, + db.emit, SIGBASE[key], False) self.db._txn_commit() except: self.db._txn_abort() @@ -201,8 +201,8 @@ class DbGenericUndo(DbUndo): pickle.loads(self.undodb[record_id]) if key != REFERENCE_KEY: - self.undo_signals(old_data, handle, key, - db.emit, SIGBASE[key]) + self.undo_signals(trans_type, handle, + db.emit, SIGBASE[key], True) self.db._txn_commit() except: self.db._txn_abort() @@ -257,20 +257,19 @@ class DbGenericUndo(DbUndo): obj = self.db._get_table_func(cls)["class_func"].create(data) self.db._update_secondary_values(obj) - def undo_signals(self, data, handle, obj_key, emit, signal_root): + def undo_signals(self, trans_type, handle, emit, signal_root, reverse): """ Helper method to undo/redo the changes made """ - cls = KEY_TO_CLASS_MAP[obj_key] - table = cls.lower() - if data is None: - emit(signal_root + '-delete', ([handle],)) - else: - if self.db.has_handle(obj_key, handle): - signal = signal_root + '-update' - else: - signal = signal_root + '-add' - emit(signal, ([handle],)) + if ((not reverse) and trans_type == TXNADD) \ + or (reverse and trans_type == TXNDEL): + typ = '-add' + elif not reverse and trans_type == TXNDEL \ + or reverse and trans_type == TXNADD: + typ = '-delete' + else: # TXNUPD + typ = '-update' + emit(signal_root + typ, ([handle],)) class Cursor: def __init__(self, iterator): diff --git a/gramps/plugins/db/bsddb/undoredo.py b/gramps/plugins/db/bsddb/undoredo.py index 21e1951e3..b69ac56a8 100644 --- a/gramps/plugins/db/bsddb/undoredo.py +++ b/gramps/plugins/db/bsddb/undoredo.py @@ -244,8 +244,9 @@ class DbUndo: pickle.loads(self.undodb[record_id]) if key != REFERENCE_KEY: - self.undo_signals(old_data, handle, self.mapbase[key], - db.emit, _SIGBASE[key]) + self.undo_signals(trans_type, handle, + db.emit, _SIGBASE[key], True) + # Notify listeners if db.undo_callback: if self.undo_count > 0: @@ -289,8 +290,8 @@ class DbUndo: pickle.loads(self.undodb[record_id]) if key != REFERENCE_KEY: - self.undo_signals(new_data, handle, self.mapbase[key], - db.emit, _SIGBASE[key]) + self.undo_signals(trans_type, handle, + db.emit, _SIGBASE[key], False) # Notify listeners if db.undo_callback: db.undo_callback(_("_Undo %s") @@ -336,24 +337,19 @@ class DbUndo: self.db._log_error() raise DbError(msg) - def undo_signals(self, data, handle, db_map, emit, signal_root): + def undo_signals(self, trans_type, handle, emit, signal_root, reverse): """ Helper method to undo/redo the changes made """ - try: - if data is None: - emit(signal_root + '-delete', ([handle.decode('utf-8')],)) - else: - ex_data = db_map.get(handle, txn=self.txn) - if ex_data: - signal = signal_root + '-update' - else: - signal = signal_root + '-add' - emit(signal, ([handle.decode('utf-8')],)) - - except DBERRS as msg: - self.db._log_error() - raise DbError(msg) + if ((not reverse) and trans_type == TXNADD) \ + or (reverse and trans_type == TXNDEL): + typ = '-add' + elif not reverse and trans_type == TXNDEL \ + or reverse and trans_type == TXNADD: + typ = '-delete' + else: # TXNUPD + typ = '-update' + emit(signal_root + typ, ([handle.decode('utf-8')],)) undo_count = property(lambda self:len(self.undoq)) redo_count = property(lambda self:len(self.redoq))