From f21fb8d6d8c0fc39288b29c1471c434464fb94de Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Tue, 2 Mar 2010 15:48:05 +0000 Subject: [PATCH] Update history and MRU lists when objects are deleted svn: r14580 --- src/DisplayState.py | 34 +++++++++++++++++++++++++++++--- src/gen/plug/_gramplet.py | 2 +- src/gui/views/navigationview.py | 2 +- src/plugins/lib/libpersonview.py | 4 ---- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/DisplayState.py b/src/DisplayState.py index adfc99115..83406035c 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -80,10 +80,22 @@ class History(gen.utils.Callback): 'mru-changed' : (list, ) } - def __init__(self): + def __init__(self, dbstate, nav_type): gen.utils.Callback.__init__(self) self.clear() + dbstate.connect('database-changed', self.connect_signals) + self.signal_map = {} + self.signal_map[nav_type.lower() + '-delete'] = self.handles_removed + self.signal_map[nav_type.lower() + '-rebuild'] = self.history_changed + + def connect_signals(self, dbstate): + """ + Connects database signals when the database has changed. + """ + for sig in self.signal_map: + dbstate.connect(sig, self.signal_map[sig]) + def clear(self): """ Clears the history, resetting the values back to their defaults @@ -191,6 +203,22 @@ class History(gen.utils.Callback): if not self.at_end(): self.history = self.history[0:self.index+1] + def handles_removed(self, handle_list): + """ + Called in response to an object-delete signal. + Removes a list of handles from the history. + """ + for handle in handle_list: + self.remove(handle) + + def history_changed(self): + """ + Called in response to an object-rebuild signal. + Objects in the history list may have been deleted. + """ + self.clear() + self.emit('mru-changed', (self.mru, )) + #------------------------------------------------------------------------- # # Recent Docs Menu @@ -370,13 +398,13 @@ class DisplayState(gen.utils.Callback): """ return self.history_lookup.get((nav_type, nav_group)) - def register(self, nav_type, nav_group): + def register(self, dbstate, nav_type, nav_group): """ Create a history and navigation object for the specified navigation type and group, if they don't exist. """ if (nav_type, nav_group) not in self.history_lookup: - history = History() + history = History(dbstate, nav_type) self.history_lookup[(nav_type, nav_group)] = history def get_active(self, nav_type, nav_group=0): diff --git a/src/gen/plug/_gramplet.py b/src/gen/plug/_gramplet.py index 533c55265..80d96b0ce 100644 --- a/src/gen/plug/_gramplet.py +++ b/src/gen/plug/_gramplet.py @@ -68,7 +68,7 @@ class Gramplet(object): Connect the given method to the active-changed signal for the navigation type requested. """ - self.uistate.register(nav_type, self.nav_group) + self.uistate.register(self.dbstate, nav_type, self.nav_group) history = self.uistate.get_history(nav_type, self.nav_group) self.connect(history, "active-changed", method) diff --git a/src/gui/views/navigationview.py b/src/gui/views/navigationview.py index 68e4e754c..df4e01ead 100644 --- a/src/gui/views/navigationview.py +++ b/src/gui/views/navigationview.py @@ -92,7 +92,7 @@ class NavigationView(PageView): self.nav_group = nav_group self.mru_active = DISABLED - self.uistate.register(self.navigation_type(), self.nav_group) + self.uistate.register(state, self.navigation_type(), self.nav_group) def navigation_type(self): diff --git a/src/plugins/lib/libpersonview.py b/src/plugins/lib/libpersonview.py index 7688b4fe3..47ba644b7 100644 --- a/src/plugins/lib/libpersonview.py +++ b/src/plugins/lib/libpersonview.py @@ -297,10 +297,6 @@ class BasePersonView(ListView): # commit the transaction self.dbstate.db.transaction_commit(trans, active_name) - # select the previously active person, turn off the busy cursor - history = self.uistate.get_history(self.navigation_type(), - self.navigation_group()) - history.remove(person.handle) self.uistate.set_busy_cursor(False) def dummy_report(self, obj):