Implement drag and drop for citations
svn: r18438
This commit is contained in:
parent
c4c64557d5
commit
7ebf8de20a
@ -87,6 +87,7 @@ for (name, file) in (
|
|||||||
('name', 'geo-show-person.png'),
|
('name', 'geo-show-person.png'),
|
||||||
('repository', 'gramps-repository.png'),
|
('repository', 'gramps-repository.png'),
|
||||||
('source', 'gramps-source.png'),
|
('source', 'gramps-source.png'),
|
||||||
|
('citation', 'gramps-citation.png'),
|
||||||
('text', 'gramps-font.png'),
|
('text', 'gramps-font.png'),
|
||||||
('url', 'gramps-geo.png'),
|
('url', 'gramps-geo.png'),
|
||||||
):
|
):
|
||||||
@ -104,7 +105,7 @@ def map2class(target):
|
|||||||
'personref': ScratchPersonRef,
|
'personref': ScratchPersonRef,
|
||||||
'childref': ScratchChildRef,
|
'childref': ScratchChildRef,
|
||||||
'source-link': ScratchSourceLink,
|
'source-link': ScratchSourceLink,
|
||||||
'srcref': ScratchSourceRef,
|
'citation-link': ScratchCitation,
|
||||||
'repo-link': ScratchRepositoryLink,
|
'repo-link': ScratchRepositoryLink,
|
||||||
'pevent': ScratchEvent,
|
'pevent': ScratchEvent,
|
||||||
'eventref': ScratchEventRef,
|
'eventref': ScratchEventRef,
|
||||||
@ -119,6 +120,7 @@ def obj2class(target):
|
|||||||
d= {"Person": ScratchPersonLink,
|
d= {"Person": ScratchPersonLink,
|
||||||
"Family": ScratchFamilyLink,
|
"Family": ScratchFamilyLink,
|
||||||
'Source': ScratchSourceLink,
|
'Source': ScratchSourceLink,
|
||||||
|
'Citation': ScratchCitation,
|
||||||
'Repository': ScratchRepositoryLink,
|
'Repository': ScratchRepositoryLink,
|
||||||
'Event': ScratchEvent,
|
'Event': ScratchEvent,
|
||||||
'Media': ScratchMediaObj,
|
'Media': ScratchMediaObj,
|
||||||
@ -131,6 +133,7 @@ def obj2target(target):
|
|||||||
d = {"Person": 'person-link',
|
d = {"Person": 'person-link',
|
||||||
"Family": 'family-link',
|
"Family": 'family-link',
|
||||||
'Source': 'source-link',
|
'Source': 'source-link',
|
||||||
|
'Citation': 'citation-link',
|
||||||
'Repository': 'repo-link',
|
'Repository': 'repo-link',
|
||||||
'Event': 'pevent',
|
'Event': 'pevent',
|
||||||
'Media': 'mediaobj',
|
'Media': 'mediaobj',
|
||||||
@ -437,24 +440,25 @@ class ScratchFamilyAttribute(ScratchObjWrapper):
|
|||||||
self._title = str(self._obj.get_type())
|
self._title = str(self._obj.get_type())
|
||||||
self._value = self._obj.get_value()
|
self._value = self._obj.get_value()
|
||||||
|
|
||||||
class ScratchSourceRef(ScratchObjWrapper):
|
class ScratchCitation(ScratchHandleWrapper):
|
||||||
|
|
||||||
DROP_TARGETS = [DdTargets.SOURCEREF]
|
DROP_TARGETS = [DdTargets.CITATION_LINK]
|
||||||
DRAG_TARGET = DdTargets.SOURCEREF
|
DRAG_TARGET = DdTargets.CITATION_LINK
|
||||||
ICON = LINK_PIC
|
ICON = ICONS["citation"]
|
||||||
|
|
||||||
def __init__(self, dbstate, obj):
|
def __init__(self, dbstate, obj):
|
||||||
super(ScratchSourceRef, self).__init__(dbstate, obj)
|
super(ScratchCitation, self).__init__(dbstate, obj)
|
||||||
self._type = _("Source ref")
|
self._type = _("Citation")
|
||||||
if self._obj:
|
self._objclass = 'Citation'
|
||||||
base = self._db.get_source_from_handle(self._obj.get_reference_handle())
|
if self._handle:
|
||||||
if base:
|
citation = self._db.get_citation_from_handle(self._handle)
|
||||||
self._title = base.get_title()
|
if citation:
|
||||||
|
self._title = citation.get_gramps_id()
|
||||||
notelist = map(self._db.get_note_from_handle,
|
notelist = map(self._db.get_note_from_handle,
|
||||||
self._obj.get_note_list())
|
citation.get_note_list())
|
||||||
srctxtlist = [note for note in notelist
|
srctxtlist = [note for note in notelist
|
||||||
if note.get_type() == gen.lib.NoteType.SOURCE_TEXT]
|
if note.get_type() == gen.lib.NoteType.SOURCE_TEXT]
|
||||||
page = self._obj.get_page()
|
page = citation.get_page()
|
||||||
if not page:
|
if not page:
|
||||||
page = _('not available|NA')
|
page = _('not available|NA')
|
||||||
text = ""
|
text = ""
|
||||||
@ -470,6 +474,14 @@ class ScratchSourceRef(ScratchObjWrapper):
|
|||||||
'sourcetext' : text,
|
'sourcetext' : text,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def is_valid(self):
|
||||||
|
data = pickle.loads(self._obj)
|
||||||
|
handle = data[2]
|
||||||
|
obj = self._db.get_citation_from_handle(handle)
|
||||||
|
if obj:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class ScratchRepoRef(ScratchObjWrapper):
|
class ScratchRepoRef(ScratchObjWrapper):
|
||||||
|
|
||||||
DROP_TARGETS = [DdTargets.REPOREF]
|
DROP_TARGETS = [DdTargets.REPOREF]
|
||||||
@ -968,7 +980,6 @@ class ScratchPadListView(object):
|
|||||||
self.register_wrapper_class(ScratchEvent)
|
self.register_wrapper_class(ScratchEvent)
|
||||||
self.register_wrapper_class(ScratchPlace)
|
self.register_wrapper_class(ScratchPlace)
|
||||||
self.register_wrapper_class(ScratchEventRef)
|
self.register_wrapper_class(ScratchEventRef)
|
||||||
self.register_wrapper_class(ScratchSourceRef)
|
|
||||||
self.register_wrapper_class(ScratchRepoRef)
|
self.register_wrapper_class(ScratchRepoRef)
|
||||||
self.register_wrapper_class(ScratchFamilyEvent)
|
self.register_wrapper_class(ScratchFamilyEvent)
|
||||||
self.register_wrapper_class(ScratchUrl)
|
self.register_wrapper_class(ScratchUrl)
|
||||||
@ -979,6 +990,7 @@ class ScratchPadListView(object):
|
|||||||
self.register_wrapper_class(ScratchMediaObj)
|
self.register_wrapper_class(ScratchMediaObj)
|
||||||
self.register_wrapper_class(ScratchMediaRef)
|
self.register_wrapper_class(ScratchMediaRef)
|
||||||
self.register_wrapper_class(ScratchSourceLink)
|
self.register_wrapper_class(ScratchSourceLink)
|
||||||
|
self.register_wrapper_class(ScratchCitation)
|
||||||
self.register_wrapper_class(ScratchPersonLink)
|
self.register_wrapper_class(ScratchPersonLink)
|
||||||
self.register_wrapper_class(ScratchFamilyLink)
|
self.register_wrapper_class(ScratchFamilyLink)
|
||||||
self.register_wrapper_class(ScratchDropList)
|
self.register_wrapper_class(ScratchDropList)
|
||||||
|
@ -63,7 +63,7 @@ class CitationEmbedList(EmbeddedList, DbGUIElement):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_HANDLE_COL = 4 # Column number from CitationRefModel
|
_HANDLE_COL = 4 # Column number from CitationRefModel
|
||||||
_DND_TYPE = DdTargets.NOTE_LINK
|
_DND_TYPE = DdTargets.CITATION_LINK
|
||||||
|
|
||||||
_MSG = {
|
_MSG = {
|
||||||
'add' : _('Create and add a new citation and new source'),
|
'add' : _('Create and add a new citation and new source'),
|
||||||
|
@ -196,7 +196,20 @@ class CitationTreeView(ListView):
|
|||||||
return self.dbstate.db.get_citation_bookmarks()
|
return self.dbstate.db.get_citation_bookmarks()
|
||||||
|
|
||||||
def drag_info(self):
|
def drag_info(self):
|
||||||
|
selection = self.selected_handles()
|
||||||
|
if len(selection) == 1:
|
||||||
|
handle = selection[0]
|
||||||
|
# The handle will either be a Source handle or a Citation handle
|
||||||
|
source = self.dbstate.db.get_source_from_handle(handle)
|
||||||
|
citation = self.dbstate.db.get_citation_from_handle(handle)
|
||||||
|
if (not source and not citation) or (source and citation):
|
||||||
|
raise ValueError("selection must be either source or citation")
|
||||||
|
if source:
|
||||||
return DdTargets.SOURCE_LINK
|
return DdTargets.SOURCE_LINK
|
||||||
|
else:
|
||||||
|
return DdTargets.CITATION_LINK
|
||||||
|
else:
|
||||||
|
return DdTargets.CITATION_LINK
|
||||||
|
|
||||||
def type_list(self):
|
def type_list(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user