6786: Invoke editor on double-click in backlinks gramplet

svn: r22954
This commit is contained in:
Nick Hall 2013-08-30 16:05:33 +00:00
parent 449d1366b1
commit 563591b031
3 changed files with 95 additions and 74 deletions

View File

@ -41,9 +41,9 @@ import gtk
# GRAMPS classes
#
#-------------------------------------------------------------------------
import Errors
from gui.widgets import SimpleButton
from embeddedlist import EmbeddedList
from gui.utils import edit_object
#-------------------------------------------------------------------------
#
@ -134,74 +134,5 @@ class BackRefList(EmbeddedList):
return (None, None)
def edit_button_clicked(self, obj):
from gui.editors import EditEvent, EditPerson, EditFamily, EditSource, \
EditPlace, EditMedia, EditRepository, \
EditCitation
(reftype, ref) = self.find_node()
if reftype == 'Person':
try:
person = self.dbstate.db.get_person_from_handle(ref)
EditPerson(self.dbstate, self.uistate, [], person)
except Errors.WindowActiveError:
pass
elif reftype == 'Family':
try:
family = self.dbstate.db.get_family_from_handle(ref)
EditFamily(self.dbstate, self.uistate, [], family)
except Errors.WindowActiveError:
pass
elif reftype == 'Source':
try:
source = self.dbstate.db.get_source_from_handle(ref)
EditSource(self.dbstate, self.uistate, [], source)
except Errors.WindowActiveError:
pass
elif reftype == 'Citation':
try:
citation = self.dbstate.db.get_citation_from_handle(ref)
EditCitation(self.dbstate, self.uistate, [], citation)
except Errors.WindowActiveError:
"""
Return the text used when citation cannot be edited
"""
blocked_text = _("Cannot open new citation editor at this time. "
"Either the citation is already being edited, "
"or the associated source is already being "
"edited, and opening a citation editor "
"(which also allows the source "
"to be edited), would create ambiguity "
"by opening two editors on the same source. "
"\n\n"
"To edit the citation, close the source "
"editor and open an editor for the citation "
"alone")
from QuestionDialog import WarningDialog
WarningDialog(_("Cannot open new citation editor"),
blocked_text)
elif reftype == 'Place':
try:
place = self.dbstate.db.get_place_from_handle(ref)
EditPlace(self.dbstate, self.uistate, [], place)
except Errors.WindowActiveError:
pass
elif reftype == 'MediaObject':
try:
obj = self.dbstate.db.get_object_from_handle(ref)
EditMedia(self.dbstate, self.uistate, [], obj)
except Errors.WindowActiveError:
pass
elif reftype == 'Event':
try:
event = self.dbstate.db.get_event_from_handle(ref)
EditEvent(self.dbstate, self.uistate, [], event)
except Errors.WindowActiveError:
pass
elif reftype == 'Repository':
try:
repo = self.dbstate.db.get_repository_from_handle(ref)
EditRepository(self.dbstate, self.uistate, [], repo)
except Errors.WindowActiveError:
pass
edit_object(self.dbstate, self.uistate, reftype, ref)

View File

@ -433,6 +433,80 @@ def is_right_click(event):
if event.button == 3:
return True
def edit_object(dbstate, uistate, reftype, ref):
"""
Invokes the appropriate editor for an object type and given handle.
"""
from gui.editors import (EditEvent, EditPerson, EditFamily, EditSource,
EditPlace, EditMedia, EditRepository,
EditCitation)
if reftype == 'Person':
try:
person = dbstate.db.get_person_from_handle(ref)
EditPerson(dbstate, uistate, [], person)
except Errors.WindowActiveError:
pass
elif reftype == 'Family':
try:
family = dbstate.db.get_family_from_handle(ref)
EditFamily(dbstate, uistate, [], family)
except Errors.WindowActiveError:
pass
elif reftype == 'Source':
try:
source = dbstate.db.get_source_from_handle(ref)
EditSource(dbstate, uistate, [], source)
except Errors.WindowActiveError:
pass
elif reftype == 'Citation':
try:
citation = dbstate.db.get_citation_from_handle(ref)
EditCitation(dbstate, uistate, [], citation)
except Errors.WindowActiveError:
"""
Return the text used when citation cannot be edited
"""
blocked_text = _("Cannot open new citation editor at this time. "
"Either the citation is already being edited, "
"or the associated source is already being "
"edited, and opening a citation editor "
"(which also allows the source "
"to be edited), would create ambiguity "
"by opening two editors on the same source. "
"\n\n"
"To edit the citation, close the source "
"editor and open an editor for the citation "
"alone")
from QuestionDialog import WarningDialog
WarningDialog(_("Cannot open new citation editor"),
blocked_text)
elif reftype == 'Place':
try:
place = dbstate.db.get_place_from_handle(ref)
EditPlace(dbstate, uistate, [], place)
except Errors.WindowActiveError:
pass
elif reftype == 'MediaObject':
try:
obj = dbstate.db.get_object_from_handle(ref)
EditMedia(dbstate, uistate, [], obj)
except Errors.WindowActiveError:
pass
elif reftype == 'Event':
try:
event = dbstate.db.get_event_from_handle(ref)
EditEvent(dbstate, uistate, [], event)
except Errors.WindowActiveError:
pass
elif reftype == 'Repository':
try:
repo = dbstate.db.get_repository_from_handle(ref)
EditRepository(dbstate, uistate, [], repo)
except Errors.WindowActiveError:
pass
#-------------------------------------------------------------------------
#
# AvailableUpdates

View File

@ -23,6 +23,7 @@
from ListModel import ListModel, NOSORT
from Utils import navigation_label
from gen.plug import Gramplet
from gui.utils import edit_object
from gen.ggettext import gettext as _
import gtk
@ -42,8 +43,10 @@ class Backlinks(Gramplet):
"""
top = gtk.TreeView()
titles = [(_('Type'), 1, 100),
(_('Name'), 2, 100)]
self.model = ListModel(top, titles)
(_('Name'), 2, 100),
('', 3, 1), #hidden column for the handle
('', 4, 1)] #hidden column for non-localized object type
self.model = ListModel(top, titles, event_func=self.cb_double_click)
return top
def display_backlinks(self, active_handle):
@ -53,7 +56,7 @@ class Backlinks(Gramplet):
for classname, handle in \
self.dbstate.db.find_backlink_handles(active_handle):
name = navigation_label(self.dbstate.db, classname, handle)[0]
self.model.add((_(classname), name))
self.model.add((_(classname), name, handle, classname))
self.set_has_data(self.model.count > 0)
def get_has_data(self, active_handle):
@ -66,6 +69,19 @@ class Backlinks(Gramplet):
return True
return False
def cb_double_click(self, treeview):
"""
Handle double click on treeview.
"""
(model, iter_) = treeview.get_selection().get_selected()
if not iter_:
return
(objclass, handle) = (model.get_value(iter_, 3),
model.get_value(iter_, 2))
edit_object(self.dbstate, self.uistate, objclass, handle)
class PersonBacklinks(Backlinks):
"""
Displays the back references for a person.