From 1b25cd8b47c08ea7e4a8d10a96dddd4d4487c8d2 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 8 Jan 2009 02:00:31 +0000 Subject: [PATCH] Fixes for bug #2416: added proper name format in gtk tree model, and update on canceled edit svn: r11583 --- src/GrampsCfg.py | 35 +++++++++++++++++++++++--- src/GrampsDbUtils/_GrampsDbWriteXML.py | 2 +- src/GrampsDbUtils/_ReadXML.py | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index ec69184fc..7a5439bc6 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -360,14 +360,37 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): "%s %s, %s" % (_("Given"), _("SURNAME"), _("Suffix")), "%s /%s/" % (_("Given"), _("SURNAME")), ] - f = lyst[int(random.random() * len(lyst))] - i = _nd.add_name_format(f, f.lower()) - node = self.fmt_model.append(row=[i, f, f.lower(), - _nd.format_str(self.examplename, f)]) + fmtlyst = ["%s, %s %s (%s)" % ("Surname", "Given", "Suffix", + "Common"), + "%s, %s %s (%s)" % ("Surname", "Given", "Suffix", + "Call"), + "%s, %s %s (%s)" % ("SURNAME", "Given", "Suffix", + "Call"), + "%s, %s (%s)" % ("Surname", "Given", "Common"), + "%s, %s (%s)" % ("Surname", "Given", "Call"), + "%s %s" % ("Given", "Surname"), + "%s %s, %s" % ("Given", "Surname", "Suffix"), + "%s %s %s" % ("Given", "Surname", "Patronymic"), + "%s, %s %s (%s)" % ("SURNAME", "Given", "Suffix", + "Common"), + "%s, %s (%s)" % ("SURNAME", "Given", "Common"), + "%s, %s (%s)" % ("SURNAME", "Given", "Call"), + "%s %s" % ("Given", "SURNAME"), + "%s %s, %s" % ("Given", "SURNAME", "Suffix"), + "%s /%s/" % ("Given", "SURNAME"), + ] + rand = int(random.random() * len(lyst)) + f = lyst[rand] + fmt = fmtlyst[rand] + i = _nd.add_name_format(f, fmt) + node = self.fmt_model.append(row=[i, f, fmt, + _nd.format_str(self.examplename, fmt)]) path = self.fmt_model.get_path(node) self.format_list.set_cursor(path, focus_column=self.name_column, start_editing=True) + self.__current_path = path + self.__current_text = f def __edit_name(self, obj): store, node = self.format_list.get_selection().get_selected() @@ -395,6 +418,9 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): iter = model.iter_next(iter) return False + def __cancel_change(self, obj): + self.__change_name("", self.__current_path, self.__current_text) + def __change_name(self, text, path, new_text): """ If the new string is empty, do nothing. Otherwise, renaming the @@ -457,6 +483,7 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): text=COL_NAME) name_renderer.set_property('editable', False) name_renderer.connect('edited', self.__change_name) + name_renderer.connect('editing-canceled', self.__cancel_change) self.name_renderer = name_renderer format_tree.append_column(name_column) example_renderer = gtk.CellRendererText() diff --git a/src/GrampsDbUtils/_GrampsDbWriteXML.py b/src/GrampsDbUtils/_GrampsDbWriteXML.py index 3a06bacc9..28eb37c6c 100644 --- a/src/GrampsDbUtils/_GrampsDbWriteXML.py +++ b/src/GrampsDbUtils/_GrampsDbWriteXML.py @@ -377,7 +377,7 @@ class GrampsDbXmlWriter(UpdateCallback): for number, name,fmt_str,active in self.db.name_formats: self.g.write('%s\n' - % (' ', number, fmt_str, fmt_str, int(active))) + % (' ', number, name, fmt_str, int(active))) self.g.write(" \n") def fix(self,line): diff --git a/src/GrampsDbUtils/_ReadXML.py b/src/GrampsDbUtils/_ReadXML.py index 5394ac5f5..3afcd4728 100644 --- a/src/GrampsDbUtils/_ReadXML.py +++ b/src/GrampsDbUtils/_ReadXML.py @@ -1054,7 +1054,7 @@ class GrampsParser(UpdateCallback): if number in self.taken_name_format_numbers: number = self.remap_name_format(number) - self.name_formats.append((number, fmt_str, fmt_str, active)) + self.name_formats.append((number, name, fmt_str, active)) def remap_name_format(self, old_number): if self.name_formats_map.has_key(old_number): # This should not happen