From 6bf09da13d6748337d7348b788f62c0f6eb7d129 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Thu, 7 Jun 2007 05:06:14 +0000 Subject: [PATCH] 2007-06-06 Alex Roitman * src/DisplayState.py (DisplayState.__signals__): Port fixes from 2.2 tree. * src/FilterEditor/_EditFilter.py: Port fixes from 2.2 tree. * src/FilterEditor/_FilterEditor.py: Port fixes from 2.2 tree. * data/grampsxml.rng: Port fixes from 2.2 tree. * data/grampsxml.dtd: Port fixes from 2.2 tree. * src/GrampsDb/_GrampsDbWriteXML.py (_xml_version): Bump up version. svn: r8536 --- ChangeLog | 10 ++++- data/grampsxml.dtd | 15 ++++--- data/grampsxml.rng | 9 ++++- src/DisplayState.py | 1 + src/FilterEditor/_EditFilter.py | 14 +++++-- src/FilterEditor/_FilterEditor.py | 66 ++++++++++++++++++++++++++++++- src/GrampsDb/_GrampsDbWriteXML.py | 2 +- 7 files changed, 103 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index cb3d83e17..b5e88cde7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ +2007-06-06 Alex Roitman + * src/DisplayState.py (DisplayState.__signals__): Port fixes from + 2.2 tree. + * src/FilterEditor/_EditFilter.py: Port fixes from 2.2 tree. + * src/FilterEditor/_FilterEditor.py: Port fixes from 2.2 tree. + * data/grampsxml.rng: Port fixes from 2.2 tree. + * data/grampsxml.dtd: Port fixes from 2.2 tree. + * src/GrampsDb/_GrampsDbWriteXML.py (_xml_version): Bump up version. + 2007-06-03 Don Allingham - * src/GrampsDb/_GrampsBSDDB.py: fix __ issue * src/GrampsDb/_GrampsCursor.py: added * src/Simple/__init__.py: add diff --git a/data/grampsxml.dtd b/data/grampsxml.dtd index 357515000..7cb41ebd6 100644 --- a/data/grampsxml.dtd +++ b/data/grampsxml.dtd @@ -24,15 +24,15 @@ --> @@ -55,7 +55,7 @@ DATABASE - + - + @@ -433,6 +435,7 @@ SHARED ELEMENTS diff --git a/data/grampsxml.rng b/data/grampsxml.rng index 38ef8ff71..47a12fd42 100644 --- a/data/grampsxml.rng +++ b/data/grampsxml.rng @@ -31,7 +31,7 @@ @@ -214,6 +214,7 @@ + @@ -469,6 +470,9 @@ + + + @@ -552,6 +556,9 @@ + + + diff --git a/src/DisplayState.py b/src/DisplayState.py index 53cf6bcc3..452576282 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -257,6 +257,7 @@ class DisplayState(GrampsDb.GrampsDBCallback): __signals__ = { 'filters-changed' : (str, ), + 'filter-name-changed' : (str,unicode,unicode), 'nameformat-changed' : None, 'plugins-reloaded' : (list, list), } diff --git a/src/FilterEditor/_EditFilter.py b/src/FilterEditor/_EditFilter.py index 8d1b542e1..5f5d879fa 100644 --- a/src/FilterEditor/_EditFilter.py +++ b/src/FilterEditor/_EditFilter.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -18,7 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: _FilterEditor.py 6840 2006-06-01 22:37:13Z dallingham $ +# $Id$ """ Custom Filter Editor tool. @@ -127,7 +127,12 @@ class EditFilter(ManagedWindow.ManagedWindow): def filter_name_changed(self,obj): name = unicode(self.fname.get_text()) - self.ok_btn.set_sensitive(len(name) != 0) + # Make sure that the name is not empty + # and not in the list of existing filters (excluding this one) + names = [filt.get_name() + for filt in self.filterdb.get_filters(self.space) + if filt != self.filter] + self.ok_btn.set_sensitive((len(name) != 0) and (name not in names)) def select_row(self,obj): store,node = self.rlist.get_selected() @@ -147,6 +152,9 @@ class EditFilter(ManagedWindow.ManagedWindow): n = unicode(self.fname.get_text()).strip() if n == '': return + if n != self.filter.get_name(): + self.uistate.emit('filter-name-changed', + (self.space,unicode(self.filter.get_name()),n)) self.filter.set_name(n) self.filter.set_comment(unicode(self.comment.get_text()).strip()) for f in self.filterdb.get_filters(self.space)[:]: diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index 933eacfda..24b9e0bec 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2000-2007 Donald N. Allingham # # 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 @@ -56,8 +56,10 @@ import GrampsDisplay import const from Filters import GenericFilterFactory, FilterList, \ reload_custom_filters, reload_system_filters +from Filters.Rules._MatchesFilterBase import MatchesFilterBase import ListModel import ManagedWindow +from QuestionDialog import QuestionDialog #------------------------------------------------------------------------- # @@ -100,6 +102,8 @@ class FilterEditor(ManagedWindow.ManagedWindow): self.connect_button('close', self.close) self.connect_button('add', self.add_new_filter) + self.uistate.connect('filter-name-changed',self.clean_after_rename) + self.clist = ListModel.ListModel( self.filter_list, [(_('Filter'),0,150),(_('Comment'),1,150)], @@ -181,9 +185,43 @@ class FilterEditor(ManagedWindow.ManagedWindow): store,node = self.clist.get_selected() if node: gfilter = self.clist.get_object(node) - self.filterdb.get_filters(self.space).remove(gfilter) + name = gfilter.get_name() + if self.check_recursive_filters(self.space,name): + QuestionDialog( _('Delete Filter?'), + _('This filter is currently being used ' + 'as the base for other filters. Deleting' + 'this filter will result in removing all ' + 'other filters that depend on it.'), + _('Delete Filter'), + self._do_delete_selected_filter, + self.window) + else: + self._do_delete_selected_filter() + + def _do_delete_selected_filter(self): + store,node = self.clist.get_selected() + if node: + gfilter = self.clist.get_object(node) + self._do_delete_filter(self.space,gfilter) self.draw_filters() + def _do_delete_filter(self,space,gfilter): + """ + This method recursively calls itself to delete all dependent filters + before removing this filter. Otherwise when A is 'matches B' + and C is 'matches D' the removal of A leads to two broken filter + being left behind. + """ + filters = self.filterdb.get_filters(space) + name = gfilter.get_name() + for the_filter in filters: + for rule in the_filter.get_rules(): + values = rule.values() + if issubclass(rule.__class__,MatchesFilterBase) \ + and (name in values): + self._do_delete_filter(space,the_filter) + filters.remove(gfilter) + def get_all_handles(self): if self.space == 'Person': return self.db.get_person_handles(sort_handles=False) @@ -201,3 +239,27 @@ class FilterEditor(ManagedWindow.ManagedWindow): return self.db.get_repository_handles() elif self.space == 'Note': return self.db.get_note_handles() + + def clean_after_rename(self,space,old_name,new_name): + if old_name == "": + return + + if old_name == new_name: + return + + for the_filter in self.filterdb.get_filters(space): + for rule in the_filter.get_rules(): + values = rule.values() + if issubclass(rule.__class__,MatchesFilterBase) \ + and (old_name in values): + ind = values.index(old_name) + values[ind] = new_name + + def check_recursive_filters(self,space,name): + for the_filter in self.filterdb.get_filters(space): + for rule in the_filter.get_rules(): + values = rule.values() + if issubclass(rule.__class__,MatchesFilterBase) \ + and (name in values): + return True + return False diff --git a/src/GrampsDb/_GrampsDbWriteXML.py b/src/GrampsDb/_GrampsDbWriteXML.py index ad0d91145..008bcb18e 100644 --- a/src/GrampsDb/_GrampsDbWriteXML.py +++ b/src/GrampsDb/_GrampsDbWriteXML.py @@ -72,7 +72,7 @@ except: _gzip_ok = 0 -_xml_version = "1.1.4" +_xml_version = "1.2.0" # table for skipping control chars from XML strip_dict = dict.fromkeys(range(9)+range(12,20))