diff --git a/gramps/gui/editors/displaytabs/backreflist.py b/gramps/gui/editors/displaytabs/backreflist.py index 72053f63d..2b4355729 100644 --- a/gramps/gui/editors/displaytabs/backreflist.py +++ b/gramps/gui/editors/displaytabs/backreflist.py @@ -65,10 +65,10 @@ class BackRefList(EmbeddedList): def __init__(self, dbstate, uistate, track, obj, refmodel, callback=None): self.obj = obj + self.connectid = None EmbeddedList.__init__(self, dbstate, uistate, track, _('_References'), refmodel) self._callback = callback - self.connectid = self.model.connect('row-inserted', self.update_label) self.track_ref_for_deletion("model") def update_label(self, *obj): @@ -124,6 +124,12 @@ class BackRefList(EmbeddedList): def get_data(self): return self.obj + def _set_data(self, new_backref_list): + """ + Reset data associated with display tab. Only called in rebuild_callback! + """ + self.obj = new_backref_list + def column_order(self): return ((1, 0), (1, 1), (1, 2)) @@ -207,3 +213,13 @@ class BackRefList(EmbeddedList): EditRepository(self.dbstate, self.uistate, [], repo) except WindowActiveError: pass + + def rebuild(self): + """ + Rebuild the view. This remakes the model, so we need to reconnect the + signal + """ + if not self.connectid is None: + self.model.disconnect(self.connectid) + EmbeddedList.rebuild(self) + self.connectid = self.model.connect('row-inserted', self.update_label) diff --git a/gramps/gui/editors/displaytabs/citedintab.py b/gramps/gui/editors/displaytabs/citedintab.py index 99ed9bf6c..a6dd6a2cc 100644 --- a/gramps/gui/editors/displaytabs/citedintab.py +++ b/gramps/gui/editors/displaytabs/citedintab.py @@ -176,8 +176,10 @@ class CitedInTab(GrampsTab): ##print ('t1', cobjclass, chandle) if cobjclass == 'Citation': cite = db.get_citation_from_handle(chandle) + has_backlink = False for (objclass, handle) in db.find_backlink_handles(chandle): ##print ('t2', objclass, handle) + has_backlink = True if objclass == 'Person': ref = db.get_person_from_handle(handle) self.__add_person(ref, cite) @@ -199,18 +201,31 @@ class CitedInTab(GrampsTab): else: #most strange, not possible for citation there! print ("Error in citedintab.py: citation referenced " - "outside citation") + "outside citation. Run rebuild reference tables") + if not has_backlink: + self.__add_cite(cite) else: #most strange, not possible ! print ("Error in citedintab.py: source referenced " - "outside citation") + "outside citation. Run rebuild reference tables") self.srtdata = sorted(self.srtdata, key=lambda x: glocale.sort_key(x[0])) def __add_object(self, obj, cite, descr_obj, shortdescr, objname): """ obtain citation data of the object and store here so it can be shown - in a treeview + in a treeview. If obj=None, an unused citation... """ + if obj is None: + #adding of a citation which is part of not a singel object. The + #citation is added under None. + if not None in self.obj2citemap: + self.obj2citemap[None] = {'prim': [], 'sec': [], 'subsec': []} + #add for sorting in the treeview to map + self.srtdata.append((descr_obj, None, shortdescr, objname)) + #add this citation + self.obj2citemap[None]['prim'].append(cite.handle) + return + if not obj.handle in self.obj2citemap: self.obj2citemap[obj.handle] = {'prim': [], 'sec': [], 'subsec': []} #add for sorting in the treeview to map @@ -307,6 +322,13 @@ class CitedInTab(GrampsTab): 'id': obj.get_gramps_id(), 'descr': name}, _("Cited in Media"), "Media") + def __add_cite(self, cite): + """ + see __add_object + """ + self.__add_object(None, cite, _('Unused Citations'), + _('Unused Citation'), "Citation") + def format_sec_obj(self, objsec): """ text for treeview on citation in secondary object diff --git a/gramps/gui/editors/displaytabs/embeddedlist.py b/gramps/gui/editors/displaytabs/embeddedlist.py index 8d4e9914f..37abc8a5f 100644 --- a/gramps/gui/editors/displaytabs/embeddedlist.py +++ b/gramps/gui/editors/displaytabs/embeddedlist.py @@ -448,6 +448,17 @@ class EmbeddedList(ButtonTab): """ raise NotImplementedError + def _set_data(self): + """ + Reset the data associated with the list. This is typically + a list of objects. + + This should be overridden in the derived classes. This method should + only be given if it is needed to call rebuild_callback with new_list + parameter. Don't use it otherwise! + """ + raise NotImplementedError + def column_order(self): """ Specifies the column order for the columns. This should be @@ -610,12 +621,14 @@ class EmbeddedList(ButtonTab): """ pass - def rebuild_callback(self): + def rebuild_callback(self, new_list=None): """ The view must be remade when data changes outside this tab. Use this method to connect to after a db change. It makes sure the data is obtained again from the present object and the db what is not present in the obj, and the view rebuild """ + if new_list is not None: + self._set_data(new_list) self.changed = True self.rebuild() diff --git a/gramps/gui/editors/displaytabs/gallerytab.py b/gramps/gui/editors/displaytabs/gallerytab.py index f78f084bc..8d0f86778 100644 --- a/gramps/gui/editors/displaytabs/gallerytab.py +++ b/gramps/gui/editors/displaytabs/gallerytab.py @@ -365,13 +365,15 @@ class GalleryTab(ButtonTab, DbGUIElement): """ self.rebuild() - def rebuild_callback(self): + def rebuild_callback(self, new_list=None): """ The view must be remade when data changes outside this tab. Use this method to connect to after a db change. It makes sure the data is obtained again from the present object and the db what is not present in the obj, and the view rebuild """ + if new_list is not None: + self.media_list = new_list self.changed = True self.rebuild() diff --git a/gramps/gui/editors/displaytabs/notetab.py b/gramps/gui/editors/displaytabs/notetab.py index 8617716ac..796230015 100644 --- a/gramps/gui/editors/displaytabs/notetab.py +++ b/gramps/gui/editors/displaytabs/notetab.py @@ -115,6 +115,12 @@ class NoteTab(EmbeddedList, DbGUIElement): """ return self.data + def _set_data(self, new_data): + """ + Reset data associated with display tab. Only called in rebuild_callback! + """ + self.data = new_data + def column_order(self): """ Return the column order of the columns in the display tab. diff --git a/gramps/gui/editors/displaytabs/srcattrembedlist.py b/gramps/gui/editors/displaytabs/srcattrembedlist.py index 9ca5f9302..a7e26097f 100644 --- a/gramps/gui/editors/displaytabs/srcattrembedlist.py +++ b/gramps/gui/editors/displaytabs/srcattrembedlist.py @@ -91,6 +91,12 @@ class SrcAttrEmbedList(EmbeddedList): def get_data(self): return self.data + def _set_data(self, new_data): + """ + Reset data associated with display tab. Only called in rebuild_callback! + """ + self.data = new_data + def column_order(self): return ((1, 2), (1, 0), (1, 1)) diff --git a/gramps/gui/editors/editsource.py b/gramps/gui/editors/editsource.py index 9ebf509db..05af0469d 100644 --- a/gramps/gui/editors/editsource.py +++ b/gramps/gui/editors/editsource.py @@ -690,7 +690,8 @@ class EditSource(EditPrimary): msg = _("Edit Source (%s)") % self.obj.get_title() else: msg = '' - + # Make sure citation references this source + self.citation.set_reference_handle(self.obj.handle) # Now commit the Citation Primary object if needed if self.citation_loaded: if not self.citation.get_handle(): @@ -719,12 +720,9 @@ class EditSource(EditPrimary): self.__base_save() if self.callback and self.citation_loaded: - #new calling sequence of callback + #callback only returns the citation handle. Source can be determined + # of this if needed. self.callback(self.citation.get_handle()) - elif self.callback: - #user closed citation, but a callback is needed. We don't know - #what citatin to return, so return None. Caller should handle this! - self.callback(None) self.close() @@ -747,8 +745,8 @@ class EditSource(EditPrimary): # CITATION PART def cite_apply_callback(self, citation_handle): - if self.citation: - self.unload_citation() + if self.citation_loaded: + self.close_citation() self.load_citation(citation_handle) def unload_citation(self): @@ -794,9 +792,11 @@ class EditSource(EditPrimary): for field in [self.gid, self.type_mon, self.tags2, self.ref_privacy]: field.update() #trigger update of the tab fields - for tab in [self.comment_tab, self.gallery_tab, self.attr_tab, - self.citationref_list]: - tab.rebuild_callback() + self.comment_tab.rebuild_callback(self.citation.get_note_list()) + self.gallery_tab.rebuild_callback(self.citation.get_media_list()) + self.attr_tab.rebuild_callback(self.citation.get_attribute_list()) + self.citationref_list.rebuild_callback( + self.db.find_backlink_handles(self.citation.handle)) def data_has_changed(self): return self.citation_data_has_changed() or \