Fix corrupted Bookmarks that can happen after Gramps crash (#655)

Fixes #10759
This commit is contained in:
Paul Culley 2018-09-03 19:16:21 -05:00 committed by Sam Manzi
parent bb6b3edee2
commit fd399323a6

View File

@ -54,6 +54,7 @@ from ..managedwindow import ManagedWindow
from gramps.gen.utils.db import navigation_label from gramps.gen.utils.db import navigation_label
from gramps.gen.const import URL_MANUAL_PAGE from gramps.gen.const import URL_MANUAL_PAGE
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.errors import HandleError
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -156,6 +157,7 @@ class Bookmarks(metaclass=ABCMeta):
actions = [] actions = []
count = 0 count = 0
bad_bookmarks = [] # list of bad bookmarks
if self.dbstate.is_open() and len(self.bookmarks.get()) > 0: if self.dbstate.is_open() and len(self.bookmarks.get()) > 0:
text.write('<placeholder name="GoToBook">') text.write('<placeholder name="GoToBook">')
@ -169,6 +171,9 @@ class Bookmarks(metaclass=ABCMeta):
count += 1 count += 1
except AttributeError: except AttributeError:
pass pass
except HandleError:
# if bookmark contains handle to something missing now
bad_bookmarks.append(item)
text.write('</placeholder>') text.write('</placeholder>')
text.write(BTM) text.write(BTM)
@ -177,6 +182,10 @@ class Bookmarks(metaclass=ABCMeta):
self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue()) self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue())
self.uistate.uimanager.ensure_update() self.uistate.uimanager.ensure_update()
text.close() text.close()
# Clean up any bad bookmarks (can happen if Gramps crashes;
# modified bookmarks set is saved only on normal Gramps close)
for handle in bad_bookmarks:
self.bookmarks.remove(handle)
@abstractmethod @abstractmethod
def make_label(self, handle): def make_label(self, handle):