Undo of delete doesn't update views

Fixes #10056.
This commit is contained in:
prculley 2017-05-28 13:44:01 -05:00 committed by Nick Hall
parent 3150fae2b8
commit c1aeb6b203
2 changed files with 31 additions and 36 deletions

View File

@ -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):

View File

@ -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))