Add Most Recently Used object functionality to Go menu
svn: r14061
This commit is contained in:
parent
a4b22193c2
commit
4a87cbbe61
@ -78,7 +78,7 @@ class History(gen.utils.Callback):
|
|||||||
|
|
||||||
__signals__ = {
|
__signals__ = {
|
||||||
'active-changed' : (str, ),
|
'active-changed' : (str, ),
|
||||||
'menu-changed' : (list, ),
|
'mru-changed' : (list, )
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -90,7 +90,7 @@ class History(gen.utils.Callback):
|
|||||||
Clears the history, resetting the values back to their defaults
|
Clears the history, resetting the values back to their defaults
|
||||||
"""
|
"""
|
||||||
self.history = []
|
self.history = []
|
||||||
self.mhistory = []
|
self.mru = []
|
||||||
self.index = -1
|
self.index = -1
|
||||||
self.lock = False
|
self.lock = False
|
||||||
|
|
||||||
@ -108,12 +108,12 @@ class History(gen.utils.Callback):
|
|||||||
self.history.remove(del_id)
|
self.history.remove(del_id)
|
||||||
self.index -= 1
|
self.index -= 1
|
||||||
|
|
||||||
mhc = self.mhistory.count(del_id)
|
mhc = self.mru.count(del_id)
|
||||||
for c in range(mhc):
|
for c in range(mhc):
|
||||||
self.mhistory.remove(del_id)
|
self.mru.remove(del_id)
|
||||||
|
self.emit('mru-changed', (self.mru, ))
|
||||||
if self.history:
|
if self.history:
|
||||||
self.emit('active-changed', (self.history[self.index],))
|
self.emit('active-changed', (self.history[self.index],))
|
||||||
self.emit('menu-changed', (self.mhistory, ))
|
|
||||||
|
|
||||||
def push(self, handle):
|
def push(self, handle):
|
||||||
"""
|
"""
|
||||||
@ -122,13 +122,13 @@ class History(gen.utils.Callback):
|
|||||||
self.prune()
|
self.prune()
|
||||||
if len(self.history) == 0 or handle != self.history[-1]:
|
if len(self.history) == 0 or handle != self.history[-1]:
|
||||||
self.history.append(str(handle))
|
self.history.append(str(handle))
|
||||||
if handle in self.mhistory:
|
if handle in self.mru:
|
||||||
self.mhistory.remove(handle)
|
self.mru.remove(handle)
|
||||||
self.mhistory.append(handle)
|
self.mru.append(handle)
|
||||||
|
self.emit('mru-changed', (self.mru, ))
|
||||||
self.index += 1
|
self.index += 1
|
||||||
if self.history:
|
if self.history:
|
||||||
self.emit('active-changed', (self.history[self.index],))
|
self.emit('active-changed', (self.history[self.index],))
|
||||||
self.emit('menu-changed', (self.mhistory, ))
|
|
||||||
|
|
||||||
def forward(self, step=1):
|
def forward(self, step=1):
|
||||||
"""
|
"""
|
||||||
@ -136,9 +136,10 @@ class History(gen.utils.Callback):
|
|||||||
"""
|
"""
|
||||||
self.index += step
|
self.index += step
|
||||||
handle = self.history[self.index]
|
handle = self.history[self.index]
|
||||||
if handle not in self.mhistory:
|
if handle in self.mru:
|
||||||
self.mhistory.append(handle)
|
self.mru.remove(handle)
|
||||||
self.emit('menu-changed', (self.mhistory, ))
|
self.mru.append(handle)
|
||||||
|
self.emit('mru-changed', (self.mru, ))
|
||||||
if self.history:
|
if self.history:
|
||||||
self.emit('active-changed', (self.history[self.index],))
|
self.emit('active-changed', (self.history[self.index],))
|
||||||
return str(self.history[self.index])
|
return str(self.history[self.index])
|
||||||
@ -150,9 +151,10 @@ class History(gen.utils.Callback):
|
|||||||
self.index -= step
|
self.index -= step
|
||||||
try:
|
try:
|
||||||
handle = self.history[self.index]
|
handle = self.history[self.index]
|
||||||
if handle not in self.mhistory:
|
if handle in self.mru:
|
||||||
self.mhistory.append(handle)
|
self.mru.remove(handle)
|
||||||
self.emit('menu-changed', (self.mhistory, ))
|
self.mru.append(handle)
|
||||||
|
self.emit('mru-changed', (self.mru, ))
|
||||||
if self.history:
|
if self.history:
|
||||||
self.emit('active-changed', (self.history[self.index],))
|
self.emit('active-changed', (self.history[self.index],))
|
||||||
return str(self.history[self.index])
|
return str(self.history[self.index])
|
||||||
@ -190,7 +192,6 @@ class History(gen.utils.Callback):
|
|||||||
if not self.at_end():
|
if not self.at_end():
|
||||||
self.history = self.history[0:self.index+1]
|
self.history = self.history[0:self.index+1]
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Recent Docs Menu
|
# Recent Docs Menu
|
||||||
|
@ -48,7 +48,24 @@ import gtk
|
|||||||
#----------------------------------------------------------------
|
#----------------------------------------------------------------
|
||||||
from gui.views.pageview import PageView
|
from gui.views.pageview import PageView
|
||||||
from TransUtils import sgettext as _
|
from TransUtils import sgettext as _
|
||||||
|
from Utils import navigation_label
|
||||||
|
|
||||||
|
DISABLED = -1
|
||||||
|
MRU_SIZE = 10
|
||||||
|
|
||||||
|
MRU_TOP = [
|
||||||
|
'<ui>'
|
||||||
|
'<menubar name="MenuBar">'
|
||||||
|
'<menu action="GoMenu">'
|
||||||
|
'<placeholder name="CommonHistory">'
|
||||||
|
]
|
||||||
|
|
||||||
|
MRU_BTM = [
|
||||||
|
'</placeholder>'
|
||||||
|
'</menu>'
|
||||||
|
'</menubar>'
|
||||||
|
'</ui>'
|
||||||
|
]
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# NavigationView
|
# NavigationView
|
||||||
@ -71,7 +88,9 @@ class NavigationView(PageView):
|
|||||||
self.book_action = None
|
self.book_action = None
|
||||||
self.other_action = None
|
self.other_action = None
|
||||||
self.active_signal = None
|
self.active_signal = None
|
||||||
|
self.mru_signal = None
|
||||||
self.nav_group = nav_group
|
self.nav_group = nav_group
|
||||||
|
self.mru_active = DISABLED
|
||||||
|
|
||||||
self.uistate.register(self.navigation_type(), self.nav_group)
|
self.uistate.register(self.navigation_type(), self.nav_group)
|
||||||
|
|
||||||
@ -126,6 +145,8 @@ class NavigationView(PageView):
|
|||||||
|
|
||||||
hobj = self.get_history()
|
hobj = self.get_history()
|
||||||
self.active_signal = hobj.connect('active-changed', self.goto_active)
|
self.active_signal = hobj.connect('active-changed', self.goto_active)
|
||||||
|
self.mru_signal = hobj.connect('mru-changed', self.update_mru_menu)
|
||||||
|
self.update_mru_menu(hobj.mru)
|
||||||
|
|
||||||
self.goto_active(None)
|
self.goto_active(None)
|
||||||
|
|
||||||
@ -138,6 +159,8 @@ class NavigationView(PageView):
|
|||||||
self.bookmarks.undisplay()
|
self.bookmarks.undisplay()
|
||||||
hobj = self.get_history()
|
hobj = self.get_history()
|
||||||
hobj.disconnect(self.active_signal)
|
hobj.disconnect(self.active_signal)
|
||||||
|
hobj.disconnect(self.mru_signal)
|
||||||
|
self.mru_disable()
|
||||||
|
|
||||||
def navigation_group(self):
|
def navigation_group(self):
|
||||||
"""
|
"""
|
||||||
@ -337,19 +360,10 @@ class NavigationView(PageView):
|
|||||||
hobj = self.get_history()
|
hobj = self.get_history()
|
||||||
hobj.lock = True
|
hobj.lock = True
|
||||||
if not hobj.at_end():
|
if not hobj.at_end():
|
||||||
try:
|
hobj.forward()
|
||||||
handle = hobj.forward()
|
|
||||||
self.uistate.modify_statusbar(self.dbstate)
|
self.uistate.modify_statusbar(self.dbstate)
|
||||||
hobj.mhistory.append(hobj.history[hobj.index])
|
|
||||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||||
self.back_action.set_sensitive(True)
|
self.back_action.set_sensitive(True)
|
||||||
except:
|
|
||||||
hobj.clear()
|
|
||||||
self.fwd_action.set_sensitive(False)
|
|
||||||
self.back_action.set_sensitive(False)
|
|
||||||
else:
|
|
||||||
self.fwd_action.set_sensitive(False)
|
|
||||||
self.back_action.set_sensitive(True)
|
|
||||||
hobj.lock = False
|
hobj.lock = False
|
||||||
|
|
||||||
def back_clicked(self, obj):
|
def back_clicked(self, obj):
|
||||||
@ -359,21 +373,60 @@ class NavigationView(PageView):
|
|||||||
hobj = self.get_history()
|
hobj = self.get_history()
|
||||||
hobj.lock = True
|
hobj.lock = True
|
||||||
if not hobj.at_front():
|
if not hobj.at_front():
|
||||||
try:
|
hobj.back()
|
||||||
handle = hobj.back()
|
|
||||||
self.uistate.modify_statusbar(self.dbstate)
|
self.uistate.modify_statusbar(self.dbstate)
|
||||||
hobj.mhistory.append(hobj.history[hobj.index])
|
|
||||||
self.back_action.set_sensitive(not hobj.at_front())
|
self.back_action.set_sensitive(not hobj.at_front())
|
||||||
self.fwd_action.set_sensitive(True)
|
self.fwd_action.set_sensitive(True)
|
||||||
except:
|
|
||||||
hobj.clear()
|
|
||||||
self.fwd_action.set_sensitive(False)
|
|
||||||
self.back_action.set_sensitive(False)
|
|
||||||
else:
|
|
||||||
self.back_action.set_sensitive(False)
|
|
||||||
self.fwd_action.set_sensitive(True)
|
|
||||||
hobj.lock = False
|
hobj.lock = False
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# MRU functions
|
||||||
|
####################################################################
|
||||||
|
|
||||||
|
def mru_disable(self):
|
||||||
|
"""
|
||||||
|
Remove the UI and action groups for the MRU list.
|
||||||
|
"""
|
||||||
|
if self.mru_active != DISABLED:
|
||||||
|
self.uistate.uimanager.remove_ui(self.mru_active)
|
||||||
|
self.uistate.uimanager.remove_action_group(self.mru_action)
|
||||||
|
self.mru_active = DISABLED
|
||||||
|
|
||||||
|
def mru_enable(self):
|
||||||
|
"""
|
||||||
|
Enables the UI and action groups for the MRU list.
|
||||||
|
"""
|
||||||
|
if self.mru_active == DISABLED:
|
||||||
|
self.uistate.uimanager.insert_action_group(self.mru_action, 1)
|
||||||
|
self.mru_active = self.uistate.uimanager.add_ui_from_string(self.mru_ui)
|
||||||
|
self.uistate.uimanager.ensure_update()
|
||||||
|
|
||||||
|
def update_mru_menu(self, items):
|
||||||
|
"""
|
||||||
|
Builds the UI and action group for the MRU list.
|
||||||
|
"""
|
||||||
|
self.mru_disable()
|
||||||
|
nav_type = self.navigation_type()
|
||||||
|
hobj = self.get_history()
|
||||||
|
menu_len = min(len(items) - 1, MRU_SIZE)
|
||||||
|
|
||||||
|
entry = '<menuitem action="%s%02d"/>'
|
||||||
|
data = [entry % (nav_type, index) for index in range(0, menu_len)]
|
||||||
|
self.mru_ui = "".join(MRU_TOP) + "".join(data) + "".join(MRU_BTM)
|
||||||
|
|
||||||
|
mitems = items[-MRU_SIZE - 1:-1] # Ignore current handle
|
||||||
|
mitems.reverse()
|
||||||
|
data = []
|
||||||
|
for index, handle in enumerate(mitems):
|
||||||
|
name, obj = navigation_label(self.dbstate.db, nav_type, handle)
|
||||||
|
data.append(('%s%02d'%(nav_type, index), None, name,
|
||||||
|
"<alt>%d" % index, None,
|
||||||
|
make_callback(hobj.push, handle)))
|
||||||
|
|
||||||
|
self.mru_action = gtk.ActionGroup(nav_type)
|
||||||
|
self.mru_action.add_actions(data)
|
||||||
|
self.mru_enable()
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
# Template functions
|
# Template functions
|
||||||
####################################################################
|
####################################################################
|
||||||
@ -422,3 +475,8 @@ class NavigationView(PageView):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def make_callback(func, handle):
|
||||||
|
"""
|
||||||
|
Generates a callback function based off the passed arguments
|
||||||
|
"""
|
||||||
|
return lambda x: func(handle)
|
||||||
|
@ -302,6 +302,7 @@ class PlaceBaseView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="EditMenu">
|
<menu action="EditMenu">
|
||||||
|
@ -156,6 +156,7 @@ class EventView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="FileMenu">
|
<menu action="FileMenu">
|
||||||
|
@ -134,6 +134,7 @@ class FamilyView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="EditMenu">
|
<menu action="EditMenu">
|
||||||
|
@ -599,6 +599,17 @@ class FanChartView(NavigationView):
|
|||||||
|
|
||||||
def ui_definition(self):
|
def ui_definition(self):
|
||||||
return '''<ui>
|
return '''<ui>
|
||||||
|
<menubar name="MenuBar">
|
||||||
|
<menu action="GoMenu">
|
||||||
|
<placeholder name="CommonGo">
|
||||||
|
<menuitem action="Back"/>
|
||||||
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
|
<menuitem action="HomePerson"/>
|
||||||
|
<separator/>
|
||||||
|
</placeholder>
|
||||||
|
</menu>
|
||||||
|
</menubar>
|
||||||
<toolbar name="ToolBar">
|
<toolbar name="ToolBar">
|
||||||
<placeholder name="CommonNavigation">
|
<placeholder name="CommonNavigation">
|
||||||
<toolitem action="Back"/>
|
<toolitem action="Back"/>
|
||||||
|
@ -367,6 +367,7 @@ class MediaView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
</menubar>
|
</menubar>
|
||||||
|
@ -153,6 +153,7 @@ class NoteView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="EditMenu">
|
<menu action="EditMenu">
|
||||||
|
@ -167,6 +167,7 @@ class RepositoryView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="EditMenu">
|
<menu action="EditMenu">
|
||||||
|
@ -162,6 +162,7 @@ class SourceView(ListView):
|
|||||||
<placeholder name="CommonGo">
|
<placeholder name="CommonGo">
|
||||||
<menuitem action="Back"/>
|
<menuitem action="Back"/>
|
||||||
<menuitem action="Forward"/>
|
<menuitem action="Forward"/>
|
||||||
|
<separator/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
</menu>
|
</menu>
|
||||||
<menu action="EditMenu">
|
<menu action="EditMenu">
|
||||||
|
Loading…
Reference in New Issue
Block a user