6786: Invoke editor on double-click in backlinks gramplet
svn: r22955
This commit is contained in:
parent
1dc39d8c1c
commit
d1c0be81f8
@ -42,9 +42,9 @@ from gi.repository import Gtk
|
||||
# GRAMPS classes
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.errors import WindowActiveError
|
||||
from ...widgets import SimpleButton
|
||||
from .embeddedlist import EmbeddedList
|
||||
from ...utils import edit_object
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -135,74 +135,5 @@ class BackRefList(EmbeddedList):
|
||||
return (None, None)
|
||||
|
||||
def edit_button_clicked(self, obj):
|
||||
|
||||
from .. 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 WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Family':
|
||||
try:
|
||||
family = self.dbstate.db.get_family_from_handle(ref)
|
||||
EditFamily(self.dbstate, self.uistate, [], family)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Source':
|
||||
try:
|
||||
source = self.dbstate.db.get_source_from_handle(ref)
|
||||
EditSource(self.dbstate, self.uistate, [], source)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Citation':
|
||||
try:
|
||||
citation = self.dbstate.db.get_citation_from_handle(ref)
|
||||
EditCitation(self.dbstate, self.uistate, [], citation)
|
||||
except 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 gramps.gui.dialog 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 WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'MediaObject':
|
||||
try:
|
||||
obj = self.dbstate.db.get_object_from_handle(ref)
|
||||
EditMedia(self.dbstate, self.uistate, [], obj)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Event':
|
||||
try:
|
||||
event = self.dbstate.db.get_event_from_handle(ref)
|
||||
EditEvent(self.dbstate, self.uistate, [], event)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Repository':
|
||||
try:
|
||||
repo = self.dbstate.db.get_repository_from_handle(ref)
|
||||
EditRepository(self.dbstate, self.uistate, [], repo)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
edit_object(self.dbstate, self.uistate, reftype, ref)
|
||||
|
@ -58,6 +58,7 @@ from gramps.gen.lib.person import Person
|
||||
from gramps.gen.constfunc import has_display, is_quartz, mac, win
|
||||
from gramps.gen.config import config
|
||||
from gramps.gen.plug.utils import available_updates
|
||||
from gramps.gen.errors import WindowActiveError
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -543,6 +544,79 @@ def hex_to_color(hex):
|
||||
color = Gdk.color_parse(hex)
|
||||
return color
|
||||
|
||||
def edit_object(dbstate, uistate, reftype, ref):
|
||||
"""
|
||||
Invokes the appropriate editor for an object type and given handle.
|
||||
"""
|
||||
from .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 WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Family':
|
||||
try:
|
||||
family = dbstate.db.get_family_from_handle(ref)
|
||||
EditFamily(dbstate, uistate, [], family)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Source':
|
||||
try:
|
||||
source = dbstate.db.get_source_from_handle(ref)
|
||||
EditSource(dbstate, uistate, [], source)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Citation':
|
||||
try:
|
||||
citation = dbstate.db.get_citation_from_handle(ref)
|
||||
EditCitation(dbstate, uistate, [], citation)
|
||||
except 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 WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'MediaObject':
|
||||
try:
|
||||
obj = dbstate.db.get_object_from_handle(ref)
|
||||
EditMedia(dbstate, uistate, [], obj)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Event':
|
||||
try:
|
||||
event = dbstate.db.get_event_from_handle(ref)
|
||||
EditEvent(dbstate, uistate, [], event)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
elif reftype == 'Repository':
|
||||
try:
|
||||
repo = dbstate.db.get_repository_from_handle(ref)
|
||||
EditRepository(dbstate, uistate, [], repo)
|
||||
except WindowActiveError:
|
||||
pass
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# AvailableUpdates
|
||||
|
@ -23,6 +23,7 @@
|
||||
from gramps.gui.listmodel import ListModel, NOSORT
|
||||
from gramps.gen.utils.db import navigation_label
|
||||
from gramps.gen.plug import Gramplet
|
||||
from gramps.gui.utils import edit_object
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from gi.repository import Gtk
|
||||
@ -43,8 +44,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):
|
||||
@ -54,7 +57,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):
|
||||
@ -67,6 +70,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.
|
||||
|
Loading…
Reference in New Issue
Block a user