Extend history functionality (back/forward) and active-changed signals to all primary objects
svn: r14023
This commit is contained in:
@@ -580,7 +580,7 @@ class EditPerson(EditPrimary):
|
||||
self.home_action.set_sensitive(True)
|
||||
|
||||
def _make_active(self, obj):
|
||||
self.dbstate.change_active_person(self.obj)
|
||||
self.uistate.set_active(self.obj.get_handle(), 'Person')
|
||||
|
||||
def _make_home_person(self, obj):
|
||||
handle = self.obj.get_handle()
|
||||
|
||||
@@ -71,8 +71,6 @@ import GrampsCfg
|
||||
import Errors
|
||||
from QuestionDialog import (ErrorDialog, WarningDialog, QuestionDialog2,
|
||||
InfoDialog)
|
||||
import gui.views.navigationview as NavigationView
|
||||
import Navigation
|
||||
from BasicUtils import name_displayer
|
||||
from gui import widgets
|
||||
import UndoHistory
|
||||
@@ -341,10 +339,7 @@ class ViewManager(CLIManager):
|
||||
openbtn = self.__build_open_button()
|
||||
self.uistate.set_open_widget(openbtn)
|
||||
self.toolbar.insert(openbtn, 0)
|
||||
|
||||
self.person_nav = Navigation.PersonNavigation(self.dbstate, self.uistate)
|
||||
self._navigation_type[NavigationView.NAVIGATION_PERSON] = \
|
||||
(self.person_nav, None)
|
||||
|
||||
self.recent_manager = DisplayState.RecentDocsMenu(
|
||||
self.uistate, self.dbstate, self._read_recent_file)
|
||||
self.recent_manager.build()
|
||||
@@ -531,18 +526,6 @@ class ViewManager(CLIManager):
|
||||
_('Undo History...'), "<control>H", None, self.undo_history),
|
||||
]
|
||||
|
||||
self._navigation_type = {
|
||||
None: (None, None),
|
||||
NavigationView.NAVIGATION_PERSON: (None, None),
|
||||
NavigationView.NAVIGATION_FAMILY: (None, None),
|
||||
NavigationView.NAVIGATION_EVENT: (None, None),
|
||||
NavigationView.NAVIGATION_PLACE: (None, None),
|
||||
NavigationView.NAVIGATION_SOURCE: (None, None),
|
||||
NavigationView.NAVIGATION_REPOSITORY: (None, None),
|
||||
NavigationView.NAVIGATION_MEDIA: (None, None),
|
||||
NavigationView.NAVIGATION_NOTE: (None, None)
|
||||
}
|
||||
|
||||
def __keypress(self, action):
|
||||
"""
|
||||
Callback that is called on a keypress. It works by extracting the
|
||||
@@ -576,8 +559,8 @@ class ViewManager(CLIManager):
|
||||
def __prev_view(self, action):
|
||||
"""
|
||||
Callback that is called when the previous view action is selected.
|
||||
It selects the previous view as the active view. If we reach the beginning
|
||||
of the list of views, we wrap around to the last view.
|
||||
It selects the previous view as the active view. If we reach the
|
||||
beginning of the list of views, we wrap around to the last view.
|
||||
"""
|
||||
current_page = self.notebook.get_current_page()
|
||||
if current_page == 0:
|
||||
@@ -883,7 +866,6 @@ class ViewManager(CLIManager):
|
||||
Create the Views
|
||||
"""
|
||||
self.pages = []
|
||||
self.prev_nav = None
|
||||
self.ui_category = {}
|
||||
self.view_toggle_actions = {}
|
||||
self.cat_view_group = None
|
||||
@@ -908,6 +890,7 @@ class ViewManager(CLIManager):
|
||||
page_category = page.get_category()
|
||||
page_translated_category = page.get_translated_category()
|
||||
page_stock = page.get_stock()
|
||||
|
||||
if nrpage == 0:
|
||||
#the first page of this category, used to obtain
|
||||
#category workspace notebook
|
||||
@@ -1123,19 +1106,6 @@ class ViewManager(CLIManager):
|
||||
category_page])
|
||||
self.merge_ids.append(mergeid)
|
||||
|
||||
def __setup_navigation(self):
|
||||
"""
|
||||
Initialize the navigation scheme
|
||||
"""
|
||||
old_nav = self._navigation_type[self.prev_nav]
|
||||
if old_nav[0] is not None:
|
||||
old_nav[0].disable()
|
||||
|
||||
page_type = self.active_page.navigation_type()
|
||||
nav_type = self._navigation_type[page_type]
|
||||
if nav_type[0] is not None:
|
||||
nav_type[0].enable()
|
||||
|
||||
def change_category(self, obj, page, num=-1):
|
||||
"""
|
||||
Wrapper for the __do_change_category, to prevent entering into the
|
||||
@@ -1184,7 +1154,6 @@ class ViewManager(CLIManager):
|
||||
self.views[category_page][view_page][0].id)
|
||||
config.save()
|
||||
|
||||
self.__setup_navigation()
|
||||
self.__connect_active_page(category_page, view_page)
|
||||
|
||||
self.uimanager.ensure_update()
|
||||
@@ -1226,12 +1195,6 @@ class ViewManager(CLIManager):
|
||||
This method is for the common UI post_load, both new files
|
||||
and added data like imports.
|
||||
"""
|
||||
if self.dbstate.active :
|
||||
# clear history and fill history with first entry, active person
|
||||
self.uistate.clear_history(self.dbstate.active.handle)
|
||||
else :
|
||||
self.uistate.clear_history(None)
|
||||
|
||||
self.dbstate.db.undo_callback = self.__change_undo_label
|
||||
self.dbstate.db.redo_callback = self.__change_redo_label
|
||||
self.__change_undo_label(None)
|
||||
@@ -1270,8 +1233,6 @@ class ViewManager(CLIManager):
|
||||
self.uistate.window.set_title(msg)
|
||||
self.actiongroup.set_sensitive(True)
|
||||
|
||||
self.setup_bookmarks()
|
||||
|
||||
self.change_category(None, None)
|
||||
self.actiongroup.set_visible(True)
|
||||
self.readonlygroup.set_visible(True)
|
||||
@@ -1339,36 +1300,6 @@ class ViewManager(CLIManager):
|
||||
# Let it go: history window does not exist
|
||||
return
|
||||
|
||||
def setup_bookmarks(self):
|
||||
"""
|
||||
Initialize the bookmarks based of the database. This needs to
|
||||
be called anytime the database changes.
|
||||
"""
|
||||
import Bookmarks
|
||||
self.bookmarks = Bookmarks.Bookmarks(
|
||||
self.dbstate, self.uistate, self.dbstate.db.get_bookmarks())
|
||||
|
||||
def add_bookmark(self, obj):
|
||||
"""
|
||||
Add a bookmark to the bookmark list
|
||||
"""
|
||||
if self.dbstate.active:
|
||||
self.bookmarks.add(self.dbstate.active.get_handle())
|
||||
name = name_displayer.display(self.dbstate.active)
|
||||
self.uistate.push_message(self.dbstate,
|
||||
_("%s has been bookmarked") % name)
|
||||
else:
|
||||
WarningDialog(
|
||||
_("Could Not Set a Bookmark"),
|
||||
_("A bookmark could not be set because "
|
||||
"no one was selected."))
|
||||
|
||||
def edit_bookmarks(self, obj):
|
||||
"""
|
||||
Displays the Bookmark editor
|
||||
"""
|
||||
self.bookmarks.edit()
|
||||
|
||||
def reports_clicked(self, obj):
|
||||
"""
|
||||
Displays the Reports dialog
|
||||
@@ -1615,7 +1546,7 @@ def run_plugin(pdata, dbstate, uistate):
|
||||
return
|
||||
|
||||
if pdata.ptype == REPORT:
|
||||
ReportBase.report(dbstate, uistate, dbstate.active,
|
||||
ReportBase.report(dbstate, uistate, uistate.get_active('Person'),
|
||||
getattr(mod, pdata.reportclass),
|
||||
getattr(mod, pdata.optionclass),
|
||||
pdata.name, pdata.id,
|
||||
|
||||
@@ -87,11 +87,11 @@ class ListView(NavigationView):
|
||||
QR_CATEGORY = -1
|
||||
|
||||
def __init__(self, title, dbstate, uistate, columns, handle_col,
|
||||
make_model, signal_map, get_bookmarks, bm_type,
|
||||
make_model, signal_map, get_bookmarks, bm_type, nav_group,
|
||||
multiple=False, filter_class=None, markup=False):
|
||||
|
||||
NavigationView.__init__(self, title, dbstate, uistate,
|
||||
get_bookmarks, bm_type)
|
||||
get_bookmarks, bm_type, nav_group)
|
||||
#default is listviews keep themself in sync with database
|
||||
self._dirty_on_change_inactive = False
|
||||
|
||||
@@ -756,7 +756,7 @@ class ListView(NavigationView):
|
||||
self.uistate.uimanager.\
|
||||
get_widget('/Popup/QuickReport').remove_submenu()
|
||||
reportactions = []
|
||||
if menu and self.dbstate.active:
|
||||
if menu and self.get_active():
|
||||
(ui, reportactions) = create_quickreport_menu(
|
||||
self.QR_CATEGORY,
|
||||
self.dbstate,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2001-2007 Donald N. Allingham
|
||||
# Copyright (C) 2009 Nick Hall
|
||||
# Copyright (C) 2009-2010 Nick Hall
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -47,19 +47,8 @@ import gtk
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
from gui.views.pageview import PageView
|
||||
|
||||
from TransUtils import sgettext as _
|
||||
|
||||
NAVIGATION_NONE = -1
|
||||
NAVIGATION_PERSON = 0
|
||||
NAVIGATION_FAMILY = 1
|
||||
NAVIGATION_EVENT = 2
|
||||
NAVIGATION_PLACE = 3
|
||||
NAVIGATION_SOURCE = 4
|
||||
NAVIGATION_REPOSITORY = 5
|
||||
NAVIGATION_MEDIA = 6
|
||||
NAVIGATION_NOTE = 7
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# NavigationView
|
||||
@@ -72,7 +61,7 @@ class NavigationView(PageView):
|
||||
should derive from this class.
|
||||
"""
|
||||
|
||||
def __init__(self, title, state, uistate, bookmarks, bm_type):
|
||||
def __init__(self, title, state, uistate, bookmarks, bm_type, nav_group):
|
||||
PageView.__init__(self, title, state, uistate)
|
||||
self.bookmarks = bm_type(self.dbstate, self.uistate, bookmarks,
|
||||
self.goto_handle)
|
||||
@@ -81,7 +70,10 @@ class NavigationView(PageView):
|
||||
self.back_action = None
|
||||
self.book_action = None
|
||||
self.other_action = None
|
||||
self.key_active_changed = None
|
||||
self.active_signal = None
|
||||
self.nav_group = nav_group
|
||||
|
||||
self.uistate.register(self.navigation_type(), self.nav_group)
|
||||
|
||||
def define_actions(self):
|
||||
"""
|
||||
@@ -111,7 +103,7 @@ class NavigationView(PageView):
|
||||
|
||||
self.fwd_action.set_visible(True)
|
||||
self.back_action.set_visible(True)
|
||||
hobj = self.uistate.phistory
|
||||
hobj = self.get_history()
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
|
||||
@@ -119,19 +111,22 @@ class NavigationView(PageView):
|
||||
"""
|
||||
Called when the page changes.
|
||||
"""
|
||||
hobj = self.uistate.phistory
|
||||
hobj = self.get_history()
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
self.other_action.set_sensitive(not self.dbstate.db.readonly)
|
||||
|
||||
self.uistate.modify_statusbar(self.dbstate)
|
||||
|
||||
def set_active(self):
|
||||
"""
|
||||
Called when the page becomes active (displayed).
|
||||
"""
|
||||
PageView.set_active(self)
|
||||
self.bookmarks.display()
|
||||
self.key_active_changed = self.dbstate.connect('active-changed',
|
||||
self.goto_active)
|
||||
|
||||
hobj = self.get_history()
|
||||
self.active_signal = hobj.connect('active-changed', self.goto_active)
|
||||
|
||||
self.goto_active(None)
|
||||
|
||||
def set_inactive(self):
|
||||
@@ -141,26 +136,51 @@ class NavigationView(PageView):
|
||||
if self.active:
|
||||
PageView.set_inactive(self)
|
||||
self.bookmarks.undisplay()
|
||||
self.dbstate.disconnect(self.key_active_changed)
|
||||
hobj = self.get_history()
|
||||
hobj.disconnect(self.active_signal)
|
||||
|
||||
def navigation_group(self):
|
||||
"""
|
||||
Return the navigation group.
|
||||
"""
|
||||
return self.nav_group
|
||||
|
||||
def get_history(self):
|
||||
"""
|
||||
Return the history object.
|
||||
"""
|
||||
return self.uistate.get_history(self.navigation_type(),
|
||||
self.navigation_group())
|
||||
|
||||
def goto_active(self, active_handle):
|
||||
"""
|
||||
Callback (and usable function) that selects the active person
|
||||
in the display tree.
|
||||
"""
|
||||
if self.dbstate.active:
|
||||
self.handle_history(self.dbstate.active.handle)
|
||||
active_handle = self.uistate.get_active(self.navigation_type(),
|
||||
self.navigation_group())
|
||||
if active_handle:
|
||||
self.goto_handle(active_handle)
|
||||
|
||||
hobj = self.get_history()
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
|
||||
# active object for each navigation type
|
||||
if self.navigation_type() == NAVIGATION_PERSON:
|
||||
if self.dbstate.active:
|
||||
self.goto_handle(self.dbstate.active.handle)
|
||||
|
||||
def get_active(self):
|
||||
"""
|
||||
Return the handle of the active object.
|
||||
"""
|
||||
hobj = self.uistate.get_history(self.navigation_type(),
|
||||
self.navigation_group())
|
||||
return hobj.present()
|
||||
|
||||
def change_active(self, handle):
|
||||
"""
|
||||
Changes the active object.
|
||||
"""
|
||||
self.dbstate.set_active(self.navigation_type(), handle)
|
||||
hobj = self.get_history()
|
||||
if handle and not hobj.lock and not (handle == hobj.present()):
|
||||
hobj.push(handle)
|
||||
|
||||
def goto_handle(self, handle):
|
||||
"""
|
||||
@@ -177,10 +197,12 @@ class NavigationView(PageView):
|
||||
Add a bookmark to the list.
|
||||
"""
|
||||
from BasicUtils import name_displayer
|
||||
|
||||
if self.dbstate.active:
|
||||
self.bookmarks.add(self.dbstate.active.get_handle())
|
||||
name = name_displayer.display(self.dbstate.active)
|
||||
|
||||
active_handle = self.uistate.get_active('Person')
|
||||
active_person = self.dbstate.db.get_person_from_handle(active_handle)
|
||||
if active_person:
|
||||
self.bookmarks.add(active_handle)
|
||||
name = name_displayer.display(active_person)
|
||||
self.uistate.push_message(self.dbstate,
|
||||
_("%s has been bookmarked") % name)
|
||||
else:
|
||||
@@ -253,9 +275,9 @@ class NavigationView(PageView):
|
||||
"""
|
||||
Set the default person.
|
||||
"""
|
||||
active = self.dbstate.active
|
||||
active = self.uistate.get_active('Person')
|
||||
if active:
|
||||
self.dbstate.db.set_default_person_handle(active.get_handle())
|
||||
self.dbstate.db.set_default_person_handle(active)
|
||||
|
||||
def home(self, obj):
|
||||
"""
|
||||
@@ -263,7 +285,7 @@ class NavigationView(PageView):
|
||||
"""
|
||||
defperson = self.dbstate.db.get_default_person()
|
||||
if defperson:
|
||||
self.dbstate.change_active_person(defperson)
|
||||
self.change_active(defperson.get_handle())
|
||||
|
||||
def jump(self):
|
||||
"""
|
||||
@@ -293,9 +315,7 @@ class NavigationView(PageView):
|
||||
gid = text.get_text()
|
||||
handle = self.get_handle_from_gramps_id(gid)
|
||||
if handle is not None:
|
||||
if self.navigation_type() == NAVIGATION_PERSON:
|
||||
self.change_active(handle)
|
||||
|
||||
self.change_active(handle)
|
||||
self.goto_handle(handle)
|
||||
else:
|
||||
self.uistate.push_message(
|
||||
@@ -314,12 +334,11 @@ class NavigationView(PageView):
|
||||
"""
|
||||
Move forward one object in the history.
|
||||
"""
|
||||
hobj = self.uistate.phistory
|
||||
hobj = self.get_history()
|
||||
hobj.lock = True
|
||||
if not hobj.at_end():
|
||||
try:
|
||||
handle = hobj.forward()
|
||||
self.dbstate.change_active_handle(handle)
|
||||
self.uistate.modify_statusbar(self.dbstate)
|
||||
hobj.mhistory.append(hobj.history[hobj.index])
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
@@ -337,14 +356,12 @@ class NavigationView(PageView):
|
||||
"""
|
||||
Move backward one object in the history.
|
||||
"""
|
||||
hobj = self.uistate.phistory
|
||||
hobj = self.get_history()
|
||||
hobj.lock = True
|
||||
if not hobj.at_front():
|
||||
try:
|
||||
handle = hobj.back()
|
||||
self.active = self.dbstate.db.get_person_from_handle(handle)
|
||||
self.uistate.modify_statusbar(self.dbstate)
|
||||
self.dbstate.change_active_handle(handle)
|
||||
hobj.mhistory.append(hobj.history[hobj.index])
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
self.fwd_action.set_sensitive(True)
|
||||
@@ -357,18 +374,6 @@ class NavigationView(PageView):
|
||||
self.fwd_action.set_sensitive(True)
|
||||
hobj.lock = False
|
||||
|
||||
def handle_history(self, handle):
|
||||
"""
|
||||
Updates the person history information
|
||||
It will push the person at the end of the history if that person is
|
||||
not present person
|
||||
"""
|
||||
hobj = self.uistate.phistory
|
||||
if handle and not hobj.lock and not (handle == hobj.present()):
|
||||
hobj.push(handle)
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
|
||||
####################################################################
|
||||
# Template functions
|
||||
####################################################################
|
||||
|
||||
@@ -44,7 +44,6 @@ import gtk
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gen.lib
|
||||
from gui.views.navigationview import NAVIGATION_PLACE
|
||||
from gui.views.listview import ListView
|
||||
from gui.utils import add_menuitem
|
||||
import Errors
|
||||
@@ -93,7 +92,7 @@ class PlaceBaseView(ListView):
|
||||
FILTER_TYPE = "Place"
|
||||
QR_CATEGORY = CATEGORY_QR_PLACE
|
||||
|
||||
def __init__(self, dbstate, uistate, title, model):
|
||||
def __init__(self, dbstate, uistate, title, model, nav_group):
|
||||
|
||||
signal_map = {
|
||||
'place-add' : self.row_add,
|
||||
@@ -115,7 +114,7 @@ class PlaceBaseView(ListView):
|
||||
len(PlaceBaseView.COLUMN_NAMES),
|
||||
model, signal_map,
|
||||
dbstate.db.get_place_bookmarks(),
|
||||
Bookmarks.PlaceBookmarks,
|
||||
Bookmarks.PlaceBookmarks, nav_group,
|
||||
multiple=True,
|
||||
filter_class=PlaceSidebarFilter)
|
||||
|
||||
@@ -123,7 +122,7 @@ class PlaceBaseView(ListView):
|
||||
self.filter_toggle)
|
||||
|
||||
def navigation_type(self):
|
||||
return NAVIGATION_PLACE
|
||||
return 'Place'
|
||||
|
||||
def column_ord_setfunc(self, clist):
|
||||
self.dbstate.db.set_place_column_order(clist)
|
||||
@@ -298,6 +297,12 @@ class PlaceBaseView(ListView):
|
||||
<menuitem action="EditBook"/>
|
||||
</placeholder>
|
||||
</menu>
|
||||
<menu action="GoMenu">
|
||||
<placeholder name="CommonGo">
|
||||
<menuitem action="Back"/>
|
||||
<menuitem action="Forward"/>
|
||||
</placeholder>
|
||||
</menu>
|
||||
<menu action="EditMenu">
|
||||
<placeholder name="CommonEdit">
|
||||
<menuitem action="Add"/>
|
||||
@@ -312,6 +317,10 @@ class PlaceBaseView(ListView):
|
||||
</menu>
|
||||
</menubar>
|
||||
<toolbar name="ToolBar">
|
||||
<placeholder name="CommonNavigation">
|
||||
<toolitem action="Back"/>
|
||||
<toolitem action="Forward"/>
|
||||
</placeholder>
|
||||
<placeholder name="CommonEdit">
|
||||
<toolitem action="Add"/>
|
||||
<toolitem action="Edit"/>
|
||||
@@ -321,6 +330,9 @@ class PlaceBaseView(ListView):
|
||||
</placeholder>
|
||||
</toolbar>
|
||||
<popup name="Popup">
|
||||
<menuitem action="Back"/>
|
||||
<menuitem action="Forward"/>
|
||||
<separator/>
|
||||
<menuitem action="Add"/>
|
||||
<menuitem action="Edit"/>
|
||||
<menuitem action="Remove"/>
|
||||
|
||||
Reference in New Issue
Block a user