Update history and MRU lists when objects are deleted

svn: r14581
This commit is contained in:
Nick Hall 2010-03-02 15:49:27 +00:00
parent 045a787ad1
commit 1698f8ddbf
4 changed files with 33 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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